Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relative references using $def are being URL encoded #356

Open
drpump opened this issue Aug 14, 2024 · 3 comments
Open

Relative references using $def are being URL encoded #356

drpump opened this issue Aug 14, 2024 · 3 comments

Comments

@drpump
Copy link

drpump commented Aug 14, 2024

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”
         }
     }
  }
}
@lindenquan
Copy link

lindenquan commented Aug 14, 2024

There was the same issue 262 which was closed in March. However, This issue still exists in the latest version

@drpump
Copy link
Author

drpump commented Aug 14, 2024

Note that this is occurring in v11.6.4. I haven’t updated to 11.7 yet.

I encountered this issue with v11.6.4. Just did a quick test with 11.7 and it makes no difference.

@simontaurus
Copy link

simontaurus commented Sep 8, 2024

It also seems like the $defs keyword of a schema is not handled like the previous keyword definitions, but since this is not enforced and the convention changed over time makes it really tricky.
See also: https://json-schema.org/draft/2019-09/release-notes#semi-incompatible-changes

Code dealing with "definitions"
https://github.com/search?q=repo%3AAPIDevTools%2Fjson-schema-ref-parser+definitions&type=code

Especially:

// Most people will expect references to be bundled into the the "definitions" property,

No matching code for "defs"
https://github.com/search?q=repo%3AAPIDevTools%2Fjson-schema-ref-parser+defs&type=code

However, not really related to the encoding of $ in json-pointers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants