Tsoa validation doesn't work with long pattern values and validation messages
See original GitHub issueSorting
-
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:
- Created 2 years ago
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
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.