Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enhancement] reuse response description #1741

Closed
ggirodda opened this issue Nov 2, 2018 · 6 comments
Closed

[enhancement] reuse response description #1741

ggirodda opened this issue Nov 2, 2018 · 6 comments
Labels
re-use: ref-everywhere Requests to support referencing in more / all places

Comments

@ggirodda
Copy link

ggirodda commented Nov 2, 2018

Hello,
First of all I want to thanks the openAPI community.
I really appreciate the standard, it really helps the communication between back and front developers. I tried to reuse response description in this way:

...
  responses:
    '200':
      allOf:
      - $ref: '../index.yaml#/components/responses/200Ok'

It seems that it's not a valid syntax even if it works well on swagger-ui
I think that it will be helpful to share the response description between different responses, avoiding to repeat the same message everytime.

@handrews
Copy link
Member

handrews commented Nov 4, 2018

@ggirodda I think you can just do

...
  responses:
    '200':
      $ref: '../index.yaml#/components/responses/200Ok'

allOf is a schema keyword and is only allowed in schemas. Usually it's the schema that you want to combine anyway, so if you need to add more schema constraints you can probably create a response that does that with an allOf within the response schema instead.

@ggirodda
Copy link
Author

ggirodda commented Nov 4, 2018

Thank you for your answer, I really had to explein it better, sorry. My problem is that every time I have a response, with 200 or 201 or other commons response code, I have to put the response description for each response, I just want the description to be shared between responses, because the content (the message) is always the same. I want to avoid to repeat every time this on my responses:

response:
  '200':
     description: Ok

Because if one day I want to change the description of responses with code 200, I have to find and replace it on every file.

@MikeRalphson
Copy link
Member

MikeRalphson commented Nov 5, 2018

@ggirodda as you suspect, this is not currently possible up to OpenAPI 3.0.x (there is an issue for tracking the way swagger-ui allows allOf and other schema-combining keywords outside of schema objects swagger-api/swagger-ui#4362).

The major issue is that a Reference Object is just that, an object containing a $ref property, and in the version of JSON Schema we use, the value of the $ref property is used to replace the containing object, but description is a string not an object. Also, there is no components/descriptions or components/strings container to reference into.

The overlay proposal (specifically that in OAI/Overlay-Specification#36) might well allow you to do this by specifying an update object with a JSON Path which matches all of the description properties in response objects where the key value is 200.

@darrelmiller
Copy link
Member

I really wish Description wasn't required.

@handrews
Copy link
Member

@webron @whitlockjc another $ref-with-stuff issue to add to that pile.

@handrews handrews added the $ref label Feb 24, 2020
@handrews handrews added re-use re-use: ref-everywhere Requests to support referencing in more / all places and removed $ref labels Jan 29, 2024
@handrews
Copy link
Member

This is a subset of issue #2697, so I'm going to close it in favor of that issue (which has more discussion).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
re-use: ref-everywhere Requests to support referencing in more / all places
Projects
None yet
Development

No branches or pull requests

4 participants