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 to definitions in another file not working?

See original GitHub issue

I cannot make references to external definitions to work, when running a copy of https://json-editor.github.io/json-editor/ on localhost (using python’s http.server and with AJAX switched on).

To explain, let’s say I have common.schema.json with

{
  "$schema": "http://json-schema.org/draft-04/schema",
  "definitions": {
    "known-product": {
      "title": "product",
      "type": "string",
      "enum": [ "power", "hydrogen", "heat" ]
    }
  },
  "title": "test",
  "properties": {
    "customer": { "type": "string" },
    "product": { "$ref": "#/definitions/known-product" }
  }
}

and test.schema.json with

{
  "$schema": "http://json-schema.org/draft-04/schema",
  "title": "Ref. tests",
  "properties": {
    "test-1": { "$ref": "common.schema.json#" },
    "test-2": { "$ref": "common.schema.json#/definitions/known-product" },
    "test-3": {
      "type": "object",
      "properties": {
        "Product": { "$ref": "./common.schema.json#/definitions/known-product" }
      }
    }
  }
}

Then, I put both schemas to the same folder as index.html, activate AJAX, and use test.schema.json in the editor.

In the generated editor, I would expect test-1 to ignore definitions and show customers and product, while both test-2 and test-3 should read only definitions/known-product and therefore show only the product selection. However, all three test show the same (customer and product), suggesting that that $ref ignores everything after # and simply includes the whole file. Is this a bug, a missing feature, or am I just doing it wrong?

Note: it could be related to this pull request, but it is marked as “merged” and the examples all use internal references, despite the title mentioning “nonlocal definitions”…

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
robocodercommented, Mar 9, 2021

Yeah, when I dumped the refs, I found the key was malformed which is why the schemaloader couldn’t resolve the JSON pointer path, eg “animals.json#/definitions/cat#/definitions/cat”.

0reactions
robocodercommented, Apr 13, 2021

p.s. I have a fix; I’ll submit a PR as soon as I have time to write the tests for it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fails to resolve file-based $refs with definitions #8 - GitHub
As a workaround for now, I can get it to work by splitting each definition into a separate file e.g.. # error.yaml type:...
Read more >
Unable to reference $ref schema from different file
The type of schema applied to the document is not supported. I am attempting to use JSchema : var schema = JSchema.Parse(@"{ '$ ......
Read more >
Using $ref - Swagger
With OpenAPI 3.0, you can reference a definition hosted on any location. It can be the same server, or another one – for...
Read more >
How to correct a #REF! error - Microsoft Support
The #REF! error shows when a formula refers to a cell that's not valid. This happens most often when cells that were referenced...
Read more >
Programming FAQ — Python 3.11.1 documentation
Contents: Programming FAQ- General Questions- Is there a source code level debugger with breakpoints, single-stepping, etc.?, Are there tools to help find ...
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