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.

internal reference in schema

See original GitHub issue

I am trying to dereference resolved schema object. But it is throwing error as “Error resolving $ref pointer “#/definitions/ApiCallList”. Token “definitions” does not exist.”

Is this a bug or What is the correct way to define $ref to refer internal definition within the schema object.

$RefParser = require('json-schema-ref-parser') $RefParser.dereference(schema, { $refs: { circular: "ignore" } }) .then(function(resolvedSchema) { res.send(resolvedSchema); })

Sample Schema { "definitions":{ "ApiCallList":{ "description":"A list of Api Call Resources", "id":"ApiCallList" }, "MaskCallList":{ "description":"A list of Mask Call Resources", "id":"MaskCallList" } }, "resources":{ "api-call":{ "methods":{ "request":{ "$ref":"#/definitions/ApiCallList }, "response":{ "$ref":"#/definitions/MaskCallList } } } } }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JamesMessingercommented, Jan 3, 2017

Hi, @dave-irvine. Sorry, I somehow missed your comment from two weeks ago; otherwise, I would have responded sooner.

The behavior you’re seeing is by design and per the JSON Pointer spec. JSON pointers are relative to the root of the document they’re in. So, in paths.yaml, the $ref to #/definitions/User is invalid. You should replace it with swagger.yaml#/definitions/User instead.

0reactions
JamesMessingercommented, Jul 30, 2018

As far as I can tell, everything is behaving as expected and according to the spec. Perhaps I don’t understand something. Can somebody please provide a reproduction of the issue, preferably on RunKit?

Here are reproductions of other issues, as examples:

https://runkit.com/bigstickcarpet/json-schema-ref-parser-issue-93

https://runkit.com/bigstickcarpet/swagger-cli-issue-19

https://runkit.com/bigstickcarpet/swagger-parser-issue-90

Read more comments on GitHub >

github_iconTop Results From Across the Web

JSON schema definitions validation for internal reference
The JSON Schema you have provided includes a reference to another schema, which you haven't included in the provided schema. In addition you...
Read more >
Definitions & References - JSON Schema
Reference Specification​​ The idea of a reference such as {"$ref": "#/definitions/person"} is to use the schema that is stored under the result of...
Read more >
Structuring a complex schema — Understanding JSON ...
A schema can reference another schema using the $ref keyword. The value of $ref is a URI-reference that is resolved against the schema's...
Read more >
Using $ref - Swagger
To reference a definition, use the $ref keyword: $ref: 'reference to definition'. For example, suppose you have the following schema object, which you...
Read more >
Using definitions internal to json schema and external to json ...
definitions refer to shared properties which could be reused throughout schema or by some external schema. · $ref says either reference external ...
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