Example of how to embed the 2020-12 schema #797
Replies: 2 comments 1 reply
-
Hey there @Mercury-Fred ! I maintain a CLI tool (https://github.com/sourcemeta/jsonschema) that has great support for bundling schemas. See https://github.com/sourcemeta/jsonschema/blob/main/docs/bundle.markdown for specific documentation on the To learn more about how bundling works, it might help to try a few ones on that CLI, and also read https://json-schema.org/blog/posts/bundling-json-schema-compound-documents. Happy to explain a specific example if you have one. |
Beta Was this translation helpful? Give feedback.
-
I don't know the context here, but you shouldn't need to bundle the meta-schema. JSON Schema implementations should already have the meta-schemas for the dialects they support built-in. No network request necessary. If you have other schemas that your schema references, you still may not need to bundle. Although many JSON Schema implementations will attempt to make a network request to retrieve a schema it doesn't know, that's generally not the way it works. Implementations generally expect you to provide the schemas you expect to use and then use those given schemas to resolve references rather than making a network request. The only time a bundle is useful is as a way to distribute a set of schemas, but really a tar/zip of the necessary schemas does the job just as well. |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I would like to use the 2020-12 schema on a machine w/o network access. Therefore I need to embed the schema resources. I found this discussion https://github.com/orgs/json-schema-org/discussions/231 that provides what appears to be the bundled schema resources. However, I'm still unclear on how I would reference this bundled schema instead of my existing reference to the "https://json-schema.org/draft/2020-12/schema".
I'm not a power user of JSON schema - but it appears the bundled schema is structured at a "base level" - as is my schema. I tried just concatenating the two together but that doesn't work - thus I assume there is some level of integration I need to do to get my existing schema to properly reference the provided bundled 2020-12 schema resources, but I'm unclear how to go about that. I'm sure its common sense to most people reading this but its probably so obvious I didn't find any good references explaining this. Maybe I change my "schema" statement referencing the https:// schema resource to a "ref" statement, and reference the bundled schema as an internal resource, but unclear.
Also I noticed the bundled schema seems to use Ids that are identical to the original https references. This makes sense but raises the question of how I can verify that the embedded resources are being referenced and nothing is being fetched from internet. (w/o special configuration of a machine w/o network access, etc). I'm sure as soon as I submit my PR to our private builds the reviewers will raise this question.
Thanks so much for your insights!
Beta Was this translation helpful? Give feedback.
All reactions