Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

384
Visualizações
Is there a way to validate strings that represent nested object keys in Joi?

I'm using joi@^17.4.0 and have a schema that looks like this:

settings: Joi.object({
  isHidden: Joi.boolean(),
  payoutData: Joi.object({
    email: Joi.string().email(),
  }),
}),

I would like to input the string 'settings.isHidden' or 'settings.payoutData.email' without hard coding each of these strings in the schema. Is there a way that I can make joi know that these strings are valid based on the object schema I already have? Currently, when I try to validate these strings I get a validation error that says those keys are not allowed.

Example object to validate:

{ 'settings.isHidden': false }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your Joi schema:

settings: Joi.object({
  isHidden: Joi.boolean(),
  payoutData: Joi.object({
    email: Joi.string().email(),
  }),
}),

says that settings (presumably a property of an object) is an object that has two properties:

  • isHidden, a boolean, and
  • payoutData, an object with the property email, a string

Your example object

{ 'settings.isHidden': false }

is an object with a single property settings.isHidden and it so fails validation.

Ergo, your object fails validation against the schema.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda