Closed oravecz closed 10 months ago
You're misunderstanding how discriminator
works. It doesn't effect the validation outcome. It just serves as meta-data that can optionally allow the validator to provide more helpful error output when using anyOf
or oneOf
. You don't have an anyOf
or oneOf
, so the discriminator
has no effect at all.
Have a look at https://stackoverflow.com/questions/38717933/jsonschema-attribute-conditionally-required/38781027#38781027 to see some techniques for conditional validation. discriminator
is intended to be used with the "Enum" pattern described in that post.
Also, keep in mind that discriminator
isn't a JSON Schema keyword, it's an OpenAPI extension. That means that if you use $schema: 'https://json-schema.org/draft/2020-12/schema'
, it won't know what discriminator
is and ignore it.
This implementation understands the OpenAPI 3.0 dialect (https://spec.openapis.org/oas/3.0/dialect
) and the OpenAPI 3.1 dialect (https://spec.openapis.org/oas/3.1/dialect/base
). If you use one of those with $schema
, discriminator
will be understood, but this implementation doesn't do anything special with the meta-data it provides.
Online tool shows that the JSON payload below is valid for the given JSON Schema.
My expectation is the discriminator
criterion
will indicate the payload forSINGLE_SELECT
will contain a requiredvalue
property.When validated, the
SINGLE_SELECT
criterion is recognized as valid JSON, even though thevalue
property is not present.JSON
Schema