使用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;
}
}
答案 0 :(得分:1)
解决方案是添加以下代码:
// Configuring Swagger 2 support
Swagger2SpecificationRestlet swagger2SpecificationRestlet
= new Swagger2SpecificationRestlet(this);
swagger2SpecificationRestlet.setBasePath("http://localhost:8080/api-docs");
swagger2SpecificationRestlet.attach(router);
并将Swagger UI指向/swagger.json
答案 1 :(得分:1)
你可以看一下这篇文章:
Swlet 1和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;
}
}
答案 2 :(得分:0)
Swagger需要找到您的API操作。我不确定Restlet,在泽西岛,您使用@Api
注释您的REST资源类,并使用@ApiOperation
注释您的方法。在此处阅读更多in the swagger docs。