Nesting/grouping definitions in schema defs #954
Replies: 2 comments 1 reply
-
|
Unfortunately, it isn't possible to support nested {
"$defs": {
"foo": {
"title": { "type": "date" }
}
}
}If If you really want to have nested The only way things like schema validation and autocomplete can be supported is if it isn't unambiguous whether a location is a schema or an object. Because schemas are represented as objects, supporting nested {
"$ref": "#/$defs/a/$defs/b",
"$defs": {
"a": {
"$defs": {
"b": { ... }
}
}
}
}
I don't know the details of you specific circumstance, but generally my advice in these situations is, don't write large schemas. Break it down into smaller pieces and compose them as needed. You can use a bundler if you need to distribute them as a single schema, but it's much easier to work with smaller schemas when developing. Usually, each of your definitions can be their own schema and the directory structure you use to store those schemas is how you organize them. What you end up with is
I think the text you quoted is pretty clear. Perhaps you tried using nested |
Beta Was this translation helpful? Give feedback.
-
|
Thank you for the detailed explanation. This makes a lot of sense the issues with using schemas in this way, and we'll be looking at alternatives.
It's not clear to me what part of the spec makes the nesting invalid. Assuming no keywords are used, this seems like it would fall under the empty schema definition which would be valid. For posterity, perhaps this could be better clarified $defs section in the spec? And yes you are spot on that nesting has worked with other tools which led to the confusion. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is it allowed to use objects within JSON schema defs to group/organize children definitions? Something like-
The specs at https://json-schema.org/draft/2020-12/json-schema-core#name-schema-re-use-with-defs state-
It's unclear to me if object with other objects is valid or not.
This behavior is useful for us to when working with a large schema with lots of defs.
Beta Was this translation helpful? Give feedback.
All reactions