Skip to content

Using class-validator with @QueryParams #323

Closed
@mlarsson

Description

@mlarsson

I have the following and are using v. 0.7.6 of routing-controllers:

export class TestObject {

  @IsNumber()
  @IsPositive()
  someNumber: number;

  @IsString()
  @IsNotEmpty()
  someString: string;

}

@Controller('/v1/test')
export class PaymentController {

  @Get()
  getTest( @QueryParams() test: TestObject) {
    console.log(test);
    return 'ok';
  }
}

I would expect that a url like "v1/test?someNumber=notanumber" would cause the user to get a bad request 400 response (as "notanumber" is not a positive number and as "someString" is missing) or at least cause some kind of error somewhere. But nothing happens. The request goes through, the object will be printed and 200 is returned.

Am I missing something here?

Kind regards Morten

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions