gpt4 book ai didi

java - Swagger 不工作

转载 作者:行者123 更新时间:2023-11-30 08:40:41 25 4
gpt4 key购买 nike

我在使用 ReSTLet 使 Swagger 显示 API 文档时遇到了一些麻烦。 Swagger 显示的只是这些东西:

enter image description here

检查 api-docs 它只显示了这个:

enter image description here

我想知道我的代码有什么问题:

public class MyApplication extends SwaggerApplication {
private static final String ROOT_URI = "/";
public Restlet createInboundRoot() {
Router router = new Router(getContext());
router.attach(ROOT_URI, RootServerResource.class);
router.attach(ROOT_URI + "ping", PingServerResource.class);
router.attach(ROOT_URI + "ping/", PingServerResource.class);
// Some code omitted for simplicity
return router;
}
}

最佳答案

你可以看看这篇文章:

Swagger1 和 2 都由 ReSTLet 的 Swagger 扩展支持:

  • Swagger v1

    public class ContactsApplication extends SwaggerApplication {
    public Restlet createInboundRoot() {
    Router router = new Router();
    (...)
    attachSwaggerSpecificationRestlet(router, "/docs");

    return router;
    }
    }
  • Swagger v2

    public class ContactsApplication extends Application {
    public Restlet createInboundRoot() {
    Router router = new Router();
    (...)
    Swagger2SpecificationRestlet swagger2SpecificationRestlet
    = new Swagger2SpecificationRestlet(this);
    swagger2SpecificationRestlet.setBasePath("http://myapp.org/");
    swagger2SpecificationRestlet.attach(router, "/docs");
    return router;
    }
    }

关于java - Swagger 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35534281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com