json-schema-ref-parser icon indicating copy to clipboard operation
json-schema-ref-parser copied to clipboard

Relative references using `$def` are being URL encoded

Open drpump opened this issue 6 months ago • 3 comments

We are using a $defs section in our schemas. Schemas within the $defs section are referenced via local file references, and these schemas can themselves have cross references to other files. The ref parser is correctly injecting a$defs cross-reference but replacing the $defs with %24defs (i.e. it is applying URL encoding). I don’t think this behaviour is correct: while $ is a reserved character in the URIs RFC, it is designated as a sub-delimiter

For example in the parent file:

{
  “properties”: {
     “foo”: “string”
  },
  ”$defs”: {
    “myschema”: {
       “$ref”: “./myschema.json”
    },
    ”otherschema”: {
       “$ref”: “./otherschema.json”
    }
  }
}

And the myschema.json file:

{
      “allOf”: [
        { “$ref”: “./otherschema.json” },
        { 
           “properties”: {
              “someProp”: “string”
           }
        }
      ]
}

Flattening results in:

{
  “properties”: {
     “foo”: “string”
  },
  ”$defs”: {
    “myschema”: {
      “allOf”: [
        { “$ref”: “#/%24defs/otherschema.” },
        { 
           “properties”: {
              “someProp”: “string”
            }
        }
      ]  
    },
    ”otherschema”: {
         “properties”: {
            “otherProp”: “string”
         }
     }
  }
}

drpump avatar Aug 14 '24 01:08 drpump