Open RPS044 opened 10 months ago
According to the docs, mapping is not supported: https://ajv.js.org/json-schema.html#discriminator.
It's unclear clear why that's the case. If the author is open to a PR perhaps you could add the feature?
It looks like somebody has already attempted that: https://github.com/ajv-validator/ajv/pull/2262/files
@mefellows then only with oneOf with discriminator is possible?
I don't think mapping is supported at all.
@mefellows alternated is then using extract policy validation?
I'm not sure what that means, sorry, but to work around it you can not using the mapping. See https://swagger.io/specification/v3/#discriminator-object for how it works without mapping.
OpenAPI defines discriminator as tooling support and no-op from validation point of view - actual validation happens as defined in oneOf. Mapping may lead to contradictory schema, so is not supported. You can add it as a custom keyword to be ignored and allowed in schemas. Also, you have to use discriminator option.
Thanks for your response @epoberezkin!
I'm still a little confused as to why we wouldn't want to support this feature. I appreciate it's not currently supported and it's a limitation (as you had documented already).
OpenAPI defines discriminator as tooling support and no-op from validation point of view - actual validation happens as defined in oneOf
That's not how I read the spec: https://spec.openapis.org/oas/v3.0.3#discriminator-object. I'm not all that familiar with spec reading and interpretation, so perhaps I'm mistaken. Or should I be looking at the JSON Schema dialect for this?
Mapping may lead to contradictory schema, so is not supported.
Is this something ajv
must consider in features? Isn't it already possible to create contradictory schemas without mapping
already? For example the following is illogical:
{
"allOf": [
{ "type": "string" },
{ "type": "number" }
]
}
You can add it as a custom keyword to be ignored and allowed in schemas. Also, you have to use discriminator option.
This will have the effect of ignoring the mapping, correct? I'm looking for a solution that would include incorporating the entire mapping and discriminator vocabulary into the parsing of the document. If you know of a workaround, I would be very grateful to hear of it.
Hello Team,
Requesting you to please check this issue and help. Performing schema validation with oneOf, discriminator and mapping property in oas3.0.
Error: { "fault": { "faultstring": "OASValidation MAM-EXT-SpecValidation with resource "oas://openapi.yaml": failed with reason: "[ERROR - An error occurred during schema validation - com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NullPointerException.: []]"", "detail": { "errorcode": "steps.oasvalidation.Failed" } } }
yaml file looks like:
json payload looks like:
--data '{ "billableHeader": { "sourceSystem": "UPSTREAM_APP", "sourceTransactionType": "INVOICE", "eventType": "BATCH", "messageCreationDatetime": "20220811140203", "timeZoneCode": "GMT", "isBulkProcessing": true, "product": "Airlcl" },