lukeautry / tsoa

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

Using `Omit` on a type, tsoa ignores regex pattern validation on field in that type #1543

Closed netofri closed 7 months ago

netofri commented 7 months ago

Using Omit on a type that includes a field that is a string with a regex pattern, tsoa ignores the regex pattern validation, and validates only that the value is a string.

Sorting

Steps to Reproduce

Given a regex pattern type, e.g. UUID type from the tsoa docs:

/**
 * Stringified UUIDv4.
 * See [RFC 4112](https://tools.ietf.org/html/rfc4122)
 * @pattern [0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}
 * @format uuid
 */
type UUID = string;

And types:

type User = {
  id: UUID;
  omittedField: number;
}

type CreateUser = Omit<User, 'omittedField'>;

Expected Behavior

Using CreateUser as the type of a request body, tsoa should validate that the id field string value matches the regex pattern.

Current Behavior

Using CreateUser on the request body of a request, tsoa only validates that the id field is a string, but does NOT validates the regex pattern.

Context (Environment)

Version of the library: 6.0.1 Version of NodeJS: 16.17.0

WoH commented 7 months ago

Dup #1531