Springdoc-Openapi不包括全局标头或API-DOC中的响应
我们将Springfox移植到SpringDoc,并且存在获取全局参数和默认响应的问题,以显示在 /V3 /API-DOCS响应中。
它们在Swagger UI中表现良好,但在JSON中没有从 /v3 /api-docs返回。我们正在从这些API文档中生成代码。
能够使标头在“组件”部分下显示,但是标题和响应并未像SpringFox一样在JSON API-DOCS输出中的每个端点下显示。
@Bean
public GroupedOpenApi groupedOpenApi() {
final OperationCustomizer globalHeader = (operation, handlerMethod) -> {
operation.addParametersItem(new HeaderParameter()
.$ref("#/components/parameters/testheader"));
return operation;
};
return GroupedOpenApi.builder()
.group("default").pathsToMatch("/**")
.addOperationCustomizer(globalHeader)
.addOpenApiCustomiser(getResponseMessages()).build();
}
@Bean
public OpenAPI openApi() {
return new OpenAPI()
.info(new Info().title("testing").description("testing").termsOfService("")
.license(new License().name("").url("")).version("1.0"))
.components(new Components()
.addParameters(
"testheader",
new Parameter()
.in(ParameterIn.HEADER.toString())
.name("testheader").description("test header")
.required(true).example("sdfdsafsf").schema(new StringSchema())));
}
private OpenApiCustomiser getResponseMessages() {
return openApi -> {
openApi.getPaths().values().forEach(pathItem ->
pathItem.readOperations().forEach(operation -> {
ApiResponses apiResponses = operation.getResponses();
apiResponses.addApiResponse(
String.valueOf(HttpStatus.BAD_REQUEST.value()),
new ApiResponse().description("Bad request"));
apiResponses.addApiResponse(
String.valueOf(HttpStatus.UNAUTHORIZED.value()),
new ApiResponse().description("Not authorized"));
}));
};
}
关于我缺少什么的想法?谢谢。
这是一个小型春季启动应用程序,证明了问题: https://github.com/ens121/swaggertest
We are porting springfox to springdoc and are having issues getting the global parameters and default responses to show up in the /v3/api-docs response.
They show up fine in the Swagger UI but not in the json returned from /v3/api-docs. We are generating code from these API docs.
Was able to get the headers to show up under the components section but the headers and responses do not show up under each endpoint in the json api-docs output like it did with springfox.
@Bean
public GroupedOpenApi groupedOpenApi() {
final OperationCustomizer globalHeader = (operation, handlerMethod) -> {
operation.addParametersItem(new HeaderParameter()
.$ref("#/components/parameters/testheader"));
return operation;
};
return GroupedOpenApi.builder()
.group("default").pathsToMatch("/**")
.addOperationCustomizer(globalHeader)
.addOpenApiCustomiser(getResponseMessages()).build();
}
@Bean
public OpenAPI openApi() {
return new OpenAPI()
.info(new Info().title("testing").description("testing").termsOfService("")
.license(new License().name("").url("")).version("1.0"))
.components(new Components()
.addParameters(
"testheader",
new Parameter()
.in(ParameterIn.HEADER.toString())
.name("testheader").description("test header")
.required(true).example("sdfdsafsf").schema(new StringSchema())));
}
private OpenApiCustomiser getResponseMessages() {
return openApi -> {
openApi.getPaths().values().forEach(pathItem ->
pathItem.readOperations().forEach(operation -> {
ApiResponses apiResponses = operation.getResponses();
apiResponses.addApiResponse(
String.valueOf(HttpStatus.BAD_REQUEST.value()),
new ApiResponse().description("Bad request"));
apiResponses.addApiResponse(
String.valueOf(HttpStatus.UNAUTHORIZED.value()),
new ApiResponse().description("Not authorized"));
}));
};
}
Any ideas on what I'm missing? Thank you.
Here is a small spring boot application that demonstrates the issue:
https://github.com/ens121/swaggertest
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以使用
@openapidefinition
注释:带有
application.properties
:哪个产生:
The global API definitions can be set with the
@OpenAPIDefinition
annotation :with the values provided in your
application.properties
:which yields :