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