openapi-go icon indicating copy to clipboard operation
openapi-go copied to clipboard

Add ReuseResponses feature to Reflector for OpenAPI 3.0 and 3.1

Open luke-hagar-sp opened this issue 2 months ago • 0 comments

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'

luke-hagar-sp avatar Oct 20 '25 16:10 luke-hagar-sp