【发布时间】:2020-12-16 17:43:40
【问题描述】:
使用 swagger-core v3 2.1.6 这三个配置产生相同的 openapi.json 结果。
无配置:
@ApplicationPath("/rest")
public class AuthRestConfig extends Application {
public AuthRestConfig() {
}
}
服务器配置,我需要使用这种conf:
@ApplicationPath("/rest")
public class AuthRestConfig extends Application {
public AuthRestConfig(@Context ServletConfig servletConfig) {
super();
OpenAPI oas = new OpenAPI();
Info info = new Info()
.title("Suma Automaton OpenAPI")
.description("This is a sample server Petstore server. You can find out more about Swagger "
+ "at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, "
+ "you can use the api key `special-key` to test the authorization filters.")
.termsOfService("http://swagger.io/terms/")
.contact(new Contact()
.email("baldodavi@gmail.com"));
oas.info(info);
String url = "/suma-automaton-ms";
List<Server> servers = new ArrayList<>();
Server server = new Server();
server.setUrl(url);
servers.add(server);
oas.setServers(servers);
SwaggerConfiguration oasConfig = new SwaggerConfiguration()
.openAPI(oas)
.prettyPrint(true)
.resourcePackages(Stream.of("io.swagger.sample.resource").collect(Collectors.toSet()));
try {
new JaxrsOpenApiContextBuilder<>()
.servletConfig(servletConfig)
.application(this)
.openApiConfiguration(oasConfig)
.buildContext(true);
} catch (OpenApiConfigurationException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
对这种行为有什么建议吗?有什么我误解了吗?考虑到我也使用https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Integration-and-configuration#jax-rs-application中报告的标准配置有相同的行为@
【问题讨论】: