Skip to content

Is there an API to access whitelisted valid values? #1447

@fluxsauce

Description

@fluxsauce

Context

  • node version: 6 LTS
  • joi version: 12.0.x
  • environment node
  • used with standalone
  • any other relevant information: N/A

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

I'd like to populate a user interface with only valid values. I'm using Joi for validation, but is there an interface for getting the valid values out of Joi once it's configured?

https://github.com/hapijs/joi/blob/master/API.md#anyvalidvalue---aliases-only-equal

There's a backdoor way:

const Joi = require('joi');
const constraint = Joi.any().valid([ 'foo', 'bar' ]);
console.log(constraint._valids._set);

which produces

[ 'foo', 'bar' ]

However, that's accessing the internals and I'd rather not depend on that in case the structure changes.

Any suggestions?

Metadata

Metadata

Assignees

Labels

supportQuestions, discussions, and general support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions