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

Reference definition itself is rendered to example content #4021

Closed
moritz-h opened this issue Dec 11, 2017 · 9 comments · Fixed by #4333
Closed

Reference definition itself is rendered to example content #4021

moritz-h opened this issue Dec 11, 2017 · 9 comments · Fixed by #4333

Comments

@moritz-h
Copy link

moritz-h commented Dec 11, 2017

Q A
Bug or feature request? bug
Which Swagger/OpenAPI version? 3.0.0
Which Swagger-UI version? http://editor.swagger.io
How did you install Swagger-UI? http://editor.swagger.io
Which browser & version? Firefox 57 + Chrome 63
Which operating system? Ubuntu

Demonstration API definition

openapi: '3.0.0'
info:
  title: 'test'
  version: '1.0.0'
paths:
  /hello:
    get:
      description: 'Get welcome message.'
      responses:
        '200':
          description: 'welcome message'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Welcome'
components:
  schemas:
    Welcome:
      type: object
      properties:
        message:
          type: string
      example:
        $ref: '#/components/examples/WelcomeExample'
  examples:
    WelcomeExample:
      value: {
        "message": "Hello, World!"
      }

Configuration (browser query string, constructor, config.yaml)

none using just http://editor.swagger.io

Expected Behavior

Not show the line marked in the following image.

Current Behavior

See red marker in this image:
swagger-ui-bug

Possible Solution

none

Context

none

@moritz-h
Copy link
Author

Also the "value" Property is wrong "value" is part of the Definition, not part of the example content:
https://swagger.io/specification/#exampleObject

@webron
Copy link
Contributor

webron commented Dec 12, 2017

The spec does not support references for example fields, only examples. This means that any value of example will be rendered as-is, as you can see in the UI.

As for your second comment, I didn't get what you meant.

@moritz-h
Copy link
Author

With the second comment, I meant it should only be rendered

{
  "message": "Hello, World!"
}

and not:

{
  "value": {
    "message": "Hello, World!"
  }
}

as is thought "value" is the property name within the Example Object definition and not part of the example data. But with your answer, that everything is rendered as-is, this makes sense.

But for the first question I still think this is a rendering issue. When the reference is not interpreted than I would expect this content:

{
  "$ref": "#/components/schemas/Welcome"
}

When the reference is interpreted and "executed" I would expect this:

{
  "value": {
    "message": "Hello, World!"
  }
}

But actually rendered is this, so the reference is "executed" but also the reference definition is shown.

{
  "value": {
    "message": "Hello, World!"
  },
  "$$ref": "#/components/examples/WelcomeExample"
}

@webron
Copy link
Contributor

webron commented Dec 12, 2017

Heh, yeah, I blame @shockey for that.

@shockey
Copy link
Contributor

shockey commented Dec 12, 2017

Hmm, yeah - this is probably something that moved around with the Swagger-Client resolver. $$ref is used internally to tell where a value came from once everything has been resolved.

Should be a simple fix 😄

@shockey
Copy link
Contributor

shockey commented Mar 15, 2018

Fixed!

@alexgmin
Copy link

alexgmin commented Mar 26, 2018

This is only fixed is the $$ref key is in the first level. This example shows the ref key.

openapi: '3.0.0'
info:
  title: 'test'
  version: '1.0.0'
paths:
  /hello:
    get:
      description: 'Get welcome message.'
      responses:
        '200':
          description: 'welcome message'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Welcome'
components:
  schemas:
    Welcome:
      type: object
      properties:
        message:
          type: string
      example:
        a:
          $ref: '#/components/examples/WelcomeExample'
  examples:
    WelcomeExample:
      value: {
        "message": "Hello, World!"
      }

@shockey
Copy link
Contributor

shockey commented Mar 31, 2018

@alexgmin thanks for the heads up on that! I just merged a fix for that as well.

@krishamoud
Copy link

krishamoud commented Aug 7, 2018

I'm having this issue with an array of $refs
OAI/OpenAPI-Specification#1658

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

Successfully merging a pull request may close this issue.

5 participants