Skip to content

$$ref appears in referenced JSON file for example #3638

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

Closed
donaldpipowitch opened this issue Sep 6, 2017 · 7 comments
Closed

$$ref appears in referenced JSON file for example #3638

donaldpipowitch opened this issue Sep 6, 2017 · 7 comments

Comments

@donaldpipowitch
Copy link

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? v3
Which Swagger-UI version? v3.1.7
How did you install Swagger-UI? $ npm i swagger-ui-dist
Which browser & version? Chrome 60
Which operating system? Mac

Demonstration API definition

openapi: 3.0.0
info:
  title: Example API
  version: 1-draft

paths:
  /:
    get:
      summary: Returns foo.
      responses:
        200:
          description: |-
            The foo object.
          examples:
            application/json:
              $ref: "examples/root.json"
{
  "foo": "bar"
}

Expected Behavior

Swagger UI renders my example as:

{
  "foo": "bar"
}

Current Behavior

Swagger UI renders my example as:

{
  "foo": "bar",
  "$$ref": "examples/root.json"
}

image


Note: If I use a .yaml instead like this:

Example: |-
  {
    "foo": "bar"
  }

And write $ref: "examples/root.yaml#/Example" the example renders correctly.

@shockey
Copy link
Contributor

shockey commented Sep 21, 2017

Fixed.

Thanks for the report, @donaldpipowitch!

@donaldpipowitch
Copy link
Author

Thank you for the fix.

@dmolesUC
Copy link

dmolesUC commented Nov 7, 2017

I'm still seeing this in 3.4.3:

screen shot 2017-11-07 at 12 43 02 pm

You can see this by pasting https://github.com/raw/dmolesUC3/stash_api/153b5a25b95436df7c76ba0280ae762e3dfc337e/public/openapi.yml into the petstore.swagger.io Explore bar. Is there something wrong with my syntax?

components:
  schemas:
    root:
      type: object
      properties:
        _links:
          $ref: '#/components/schemas/hal_links'
      required:
        - _links
      example:
        $ref: examples/root.json

Or is it possibly fixed for operation examples, but not schema examples?

@webron
Copy link
Contributor

webron commented Nov 8, 2017

According to the spec, Schema Object's example does not support a reference value. You'd have to add the example inline for it to work.

@dmolesUC
Copy link

dmolesUC commented Nov 8, 2017

I believe you, but can you explain what's going on in the first example of this section of the spec?

Examples Object

In an example, a JSON Reference MAY be used, with the explicit restriction...

# in a model
schemas:
  properties:
    name:
      type: string
      example:
        $ref: http://foo.bar#/examples/name-example

@dmolesUC
Copy link

dmolesUC commented Nov 8, 2017

It looks like "Examples Object", plural, has been removed from the 3.0.1 spec, so maybe that section was in error.

@webron
Copy link
Contributor

webron commented Nov 8, 2017

The Examples Object was a left over in 3.0.0 - but it's not referenced anywhere inside the specification so it's not really relevant. If you look at the Schema Object, at the example field itself, that's what matters.

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

No branches or pull requests

4 participants