lukeautry / tsoa

Build OpenAPI-compliant REST APIs using TypeScript and Node
MIT License
3.54k stars 499 forks source link

Missing Support For Unicode Character Classes #1477

Open Car-ElWilliams opened 1 year ago

Car-ElWilliams commented 1 year ago

Sorting

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

WoH commented 1 year ago

My bad, I'll tag it to prevent the bot.