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

Runtime discriminator to be able to support useDefaults within anyOf/oneOf #2375

Closed
cmawhorter opened this issue Feb 4, 2024 · 1 comment

Comments

@cmawhorter
Copy link

What version of Ajv you are you using?
8.12.0

What problem do you want to solve?
Ajv ignores or throws when a default is used within oneOf/anyOf/not.

The reasons for this are understandable, but it's a frequent source of confusion and severely limits the usefulness of the default keyword when using the useDefaults option.

The OpenAPI discriminator keyword is an option, but requires using the problematic oneOf that literally means only one of these schema and can cause subtle problems.

What do you think is the correct solution to problem?
The app knows best about resolving ambiguity, so why not allow it to define a function that can tell ajv how to proceed?

I'd propose an optional runtime discriminator that ajv would call to get a definitive answer on which branch to use. This would allow defaults to behave normally, remain statically defined within the schema, and could even improve performance.

Will you be able to implement it?
Sure, but I don't know too much about the inner workings of ajv.

@cmawhorter
Copy link
Author

meh. closing this because discriminator+oneOf seems to work fine for my immediate case so 🤷

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

No branches or pull requests

1 participant