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

Same ref example in methods not working #3198

Closed
petrkasnal opened this issue Mar 9, 2023 · 4 comments
Closed

Same ref example in methods not working #3198

petrkasnal opened this issue Mar 9, 2023 · 4 comments

Comments

@petrkasnal
Copy link

petrkasnal commented Mar 9, 2023

Hi,

i'm try use same example over ref in few methods and it isn't work.

Example.yml
test: 'ok'

items.yml

post:
  summary: Import items 
  responses:
    '401':
      description: 'Unauthorized'
      content:
        application/json:
          schema:
            $ref: '../BaseSchemas/ApiResult.yml'
          example:
            $ref: '../BaseExamples/UnauthorizedExample.yml'

get:
  summary: Get all items
  responses:
    '401':
      description: 'Unauthorized'
      content:
        application/json:
          schema:
            $ref: '../BaseSchemas/ApiResult.yml'
          example:
            $ref: '../BaseExamples/UnauthorizedExample.yml'

And result show this
Post:
image

Get:
image

@MikeRalphson
Copy link
Member

What tool are you using which doesn't work? This repository is for the OpenAPI specification itself.

@petrkasnal
Copy link
Author

@MikeRalphson Swagger but i dont know if openapi write correctly

@hkosova
Copy link
Contributor

hkosova commented Mar 10, 2023

@petrkasnal The example keyword (singular form) does not support $ref, you need to specify the entire example value inline.

The examples keyword (plural form) supports both $ref (to reference an Example Object definition) and externalValue (to "import" the example value from an external file). The syntax for examples+$ref is:

      content:
        application/json:
          schema:
            $ref: '../BaseSchemas/ApiResult.yml'
          examples:
            UnauthorizedExample:
              $ref: '#/components/examples/UnauthorizedExample'

components:
  examples:
    UnauthorizedExample:
      summary: An example of a 401 Unauthorized response
      value:
        code: 401
        message: The 'Authorization' header is missing or contains an invalid value.

and the externalValue syntax is as follows (but Swagger UI does this support this yet):

      content:
        application/json:
          schema:
            $ref: '../BaseSchemas/ApiResult.yml'
          examples:
            UnauthorizedExample:
              summary: An example of a 401 Unauthorized response
              externalValue: '../examples/UnauthorizedExample.json'
// UnauthorizedExample.json

{
  "code": 401,
  "message": "The 'Authorization' header is missing or contains an invalid value."
}

@petrkasnal
Copy link
Author

@hkosova ok thank you very much for your help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants