nestjsx / crud

NestJs CRUD for RESTful APIs
https://github.com/nestjsx/crud/wiki
MIT License
4.09k stars 539 forks source link

Global ValidationPipe & SerializeClassInterceptor don't apply on @Crud() controllers #604

Open noerw opened 4 years ago

noerw commented 4 years ago

See title; if i set these on my app (main.ts) like this, they have no effect on controllers annotated with @Crud()

app.useGlobalPipes(new ValidationPipe({ transform: true }))
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)))

This is very unintuitive, is this intended?

As a workaround I set CrudOptions.validation on each @Crud() controller, but this means duplication of config & is errorprone. Also; why is the validation property not available on the CrudGlobalConfig (CrudConfigService.load({ validation }))?

michaelyali commented 4 years ago

In every crud controller validation and serialization is on by default. setting up a global validator doe not effect because as one of the feature we use validation groups depending on a request type (post, patch/put) and thus can't use a nestjs global validation pipe. Serialization is on by default too.

So I have a question - why would you need to add those globally even if they are already being used internally by the lib?

noerw commented 4 years ago

I have other controllers that are not @Crud annotated (as they are about custom logic). I added those global pipes, as I wanted to have a common approach to validation & serialization, and was suprised that I didn't get that with @Crud. Your explanation with validation groups makes sense though, I'll look into it