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

Bundling should sanitize $defs elements and update $ref #207

Open
mpviau opened this issue Jan 13, 2025 · 1 comment
Open

Bundling should sanitize $defs elements and update $ref #207

mpviau opened this issue Jan 13, 2025 · 1 comment

Comments

@mpviau
Copy link

mpviau commented Jan 13, 2025

It seems the bundling correctly adds the $defs section to the schema being bundled. However, when the referenced schema id is a full URI, it leads to reference names containing invalid characters such as : and /. Also, the original $ref occurrences in the original schema are not updated with the local reference.

@jviotti
Copy link
Member

jviotti commented Jan 13, 2025

Hey @mpviau ,

Many JSON Schema tools out there attempt to de-reference schemas in non-compliant manners that have certain edge cases. This tool is following the "standard" bundling approach documented here: https://json-schema.org/blog/posts/bundling-json-schema-compound-documents. In this compliant manner:

  • The original $refs are not supposed to be updated. When a compliant JSON Schema implementation sees the bundled schema, it first considers all $ids across the various embedded resources and pre-populates its internal cache

However, when the referenced schema id is a full URI, it leads to reference names containing invalid characters such as : and /

Are you referring to the property names in $defs? If so, that's OK. There is no limitation on the characters that can happen there and : and / are totally valid as per the JSON grammar!

Do you have an example that is incorrectly bundled and does not work?


Leaving that aside, if you are dealing with non-compliant JSON Schema implementations, we have implemented --without-id in the bundle command that after performing bundling, will get rid of all schema identifiers and re-phrase references from the root. i.e. https://github.com/sourcemeta/jsonschema/blob/main/docs/bundle.markdown#bundle-a-json-schema-without-identifiers-and-importing-a-single-local-schema

But note that we only support that for problematic implementations. Compliant ones should work just fine with the normal approach. Let me know if that helped!

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

2 participants