Swagger-editor: Using $ref in request body schema hides defined example

Created on 21 Sep 2017  路  3Comments  路  Source: swagger-api/swagger-editor

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

Most helpful comment

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

All 3 comments

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

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

This should be fixed now 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marcopiraccini picture marcopiraccini  路  3Comments

Andriy-Kulak picture Andriy-Kulak  路  3Comments

freak4pc picture freak4pc  路  3Comments

fchebbo picture fchebbo  路  5Comments

ljerka picture ljerka  路  5Comments