question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Joi.ref is breaking

See original GitHub issue

Schema:

const schema = Joi.object()
  .label('SignUp')
  .keys({
    password: Joi.string()
      .required()
      .description('The password of the authenticating user')
      .example('test-PASSWORD123'),
    repeatPassword: Joi.string()
      .required()
      .allow(Joi.ref('password'))
      .description('Repeat the password to ensure no typos')
      .example('test-PASSWORD123')
  });

Result:

joi-to-typescript/dist/main/utils.js:26
    return `'${value.replace(/\\/g, '\\\\').replace(/'/g, "\\'")}'`;
                     ^

TypeError: value.replace is not a function
    at toStringLiteral (joi-to-typescript/dist/main/utils.js:26:22)
    at joi-to-typescript/dist/main/parse.js:341:92
    at Array.map (<anonymous>)
    at parseStringSchema (joi-to-typescript/dist/main/parse.js:339:42)
    at parseHelper (joi-to-typescript/dist/main/parse.js:189:20)
    at parseSchema (joi-to-typescript/dist/main/parse.js:265:26)
    at joi-to-typescript/dist/main/parse.js:423:30
    at joi-to-typescript/dist/main/utils.js:13:27
    at Array.reduce (<anonymous>)
    at filterMap (joi-to-typescript/dist/main/utils.js:12:17)

Shape returned at this line:

{ ref: { path: [ 'password' ] } }

Is it possible for me to just skip all processing on this field using a meta flag or something?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
toddtarsicommented, May 18, 2022

🤯 - Holy cow! You resolved that so fast. Thank you so much! Also, please don’t let any of the people on things I maintain know that you can fix things this fast 😆 😭

0reactions
mrjono1commented, May 19, 2022

fixed released under 4.0.3

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Joi.valid(Joi.ref('password')) breaks the endpoint form ...
Using Joi.string().valid(Joi.ref('password')); gives a drop-down with a single weird value that doesn't pass the validation on swagger's UI.
Read more >
How to validate sum of refs in Joi - Stack Overflow
ref . I can do the following and hang a custom off the entire validation schema, but would prefer to attach it to...
Read more >
Changelog - joi.dev
Joi valid fails, when ref is used with a stripped key. 10.2.2 · #1103. allow param defaults to be set by the param...
Read more >
How to use the joi.ref function in joi - Snyk
To help you get started, we've selected a few joi.ref examples, based on popular ways it is used in public projects.
Read more >
Chapter 6: Validations with Joi | Hapi With Typescript - Softcover
Some users may send in invalid input because of ignorance; othes might do it on purpose to break the application. Instead of assuming...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found