You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just implemented a JSON-Schema validator and would like to add OpenAPI support to it.
I'm now stuck at adding discriminators with the "allOf" variant.
According to the spec a "discriminator MAY be added to a parent schema definition, and all schemas comprising the parent schema in an allOf construct may be used as an alternate schema."
However, I can't find the definition of "parent". The term "parent" in JSON Schema seems to mean something unrelated in JSON Schema, and I didn't see anything in the OpenAPI spec. I'm assuming it is the "parent" in the inheritance hierarchy, but that's not something that is well defined in JSON Schema (afaik).
Also: I can't just do this dynamically (waiting to encounter an discriminator), as I need to have the mappings targets statically. After, all, I might get the generic schema as "type" and then use the discriminator to validate the more specialized one.
I'm guessing that one isn't valid, but my gut instinct would have said the same for the allOf of the allOf.
There are also some interesting cases:
If I have a schema in a different schema-resource (for example 'https://gigantic-server.com/schemas/Monster') that references my discriminator schema with "allOf", then clearly I can't find that schema. However, what if that same schema-resource is loaded through other means?
Does that schema then count as a target for the mapping?
Roughly:
# Let's give this the URI "URI-DISCRIMINATOR"Pet:
type: objectrequired:
- petTypeproperties:
petType:
type: stringdiscriminator:
propertyName: petTypeUnrelated:
# An unrelated schema references the external schema resource.if: https://gigantic-server.com/schemas/Monster# With https://gigantic-server.com/schemas/Monster:all-of:
- $ref: URI-DISCRIMINATOR/Pet...
It feels like finding all possible schemas that have the discriminator in it can become quite complicated.
Is there a description somewhere of how I can find all possible targets?
The text was updated successfully, but these errors were encountered:
I'm not aware of any comprehensive explanation. If the OpenAPI Description is a single document, then my assumption is that the entire schemas section of the Components Object should be searched for schemas that use allOf to reference the schema with the discriminator. If your description is multiple documents, it's ambiguous as to which Components document should be searched.
I just implemented a JSON-Schema validator and would like to add OpenAPI support to it.
I'm now stuck at adding discriminators with the "allOf" variant.
According to the spec a "discriminator MAY be added to a parent schema definition, and all schemas comprising the parent schema in an allOf construct may be used as an alternate schema."
However, I can't find the definition of "parent". The term "parent" in JSON Schema seems to mean something unrelated in JSON Schema, and I didn't see anything in the OpenAPI spec. I'm assuming it is the "parent" in the inheritance hierarchy, but that's not something that is well defined in JSON Schema (afaik).
Also: I can't just do this dynamically (waiting to encounter an discriminator), as I need to have the mappings targets statically. After, all, I might get the generic schema as "type" and then use the discriminator to validate the more specialized one.
There are a few cases that are obvious:
According to #2165 (comment) an
allOf
of anallOf
is also a valid target.What about a reference in an
if
?I'm guessing that one isn't valid, but my gut instinct would have said the same for the
allOf
of theallOf
.There are also some interesting cases:
If I have a schema in a different schema-resource (for example 'https://gigantic-server.com/schemas/Monster') that references my discriminator schema with "allOf", then clearly I can't find that schema. However, what if that same schema-resource is loaded through other means?
Does that schema then count as a target for the mapping?
Roughly:
It feels like finding all possible schemas that have the discriminator in it can become quite complicated.
Is there a description somewhere of how I can find all possible targets?
The text was updated successfully, but these errors were encountered: