-
Notifications
You must be signed in to change notification settings - Fork 403
QueryParams does not include ParamOptions as like as the documentation says? #160
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
Comments
Yeah, looks like @pleerock forgot to add export function QueryParams(): Function So now we can't turn on/off validation or set class-transform options. |
Thats a documentation issue. QueryParams do not accept param options because QueryParams is dummy - it simply take |
@pleerock |
Type transformation wont work because we cant read data type of array, so classtransformation and validation wont work until explicit given type. Usually all params in query params are different which means array of different object types. How are we going to specify them to |
Hello @pleerock , I think it will be nice if we add this feature as @19majkel94 says, it will be nice if we have the ability to enable the validations for query params, example: if i'm sending an email format inside a query string and want to validate it..etc |
Wait... what? What array? 😨 @Get("/test/:paramOne/:paramTwo")
public async test(@Req() req: any) {
const query = req.query;
const params = req.params;
return {
query,
params,
}
}
{
"query": {
"express": "better",
"koa": "poor"
},
"params": {
"paramOne": "pleerock",
"paramTwo": "19majkel94"
}
} Both route params and query params are an OBJECT, not an ARRAY. So you can declare a class, decorate it with class-validator decorator and class-transformer will transform plain object to class instance and allow to validate. |
ah right I forgot that its an object 😆 . But what class do you want to define - special for the whole query object?, e.g. |
Yes, like I already have for body validation. Until #122 it's the only solution for auto validating route params. |
Will this be reopened? It would be really useful if |
Actually describe.only("should validate @QueryParams input", () => {
class UserQuery {
@MinLength(5)
author: string;
@MinLength(5)
contributor: string;
hello() {
return "Hello world!";
}
}
let requestQuery: UserQuery;
beforeEach(() => {
requestQuery = undefined;
});
before(() => {
getMetadataArgsStorage().reset();
@JsonController()
class UserController {
@Get("/github")
getUsers(@QueryParams() query: UserQuery): any {
requestQuery = query;
return query.hello();
}
}
});
const options: RoutingControllersOptions = {
validation: true
};
let expressApp: any, koaApp: any;
before(done => expressApp = createExpressServer(options).listen(3001, done));
after(done => expressApp.close(done));
before(done => koaApp = createKoaServer(options).listen(3002, done));
after(done => koaApp.close(done));
assertRequest([3001], "get", "github?author=Umed&contributor=19majkel94&somethingPrivate=blablabla", response => {
console.log(response.body.errors);
expect(response).to.have.status(400);
expect(response.body.errors).to.have.lengthOf(1);
expect(response.body.errors[0].value).to.eql("Umed");
});
}); But correct errors are returned in response only in express - in koa I get this in
I will try to fix it and implement the |
Waiting for this feature :) |
Closing this via #289. Will be released in 0.8.0-beta.1 - |
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. |
I can not find ParamOptions while using the newly added feature QueryParams?
The text was updated successfully, but these errors were encountered: