Description
I just created an example to illustrate what I think is idiomatic use of discrimator
, so I could help answer #2141. I find it helpful to use JSON Schema Lint so I can validate in real-time. To make sure the discriminating logic worked correctly in a standard JSON Schema validator (not aware of OAS discriminator
), I used standard JSON Schema keywords to duplicate that logic.
This begs the question: now that 3.0 supports a large-enough subset of JSON Schema to describe discriminated subtypes, and 3.1 is planned to support full JSON Schema, do we still need discriminator
?
@handrews mentions the same idea here in #2031, so I think the idea deserves its own issue for future version planning.
I can see that discriminator
might have some value for code generators. It might be easier for a code generator to be told explicitly to discriminate based on a given property, rather than relying on a JSON Schema validator to identify the matched subtype, or recognizing a pattern involving oneOf
, enum
(or const
), etc.
But discriminator
, as it's defined, is kind of problematic. @handrews pointed out that it ignores some available JSON Schema semantics. And I've observed, generally, that the documentation is difficult (for me) to follow, and seems to leave some questions unanswered. Without trying to create a comprehensive list here:
- I have doubts about the combination of
mapping
and default name matching shown in the last example of this section. - It seems that
mapping
is supposed to be supplemental to name matching, rather than replacing it. In that case, is there a way for the discriminator to ensure that the discriminator property value is one of a known list of subtypes? Do we always need a separateoneOf
to validate this? - Does name matching (without
mapping
) assume it's going to find the named subtype schema in#/components/schemas
, or is there some other expectation?
Maybe this is more weight than we need to carry, and we'd be better off leaving this problem to JSON Schema and some new vocabulary for code generation, O-O type system mapping, or something like that.
Metadata
Assignees
Type
Projects
Status
Done