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

Joi schema always returns same error message from local xontext #3060

Open
HunterJS-bit opened this issue Jan 13, 2025 · 0 comments
Open

Joi schema always returns same error message from local xontext #3060

HunterJS-bit opened this issue Jan 13, 2025 · 0 comments
Labels
bug Bug or defect

Comments

@HunterJS-bit
Copy link

Runtime

node

Runtime version

18

Module version

latest

Last module version without issue

No

Used with

standalone

Any other relevant information

No response

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

Hi, I have been using Joi library latest to validate some complex schemas. And I have noticed following issue.

I have a schema stored as a string in Redis. What I do I fetch it. Then build it and use to validate some objects.

My code looks like this

const Joi = require('joi');
const schema = require('my-schema');

const schemaCashe = {};

if (!schemaCashe['key']) {
    const joiSchema = Joi.build(schema);
    schemaCashe['key'] = joiSchema
} 

try {
  const res = await schemaCashe['key'].validateAsync(data);
  if (res.warning) {
      console.log('warning', res.warning);
  }
} catch (err) {
}

the problem that I'm having is after I validate input and If I use the local context to display the message. THe second time when I try to validate Data object. The same message is shown.

I use the custom messages like "any.only": {#value} does not match provided

And If I try to validate with the same object twice in a row, with data { "test": "Some text" } , and then with { "test": "Some text22" } I get twice the same message Some textdoes not match provided

What was the result you got?

And If I try to validate with the same object twice in a row, with data { "test": "Some text" } , and then with { "test": "Some text22" } I get twice the same message Some text does not match provided

This is not valid it should always show the updated value.

What result did you expect?

I expect the local value to be updated properly and to show the proper warning.

@HunterJS-bit HunterJS-bit added the bug Bug or defect label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

1 participant