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.

Tsoa validation doesn't work with long pattern values and validation messages

See original GitHub issue

Sorting

  • I’m submitting a …

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn’t already been submit

Expected Behavior

Export type with long pattern added. Since the pattern string has a length bigger than 100 symbols (eslint max 100), pattern part moved to next line. Reject message moved to next line and starts from whitespace.

  • Validation mechanism should use pattern from different rows and search for the regexp match.
  • email@company.com value should pass validation
  • incorrectemail value should be rejected with message: Invalid email. Value is expected to match the pattern [a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]+@a-zA-Z0-9?(?:.a-zA-Z0-9?)
/**
 * Stringified email.
 * See [RFC 1123](https://html.spec.whatwg.org/multipage/input.html#valid-e-mail-address).
 *
 * @pattern [a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?
 * (?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*
 *  Invalid email. Value is expected to match the pattern 
 * [a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9]
 * (?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9]
 * (?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*
 * 
 * @format email
 */
export type Email = string;

Current Behavior

  • email@company.com can’t pass validation, probably, because validation mechanism includes newline symbol into regexp expression.
  • An error message omits first message word: email. Value is expected to match the pattern \n[a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]+@[a-zA-Z0-9]\n(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9]\n(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)
  • Multiline reject messages renders new line \n symbols.

Possible Solution

Steps to Reproduce

Use provided type

Context (Environment)

Version of the library: ^4.0.0-alpha.2 Version of NodeJS:

  • Confirm you were using yarn not npm: [x ]

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
ggbrunocommented, May 27, 2022

I made an implementation of the idea. It removes the newlines and allow the error message with double newlines.

https://github.com/ggbruno/tsoa/commit/2907652adf790c76ef9e365538c2ebb3a1a606d8

0reactions
igarioshkacommented, May 27, 2022

That’s a great idea! We can postprocess the error message in the function that handles validation errors, removing all unnecessary newlines. Now, only the pattern length would be difficult, as there would need to be a change in validatorUtils.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Handling | tsoa - GitHub Pages
Handling Validation Errors​​ Let's first make sure that, whenever the Client triggers a Validation Error, instead of printing the stack trace, instead we...
Read more >
TypeScript is a waste of time. Change my mind.
With regard to more complicated issues (e.g. race conditions, memory leaks, etc.), TypeScript is completely useless.
Read more >
@rlvt/tsoa - npm
Runtime validation of tsoa should behave as closely as possible to the specifications that the generated Swagger/OpenAPI schema describes. Any ...
Read more >
Allow string to be null or empty in joi and express-validation
You could also specify this with a comma delimited list. dataId: Joi.string().allow(null, ''). See Joi documentation on allow(value).
Read more >
OpenAPI.Tools
Contribute APIs You Won't Hate ... openapi-data-validator - Validate API requests against an OpenAPI schema. Lightweight, focused, and integrates with any ...
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