Sorry if I've got the wrong end of the stick, but it sounds like you just need a Custom Decorator that will skip over the Global Validation Pipe and instead use a Zod Validation Pipe where indicated?
By default the Global Validation Pipe won't run on a Custom Decorator (unless you set validateCustomDecorators: true, but I don't think that's applicable here since you want to validate with Zod directly), instead it only runs on the basic ones (@Body() for example). (see https://docs.nestjs.com/custom-decorators)
So you can just make a Custom Decorator and use it on your Controller with a Zod Validation Pipe like so:
Main.ts:
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(new ValidationPipe({whitelist: true, forbidNonWhitelisted: true}))
await app.listen(process.env.PORT ?? 3000);
}
bootstrap();```
app.controller.ts:
```ts
import { Body, Controller, Post } from '@nestjs/common';
import { AppService } from './app.service';
import { CreateAppDto } from './dtos/app-test.dto';
import { ZodValidationPipe } from './pipes/zod-validation.pipe';
import { CreateAppTestZodDto, CreateAppTestZodDtoType } from './dtos/app-test-zod.dto';
import { ZodValidation } from './decorators/zod-validation.decorator';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Post()
createApp(@Body() createDto: CreateAppDto) {
return this.appService.createTest(createDto)
}
@Post('zod')
createAppWithZod(@ZodValidation(new ZodValidationPipe(CreateAppTestZodDto)) createDto: CreateAppTestZodDtoType
) {
return this.appService.createTest(createDto)
}
}```