openapi-go
openapi-go copied to clipboard
Add ReuseResponses feature to Reflector for OpenAPI 3.0 and 3.1
This update introduces the ReuseResponses boolean flag in the Reflector struct, allowing common response definitions to be moved to components/responses.
The new methods generateResponseName and collectResponse facilitate the generation of consistent response names and the storage of responses in components when ReuseResponses is enabled. The setupResponse method has been updated to utilize these new functionalities, improving response management.
This allows operations response sections with repeated responses to be collapsed down to something like this:
responses:
"400":
$ref: '#/components/responses/BadRequest'
"401":
$ref: '#/components/responses/Unauthorized'
"403":
$ref: '#/components/responses/Forbidden'
"404":
$ref: '#/components/responses/NotFound'
"500":
$ref: '#/components/responses/InternalServerError'
"503":
$ref: '#/components/responses/ServiceUnavailable'