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

Using $ref in request body schema hides defined example #1501

Closed
gerbsen opened this issue Sep 21, 2017 · 3 comments
Closed

Using $ref in request body schema hides defined example #1501

gerbsen opened this issue Sep 21, 2017 · 3 comments

Comments

@gerbsen
Copy link

gerbsen commented Sep 21, 2017

hello, currently it's not possible to define an example for a request body if I reference another object. only default/null values are shown as example.

This can be seen here: (example is empty since no properties defined for Configuration)

openapi: 3.0.0
info:
  description: what a description
  version: 1.0.0
  title: API Docs
servers:
  - url: 'https://some.url.net'
paths:
  /some/path:
    post:
      summary: THis is a summary
      description: This should be a long description...
      requestBody:
        description: Optional description in *Markdown*
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Configuration'
            example:
              sources:
              - id: '1'
                lat: 52.450411
                lng: 13.43755
      responses:
        '200':
          description: Totally cool
          
components:
  schemas:
    Configuration:
      type: object

screenshot 2017-09-21 13 49 51

If we change this to that:

openapi: 3.0.0
info:
  description: what a description
  version: 1.0.0
  title: API Docs
servers:
  - url: 'https://some.url.net'
paths:
  /some/path:
    post:
      summary: THis is a summary
      description: This should be a long description...
      requestBody:
        description: Optional description in *Markdown*
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Configuration'
      responses:
        '200':
          description: Totally cool
          
components:
  schemas:
    Configuration:
      type: object
      example:
        sources:
        - id: '1'
          lat: 52.450411
          lng: 13.43755

screenshot 2017-09-21 13 49 38

Then this works as expected, but forces me to use one example for all requests, I also validated this against another OpenAPI Viewer (Koumoul).

Hope this get's fixed soon.
Thanks, Daniel

@hkosova
Copy link
Contributor

hkosova commented Sep 21, 2017

Swagger UI does not currently display the example and examples defined under content.<media-type> - see swagger-api/swagger-ui#3437. The workaround is to use schema-level examples.

@gerbsen
Copy link
Author

gerbsen commented Sep 21, 2017

This is not a really a workaround since I have to use the same example everywhere :(

@shockey
Copy link
Contributor

shockey commented Aug 28, 2018

This should be fixed now 😄

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