我在使用 ReSTLet 使 Swagger 显示 API 文档时遇到了一些麻烦。 Swagger 展示的只是这些东西:
检查 api-docs 它只显示:
我想知道我的代码有什么问题:
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;
}
}
最佳答案
你可以看看这篇文章:
- APISpark 可以为您现有的 Web API 带来什么(第 2 部分)- http://restlet.com/blog/2016/01/04/what-can-apispark-bring-to-your-existing-web-apis-part-2/
ReSTLet 的 Swagger 扩展都支持 Swagger1 和 2:
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/