Skip to content

Relative references using $def are being URL encoded #356

New issue

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

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

Already on GitHub? # to your account

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

Relative references using $def are being URL encoded #356

drpump opened this issue Aug 14, 2024 · 5 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.

@KurtGokhan
Copy link
Contributor

KurtGokhan commented Apr 25, 2025

Is there a plan to fix this? Is there a workaround?

Edit: I guess it works if I replace all $defs with definitions, and wrap all $ref in allOf because of the issue #370

@jonluca
Copy link
Collaborator

jonluca commented Apr 25, 2025

Not currently, although we are open to PRs

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

No branches or pull requests

5 participants