tsoa icon indicating copy to clipboard operation
tsoa copied to clipboard

@pattern not enforced with Record

Open JasonGore opened this issue 8 months ago • 1 comments

Sorting

  • I'm submitting a ...

    • [x] bug report
    • [ ] feature request
    • [ ] support request
  • I confirm that I

    • [x] used the search to make sure that a similar issue hasn't already been submit

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';

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

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;
  }
}
  1. Send REST Client request and confirm validation error is as expected
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

Possibly related to #1515, #1531 and #1612

Breaking change?

JasonGore avatar Jun 21 '24 16:06 JasonGore