Replies: 3 comments 1 reply
-
I'm not sure what you're getting at. I'm not seeing how the text implies that anything is combined. You are, of course, correct that there is no "combining" in this or any other aspect of JSON Schema. |
Beta Was this translation helpful? Give feedback.
-
The text states that common text can be moved out of each schema ("factored out") and that both schema examples are equivalent, which to me suggests that schemas can be optimized in not to have to repeat the moved out parts, which is not the case. |
Beta Was this translation helpful? Give feedback.
-
That's not how I read "equivalent" - the same outcome happens only in a particular use case, so this technique is not transferrable to other use cases. I will leave it at that, however. Thanks for your insights. |
Beta Was this translation helpful? Give feedback.
-
Wonder if anyone can provide any insights into what the JSON Schema guide is saying about
oneOf
and how common parts can be "factored out" fromoneOf
parts. Here's the link and the text:https://json-schema.org/understanding-json-schema/reference/combining.html?highlight=oneof#factoring-schemas
This is the example.
However, it appears that the text incorrectly characterizes that both schemas are equivalent, while the top one has 2 schemas and the bottom one has 3 schemas, each applied independently and not combined, as the text implies.
If schemas were indeed combined as described, then it would be possible to introduce alternative fields, like this:
However, because each schema is applied independently a document like this would fail, because
y
is not defined in the top schema and because both schemas inoneOf
match, since each allows additional properties, meaning that outeradditionalProperties
is not applied here either:Shouldn't the Factoring Schemas instead say that in this specific case, the top schema and one of the
oneOf
branches are applied independently and for some configurations will appear like common parts are "factored out", but won't work in general?Beta Was this translation helpful? Give feedback.
All reactions