question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

$ref in response example relative to response example

See original GitHub issue

I am using a $ref in a response example that, when the response is returned, is interpreted correctly as relative to the response itself:

responses:
  200:
    description: OK
    schema:
      "$ref": "#/definitions/CollectionOfFoos"
    examples:
      application/json:
        foos:
          - id: 00000000-0000-0000-0000-000000000000
            name: sample foo 0
            bar:
              id: 0
              "$ref": "#/refs/bars/0"
            baz:
              id: 42
              "$ref": "#/refs/bazzes/myBaz"
          - id: 00000000-0000-0000-0000-000000000001
            name: sample foo 1
            bar:
              "$ref": "#/refs/bars/0"
            baz:
              "$ref": "#/refs/bazzes/myOtherBaz"
        refs:
          bars:
            0:
              detail: "Additional detail about this bar..."
          bazzes:
            myBaz:
              detail: "Additional detail about this baz..."
            myOtherBaz:
              detail: "Additional detail about this other baz..."

So, were that example response to be sent to a consumer, the pointer in those $refs would point to the refs member on the response. This is a contrived example, but we do this for “normalization” purposes, so that more than one foo can refer to the same bar or baz.

The problem is that this doesn’t comply with the spec, since those $ref elements that will later resolve correctly don’t do so when the API including examples is checked for compliance. That first $ref ("$ref": "#/definitions/CollectionOfFoos") is perfectly compliant, since in the API doc there is something at definitions/CollectionOfFoos, but there isn’t anything at refs/bazzes/myBaz, etc., so those lines throw an error with the description $refs must reference a valid location in the document. Is there any way around this, or a better way to approach this problem?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
webroncommented, Aug 9, 2019

@brennon Forgot to mention, since I’m related to the SwaggerHub team, I can tell you that as far as I know, the fact that you get resolution errors is being worked on so that references within examples will not be resolved.

1reaction
webroncommented, Aug 9, 2019

Maybe should have used SHOULD 😉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: $ref in response example relative to response exam...
Solved: I am using a $ref in a Swagger 2.0 API response example that, when the response is returned , is interpreted correctly...
Read more >
Using $ref - Swagger
The value of $ref uses the JSON Reference notation, and the portion starting with # uses the JSON Pointer notation. This notation lets...
Read more >
$ref in response example - swagger - Stack Overflow
This is a bug in Swagger Editor and UI. As a workaround, define a schema for your response and use a schema example...
Read more >
How to use JSON references ($refs) - Redocly
The value of the <reference> is a JSON Reference which is composed of two parts <relative path to file or URL><JSON pointer> ....
Read more >
Step 5: Response example and schema (API reference tutorial)
The response example is not comprehensive of all parameter configurations or operations, but it should correspond with the parameters passed in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found