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

Body validation is not working #425

Closed
ghost opened this issue Jul 30, 2018 · 2 comments
Closed

Body validation is not working #425

ghost opened this issue Jul 30, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Jul 30, 2018

The Body decoration does not seem to be working

Example code:

import "reflect-metadata";
import {
  JsonController,
  Body,
  Post,
  createExpressServer
} from "routing-controllers";
import { IsEmail, MinLength } from "class-validator";

class NewUserDto {
  @IsEmail() email: string;
  @MinLength(8)
  password: string;
}

@JsonController("/user")
class UserController {
  @Post("/")
  createUser(@Body() user: NewUserDto) {
    return user;
  }
}

const app = createExpressServer({ controllers: [UserController] });
app.listen(8080, () => console.log("listening on port 8080"));

If I send a POST request to localhost:8080/user with the following JSON data

{
  "email": "asdf",
  "password": "asdf"
}

The server respondes with

{
    "email": "asdf",
    "password": "asdf"
}

instead of the expect 400 response I would expect since the email and password fields are invalid

My dependencies are:

"body-parser": "^1.18.3",
"class-validator": "^0.9.1",
"express": "^4.16.3",
"reflect-metadata": "^0.1.12",
"routing-controllers": "^0.7.7",
"ts-node": "^7.0.0",
"typescript": "^2.9.2"
@ghost
Copy link
Author

ghost commented Aug 1, 2018

This is a clone of #384

@ghost ghost closed this as completed Aug 1, 2018
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 14, 2020
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

0 participants