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

Is it safe to use Schema._inner[n].children to walk through a schema as defined by Joi.object.keys({})? #1092

Closed
pr1ntr opened this issue Jan 25, 2017 · 2 comments
Labels
support Questions, discussions, and general support

Comments

@pr1ntr
Copy link

pr1ntr commented Jan 25, 2017

Context

  • node version: 6.5
  • joi version: 10.1
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

What are you trying to achieve or the steps to reproduce ?

If i want to validate server payload (json) against the schema props and not running the validate function could I reliably dig into:
schema._inner.children[n].schema._inner[n2]
recursively to figure out the object keys that belong there?

const schema = Joi.object().keys({
  hmaId: Joi.string().max(255).required(),
  modelName: Joi.string().max(255).required(),
  modelYear: Joi.number().required(),
  modelData: Joi.object().keys({
    disclaimers: Joi.array().items(
      Joi.object().keys({
        key: Joi.string().required(),
        text: Joi.string().required(),
      }),
    ),
  }).required(),
}).unknown(false)

Which result you had ?

It seems pretty consistent but just want to make sure.

What did you expect ?

that it is consistent...

@pr1ntr pr1ntr changed the title Is it safe to use Schema._inner[n].children to walk through a schema as defined by Joi.object.keys({}) Is it safe to use Schema._inner[n].children to walk through a schema as defined by Joi.object.keys({})? Jan 25, 2017
@WesTyler
Copy link
Contributor

It's safer to use the undocumented .describe() method on the schema object. :)

@Marsup may change _inner without notice

@pr1ntr
Copy link
Author

pr1ntr commented Jan 25, 2017

ok cool! I couldn't find anything else in the docs. this will help.

@pr1ntr pr1ntr closed this as completed Jan 25, 2017
@Marsup Marsup added the support Questions, discussions, and general support label Jan 26, 2017
@Marsup Marsup self-assigned this Jan 26, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

3 participants