lukeautry / tsoa

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

Feature request: support reusing types with new restriction in the validator #1457

Closed Ivan-Shesterkin closed 1 year ago

Ivan-Shesterkin commented 1 year ago

Sorting

Expected Behavior

I trying to reuse and modify some types in the validator. I define type ILatinString with pattern and I trying to reuse this type with new restrictions like maxLength.

/**
 * String that contains only Latin letters
 * @pattern ^[a-zA-Z]+$
 */
type ILatinString = string;

export interface IUser {
  /**
   * @minLength 2
   * @maxLength 15
   */
  nickname: ILatinString;
  /**
   * @minLength 2
   * @maxLength 10
   */
  clanName: ILatinString;
}

I expect, that after this configuration validator will check that nickName and clanName fields contains only Latin characters and the validator ensure that nickname length should be between 2 - 15 and clanName length should be between 2 - 10.

Current Behavior

Validator checks pattern, but ignores length decorators.

Steps to Reproduce

https://github.com/Ivan-Shesterkin/tsoa-issues

Context (Environment)

Version of the library: "tsoa": "5.1.1", Version of NodeJS: v18.15.0

Detailed Description

This is how autogenerated model looks like for this config

const models: TsoaRoute.Models = {
    "ILatinString": {
        "dataType": "refAlias",
        "type": {"dataType":"string","validators":{"pattern":{"value":"^[a-zA-Z]+$"}}},
    },
    // WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
    "IUser": {
        "dataType": "refObject",
        "properties": {
            "nickname": {"ref":"ILatinString","required":true,"validators":{"minLength":{"value":2},"maxLength":{"value":15}}},
            "clanName": {"ref":"ILatinString","required":true,"validators":{"minLength":{"value":2},"maxLength":{"value":10}}},
        },
        "additionalProperties": false,
    }
};

Breaking change?

github-actions[bot] commented 1 year ago

Hello there Ivan-Shesterkin 👋

Thank you for opening your very first issue in this project.

We will try to get back to you as soon as we can.👀

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days