Skip to content

Validation message for union type is incorrect #1755

Open
@gaetan-shopopop

Description

@gaetan-shopopop

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

When validating a field with an union string like :

import { Body, Controller, Path, Post, Response, Route } from 'tsoa';

type CountryISO =
    | "ES"
    | "FR"
    | "BE"

class UserAddress {
    address: string;

    city: string;

    country: CountryISO;
}

@Route('users')
export class UserController extends Controller {

    @Post('/{userId}/address')
    public async setUserAddress(
        @Body() body: UserAddress,
        @Path() userId: number,
    ): Promise<void> {
      // 
    }

If I call the endpoint with an incorrect value for the field country, I want to receive this message :

Could not match the union against any of the items. Issues: [{\"body.country\":{\"message\":\"should be one of the following; ['ES', 'FR', 'BE']\",\"value\": 'PT'}}]

Current Behavior

The validation message received is :

Could not match the union against any of the items. Issues: [{\"body.country\":{\"message\":\"should be one of the following; ['ES']\",\"value\":'PT'}},{\"body.country\":{\"message\":\"should be one of the following; ['FR']\",\"value\":'PT'}},{\"body.country\":{\"message\":\"should be one of the following; ['BE']\",\"value\":'PT'}}]

Context (Environment)

Version of the library: 6.6.0
Version of NodeJS: 22.14.0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions