我有一个jax-rs应用程序,多数民众赞成在带有swagger2:
的openapi.json http://localhost:8080/notification/rest/openapi.json
并公开OpenAPI:
{
"openapi" : "3.0.1",
"info" : {
"title" : "Notification Module",
"version" : "1.0"
},
"paths" : {
"/sms/send" : {
"post" : {
"operationId" : "send_1",
"requestBody" : {
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/Sms"
}
}
}
},
"responses" : {
"default" : {
"description" : "default response",
"content" : {
"application/json" : {
"schema" : {
"$ref" : "#/components/schemas/SendSmsResult"
}
}
}
}
}
}
}
...
}
}
现在,我正在尝试在Docker容器中显示Swagger-UI:
docker run -p 80:8080 -e URL="http://localhost:8080/notification/rest/openapi.json" swaggerapi/swagger-ui
Swagger2正常打开。但是,它试图要求:
的"尝试"。 http://localhost:8080/sms/send
缺少上下文和基本路径/notification/rest/
可以配置Swagger-UI以创建url请求:
http://localhost:8080/notification/rest/sms/send
?
已解决。
只需将servers
配置为openapi-configuration.yaml
并有效。
resourcePackages:
- com.mycompany.app.rest
prettyPrint: true
cacheTTL: 0
buildContext: true
openAPI:
servers:
- url: http://localhost:8080/notification
info:
version: '1.0'
title: Notification Module
另外,重要的是要使用@Context ServletConfig
参数添加构造函数:
@ApplicationPath("/rest")
public class App extends Application {
public App(@Context ServletConfig servletConfig) {
}
}