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.

External definitions with $ref JSON-pointer

See original GitHub issue

General information

I want to reuse external enumerations for several main schemas. There is a problem referencing external definitions. According to the schema documentation we should be able to reference external definitions with reference like this : “$ref” : “[url]#/definitions/[type]” As pointed in several sites like this: http://www.tothenew.com/blog/using-definitions-internal-to-json-schema-and-external-to-json-schema-version-draft-v4/

  • json-editor version: 1.3.5

Expected behavior

To have a drop-down with the values defined in the external definition when referencing another json at the same level as the main document with : “$ref”: “./enums.json#/definitions/types” “$ref”:“enums.json#/definitions/types”

Actual behavior

The enums.json file is actually found and fetched with an ajax call.
The field is broken and displays a drop-down with property types (string, object, etc…)

Steps to reproduce the behavior

Two schema files defined in the same project folder

main.json

{  
   "$schema":"http://json-schema.org/draft-04/schema#",
   "type":"object",
   "definitions":{  
      "envInternal":{  
         "type":"string",
         "enum":[  
            "Production",
            "UAT",
            "Performance",
            "Development",
            "Test"
         ]
      }
   },
   "properties":{  
      "brokenDropDown":{  
         "title":"Environment",
         "$ref":"enums.json#/definitions/envExternal"
      },
  "workingDropDown":{  
         "title":"Environment",
         "$ref":"#/definitions/envInternal"
      }
   }
}

enums.json

{  
   "$schema":"http://json-schema.org/draft-04/schema#",
   "definitions":{  
      "envExternal":{  
         "type":"string",
         "enum":[  
            "Production",
            "UAT",
            "Performance",
            "Development",
            "Test"
         ]
      }
   }
}

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
vmanasievcommented, Jun 17, 2019

@pmk65 To some extend it seems to address the same issue. Although this change is made on top of an older code and I don’t think it is applicable straight away. So when I have time I will try to push my modifications for a review. I think I have addressed two more issues :

  1. work correctly with “up-a-level” relative paths like “…/xxxxxx”
  2. Managing correctly resources with same name Lets say we have to json files with same name “/path1/fileName.json” and “/path2/fileName.json” and they are both loaded with “$ref”:“./fileName.json” by “/path1/refferer1.json” , “/path2/refferer2.json” Currently the code will try to store them both in jsoneditor.ref with key “./fileName.json” Second one will not be stored at all because such key already exists. So I think it is better if store the full url in the “refs” and refs_with_info" properties
0reactions
robocodercommented, Mar 6, 2021

I think I fixed this in #928

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using definitions internal to json schema and external to json ...
$ref says either reference external schema or schema itself. Hence, it acts as JSON pointer. Now in $ref 's value # refers to...
Read more >
Definitions & References - JSON Schema
Json Pointer Evaluation. Let J be a JSON document. JSON Pointers are intended to extract a part of J that is specifically indexed...
Read more >
How to use JSON references ($refs) - Redocly
Reference a definition within a file by remote URL and pointer to the object. Definition within same file. Use a JSON Pointer to...
Read more >
Using $ref - Swagger
With OpenAPI 3.0, you can reference a definition hosted on any location. ... JSON Reference notation, and the portion starting with # uses...
Read more >
Structuring a complex schema — Understanding JSON ...
Base URI determination and relative reference resolution is defined by RFC-3986. ... The most common way to do that is to use a...
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