tsoa
tsoa copied to clipboard
Missing Support For Unicode Character Classes
Sorting
-
I'm submitting a ...
- [X] bug request
- [X] feature request
-
I confirm that I
- [] used the search to make sure that a similar issue hasn't already been submit
Previous issue 1442, was automatically closed without any auxiliary assistance, hence the repost.
Expected Behavior
I am implementing regex validation via the pattern keyword annotation for my api:
/**
* Allows for more generic naming, but disallows general punctuation, line breaks and non unicode letters/numbers
* @pattern ^[\p{N}\p{L}\h]{0,62}$ Generic name failed validation pattern
*/
type GenericName = string
The provided @pattern regex with it's provided unicode classes (e.g. \p{L}) should match generic names such as: Müller, Åman, Project 123 etc and throw an error if the request string is invalid.
Current Behavior
It seems that unicode classes are not supported by whatever regex engine TSOA runs on, since my api throws the @pattern's error message even though the request parameter string is clearly valid. However, If I exchange the regex pattern with a non unicode regex (^[a-zA-Z0-9-\h]*$ or anything similar) the validation works as intended.
Attempted Solutions
I have double checked that the regex is correct I have tried adding the /u (unicode) flag to my regex I have also tried removing the escaping backslash generated by TSOA in the swagger.json file, but to no avail.
Maintainer Note
If unicode regex is supported please provide a working example, if not then we would greatly desire such a feature since we use a lot of regex validation with unicode for our api.
Swagger File
The auto generated swagger.json file looks like this:
"schemas": {
"GenericName": {
"type": "string",
"description": "Allows for more generic naming, but disallows general punctuation and line breaks and non unicode letters/numbers",
"pattern": "^[\\p{N}\\p{L}\\h]{0,62}$"
}
}
Context (Environment)
Version of the library: 4.1.3 Version of NodeJS: 16.14.2 Package manager: npm
My bad, I'll tag it to prevent the bot.