Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OneOf property is failing during OAS Schema Validation #2349

Open
RPS044 opened this issue Nov 29, 2023 · 8 comments
Open

OneOf property is failing during OAS Schema Validation #2349

RPS044 opened this issue Nov 29, 2023 · 8 comments

Comments

@RPS044
Copy link

RPS044 commented Nov 29, 2023

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:
image

image

json payload looks like:

--data '{ "billableHeader": { "sourceSystem": "UPSTREAM_APP", "sourceTransactionType": "INVOICE", "eventType": "BATCH", "messageCreationDatetime": "20220811140203", "timeZoneCode": "GMT", "isBulkProcessing": true, "product": "Airlcl" },

@mefellows
Copy link

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?

@mefellows
Copy link

It looks like somebody has already attempted that: https://github.com/ajv-validator/ajv/pull/2262/files

@RPS044
Copy link
Author

RPS044 commented Nov 30, 2023

@mefellows then only with oneOf with discriminator is possible?

@mefellows
Copy link

I don't think mapping is supported at all.

@RPS044
Copy link
Author

RPS044 commented Dec 1, 2023

@mefellows alternated is then using extract policy validation?

@mefellows
Copy link

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.

@epoberezkin
Copy link
Member

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.

@mefellows
Copy link

mefellows commented Jan 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants