Globally set the response content schema for specific status codes #2880
Unanswered
jochenberger asked this question in Q&A
Replies: 1 comment
-
I may just have found a solution myself: @BeanpublicOperationCustomizererrorResponseSchemas( finalSpringDocConfigPropertiesspringDocConfigProperties) { Schemaschema = AnnotationsUtils.resolveSchemaFromType( ErrorResponse.class, null, null, springDocConfigProperties.isOpenapi31()); Contentcontent = newContent() .addMediaType( org.springframework.http.MediaType.APPLICATION_JSON_VALUE, newMediaType().schema(schema)); return (operation, handlerMethod) -> { operation .getResponses() .forEach( (status, response) -> { if (HttpStatus.resolve(Integer.valueOf(status)).is4xxClientError()) { response.setContent(content); } }); returnoperation; }; } Is this how it's supposed to be done? Is this the correct way to get hold of the |
BetaWas this translation helpful?Give feedback.
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment
-
We have a lot of methods that return a specific type of object, e.g.
Now everywhere I want to document the 404 (or any other error) response, I need to specify the content schema
ErrorResponse
, or otherwise,Person
ends up as the content schema for the 404 response.Is it possible to define that mapping application-wide so I don't have to repeat it in so many places?
BetaWas this translation helpful?Give feedback.
All reactions