lukeautry / tsoa

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

@pattern not enforced with Record #1644

Open JasonGore opened 2 weeks ago

JasonGore commented 2 weeks ago

Sorting

Expected Behavior

/**
 * @pattern ^(?!-)[A-Za-z0-9-]+([\-\.]{1}[a-z0-9]+)*\.[A-Za-z]{2,6}$ Should be valid site domain.
 */
export type Domain = string;

export type DomainRecord = Record<Domain, string>;

interface RequestBody {
  record: DomainRecord;
  siteDomain: Domain;
}

Current Behavior

siteDomain has regex @pattern enforced. record does not.

Possible Solution

Steps to Reproduce

  1. Implement simple controller with above typing
    
    import { Body, Controller, Post, Route, SuccessResponse } from 'tsoa';

/**

type DomainRecord = Record<Domain, string>;

interface ReproBody { record: DomainRecord; siteDomain: Domain; }

@Route('/v0.1/repro') export class ReproController extends Controller { @Post('/') @SuccessResponse('200') public async readPage(@Body() requestBody: ReproBody) { return requestBody; } }

2. Send REST Client request and confirm validation error is as expected
```http
POST {{url}}/v0.1/repro
Content-Type: application/json

{
  "record": { "https://some.domain.com": "test string" },
  "siteDomain": "https://some.domain.com"
}
  1. Send REST Client request and see that validation error does not occur for record as expected
    
    POST {{url}}/v0.1/repro
    Content-Type: application/json

{ "record": { "https://some.domain.com": "test string" }, "siteDomain": "some.domain.com" }



## Context (Environment)

Version of the library: 6.2.1
Version of NodeJS: 20.13.0

- Confirm you were using yarn not npm: [x]

## Detailed Description

<!--- Provide a detailed description of the change or addition you are proposing -->
Possibly related to #1515, #1531 and #1612 

## Breaking change?

<!--- if this is a breaking change, then please describe how it breaks the existing libraries inputs/outputs -->
<!--- if this is a breaking change, then discuss how we can mitigate that -->
github-actions[bot] commented 2 weeks ago

Hello there JasonGore šŸ‘‹

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

We will try to get back to you as soon as we can.šŸ‘€