从 Restlet 生成 Swagger 2.0 JSON
Generating Swagger 2.0 JSON from Restlet
使用 Restlet 2.3.3 我已经声明我的 Restlet 应用程序派生自 SwaggerApplication。当我访问默认的 /api-docs URI 时,我观察到元数据的 Swagger 版本是 1.2。随后,我无法将其加载到 Swagger-UI 中而不会出现错误。
如何从 Restlet 的 Swagger 扩展中获取 Swagger 2.0 JSON?文档似乎表明它可以输出 v2.0 JSON.
谢谢!
classSwaggerApplication
只支持Swagger 1.2。如果要使用 Swagger 2.0,必须手动附加相应的 restlet 以根据 class Swagger2SpecificationRestlet
生成内容,如下所述:
public Restlet createInboundRoot() {
Router router = new Router(getContext());
// Configuring Swagger 2 support
Swagger2SpecificationRestlet swagger2SpecificationRestlet
= new Swagger2SpecificationRestlet(this);
swagger2SpecificationRestlet.setBasePath(
"http://myapp.com/api/v1");
swagger2SpecificationRestlet.attach(router);
return router;
}
通过这样的配置,获取 Swagger 内容的相关资源附加在路径 /swagger.json
上。您会注意到,您可以使用方法 Swagger2SpecificationRestlet#attach(Router, String)
.
指定自己的路径
希望对你有帮助,
蒂埃里
使用 Restlet 2.3.3 我已经声明我的 Restlet 应用程序派生自 SwaggerApplication。当我访问默认的 /api-docs URI 时,我观察到元数据的 Swagger 版本是 1.2。随后,我无法将其加载到 Swagger-UI 中而不会出现错误。
如何从 Restlet 的 Swagger 扩展中获取 Swagger 2.0 JSON?文档似乎表明它可以输出 v2.0 JSON.
谢谢!
classSwaggerApplication
只支持Swagger 1.2。如果要使用 Swagger 2.0,必须手动附加相应的 restlet 以根据 class Swagger2SpecificationRestlet
生成内容,如下所述:
public Restlet createInboundRoot() {
Router router = new Router(getContext());
// Configuring Swagger 2 support
Swagger2SpecificationRestlet swagger2SpecificationRestlet
= new Swagger2SpecificationRestlet(this);
swagger2SpecificationRestlet.setBasePath(
"http://myapp.com/api/v1");
swagger2SpecificationRestlet.attach(router);
return router;
}
通过这样的配置,获取 Swagger 内容的相关资源附加在路径 /swagger.json
上。您会注意到,您可以使用方法 Swagger2SpecificationRestlet#attach(Router, String)
.
希望对你有帮助, 蒂埃里