Skip to content

Overview ​

npmNPM DownloadsLicenseAsk DeepWiki

@nest-openapi/validator Automatically validates request/response using your OpenAPI 3.x spec.

  • Spec‑driven — The OpenAPI spec is the contract; validation is generated from it.
  • Fast by Design — AJV under the hood, with schema caching and optional pre-compilation.
  • Full Coverage — Validates request body, route params, query strings, and responses.
  • NestJS‑native & Platform Agnostic — Auto validates with per‑route opt‑out and overrides (@Validate()) and fully compatible with both Express and Fastify adapters.

Install ​

bash
npm i @nest-openapi/validator

Quick Start ​

typescript
// app.module.ts
import { OpenAPIValidatorModule } from "@nest-openapi/validator";
import * as openApiSpec from "./openapi.json";

@Module({
  imports: [
    OpenAPIValidatorModule.forRoot({
      specSource: { type: "object", spec: openApiSpec },
    }),
  ],
})
export class AppModule {}

That's it! All routes automatically validated.

Next Steps ​

Released under the MIT License.