Comments (9)
sorry, I setup the project incorrectly, my problem was solved
from routing-controllers.
I cannot reproduce this with your example. Here is the snippet I'm running:
import 'reflect-metadata';
import {Expose, plainToClass} from "class-transformer";
import {IsEmail} from "class-validator";
import {Body, createExpressServer, JsonController, Post, Res} from "routing-controllers";
import {Response} from 'express';
export class GenerateIdentificationByEmailCommand {
@Expose()
@IsEmail()
email!: string;
static setProperties(cmd: GenerateIdentificationByEmailCommand): GenerateIdentificationByEmailCommand {
return plainToClass(GenerateIdentificationByEmailCommand, cmd, {excludeExtraneousValues: true});
}
}
@JsonController('')
export class TestController {
@Post('/email')
async generateIdentificationByEmail(
@Res() res: Response,
@Body({validate: true}) cmd: GenerateIdentificationByEmailCommand
) {
const body = GenerateIdentificationByEmailCommand.setProperties(cmd);
return res.status(201).send('test');
}
}
const server = createExpressServer({
defaultErrorHandler: true,
defaults: {
nullResultCode: 400,
undefinedResultCode: 204,
paramOptions: {
required: true,
},
},
classTransformer: true,
validation: true,
routePrefix: "/oks",
controllers: [
TestController
],
});
server.listen(8080, () => console.log('started'));
Running POST request to /oks/email
with body
{
"email2": "[email protected]"
}
Getting back an error:
{
"errors": [
{
"target": {
"email2": "[email protected]"
},
"property": "email",
"children": [],
"constraints": {
"isEmail": "email must be an email"
}
}
]
}
Dependencies installed:
"dependencies": {
"@types/express": "^4.17.17",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"routing-controllers": "^0.10.4",
"ts-node": "^10.9.1",
"typedi": "^0.10.0",
"typescript": "^4.8.4"
}
Could you please include more details?
from routing-controllers.
I cannot get errors when passing an invalid request body. It seems like the validator not working
from routing-controllers.
@magiskboy could you include an example that is not working?
from routing-controllers.
Yep
This is to create application and express
and then I setup a controller called User
with a route /login
I use httpie to call to localhost:3000/api/users/login
from routing-controllers.
@magiskboy Do you have reflect-metadata imported?
from routing-controllers.
yep, I imported reflect-metadata on top
from routing-controllers.
@magiskboy how do you transpile ts? Using tsc or something else?
from routing-controllers.
I have the same problem, could you tell me where you configured the project wrong?
from routing-controllers.
Related Issues (20)
- fix: global middlewares (re)registered each time useExpressServer is called HOT 3
- question: @Param not type casted HOT 21
- question: building the code looks for Koa, while I'm only using Express HOT 8
- fix: <Injected Response object is undefined> HOT 1
- question: @Get path with literal and variable HOT 3
- feature: <how make sub folder controllers> how make sub folder controllers HOT 2
- fix: jsdoc for Put http method, it mentions POST http method
- fix: TypeDI do not inject service HOT 1
- Annotate return type of `createExpressServer` with more narrow type HOT 1
- `cors: true` causes "Cannot set headers after they are sent to the client" error HOT 3
- fix: Global middlewares are not used if route prefix doesn't start with a slash ("/")
- fix: TypeError this.targetType.toLowerCase is not a function HOT 3
- fix: import statements should not affect the route matching order
- Can we create multiple paths for the same controller function? HOT 7
- fix: CJS being imported instead of ESM when trying to load controllers from directory import HOT 4
- feature: Allow to use `app.use(createExpressRouter())` instead of `useExpressServer(app)` HOT 6
- question: Routes with path parameters continue middleware chain (but those without, don't)? HOT 5
- feature: Dynamic route HOT 5
- feature: Introduce Generics to CurrentUserChecker for Enhanced Type Safety HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from routing-controllers.