Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@pattern not enforced with Record #1644

Open
2 of 4 tasks
JasonGore opened this issue Jun 21, 2024 · 1 comment
Open
2 of 4 tasks

@pattern not enforced with Record #1644

JasonGore opened this issue Jun 21, 2024 · 1 comment

Comments

@JasonGore
Copy link

JasonGore commented Jun 21, 2024

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • 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?

Copy link

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.👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants