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

Add support for recursive warnings #2739

Open
imjoshin opened this issue Feb 8, 2022 · 0 comments · May be fixed by #2743
Open

Add support for recursive warnings #2739

imjoshin opened this issue Feb 8, 2022 · 0 comments · May be fixed by #2743

Comments

@imjoshin
Copy link

imjoshin commented Feb 8, 2022

Context

This feature requests comes from the discussion in #2669.

  • node version:
  • module version:
  • environment (e.g. node, browser, native):
  • used with (e.g. hapi application, another framework, standalone, ...):
  • any other relevant information:

What problem are you trying to solve?

We currently have the ability to set warnings on unknown keys within an object of Joi, but not recursively. It would be nice to have the ability to say "I have an object and if I receive any unknown keys at any depth, I'd like to warn the user." The following technically works, but is not great as it can hide future problems validating joi config.

const wrappedJoiObjectWithUnknownWarnings = <TSchema = any, T = TSchema>(schema?: SchemaMap<T>): ObjectSchema<TSchema> =>
  joi.object(schema)
    .pattern(/.*/, joiInstance.any().warning(`any.unknown`))

joiInstance.object = wrappedJoiObjectWithUnknownWarnings

Do you have a new or modified API suggestion to solve the problem?

Joi.object().pattern(/.*/, Joi.any().warning('any.unknown'));

Given the single-level warning above, I'm not sure what the best approach here would be. Attaching a recursive argument into one of these would make sense, but doesn't feel right in any of the method calls. My initial idea is to add a Joi.rules or some other top-level method to set up these types of controls.

@imjoshin imjoshin linked a pull request Feb 16, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant