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

330
Visualizações
Joi not accepting correct string value with valid ()

I have a form with a dropdown input, so the options for that input are already set.

The problem is that the value of the input, despite being correct and it is within the accepted values of the schema I got the message that Provider must be one of [[object Set], [object Set]].

Most weird thing is that this problem is ocurring in production, but in localhost I don't get this validation error.

provider key from the schema:

 provider: Joi.string().required().label('Provider').when('entitlementType', {
    is: 'Offer', 
    then: Joi.string().valid(...providersForSubscriptions),
    otherwise: Joi.string().valid(...providersForProducts),
  }),

providersForSubscriptions array:

[
    "RBL",
]

providersForProducts array:

[
    "RBL",
    "content-store",
    "zencore",
    "VIP"
]

As you can see is a quite simple validation, it will receive some provider value and will accept the value if it's within the valid arrays.

Loging the form in the browser.

console.log(entitlementType, provider, providersForProducts);

And this is the output:

enter image description here

So what's going on? If we check the context from the validation warning, the input value is zencore and zencore is considered as a valid value.

Any thoughts? Should I try refactoring the schema? Why this is prod only?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

From your schema:

provider: Joi.string().required().label('Provider').when('entitlementType', {
    is: 'Offer', 
    then: Joi.string().valid(...providersForSubscriptions),
    otherwise: Joi.string().valid(...providersForProducts),
  }),

And your output, we can see that entitlementType is NOT offer. So that means

Joi.string().valid(...providersForProducts),

is being used for validation on this particular field.

We can also see the error Provider must be one of [[object Set], [object Set]] which means that Joi is checking against an array of sets.

That points us to providersForProducts as the culprit.

Why is it an array of sets? Who knows. Log that value to confirm and then work your way back to see why it's set as such.

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