Overview
@nest-openapi/serializer High‑performance response serialization based on your OpenAPI 3.x spec.
- Spec‑driven — The OpenAPI spec is the contract; serializers are generated from it.
- Blazing Fast — Uses
fast-json-stringifywith schema caching and optional pre‑compilation. - Strips Secret Fields — Only fields declared in your OpenAPI response schema are serialized, preventing accidental data leaks.
- NestJS‑native & Platform Agnostic — Per‑route opt‑out and overrides (
@Serialize()) and fully compatible with both Express and Fastify adapters.
Install
bash
npm i @nest-openapi/serializerQuick Start
ts
// app.module.ts
import { Module } from "@nestjs/common";
import { OpenAPISerializerModule } from "@nest-openapi/serializer";
import * as openApiSpec from "./openapi.json";
@Module({
imports: [
OpenAPISerializerModule.forRoot({
specSource: { type: "object", spec: openApiSpec },
precompileSchemas: true,
responseSerialization: { enable: true, skipErrorResponses: true },
}),
],
})
export class AppModule {}That's it. Successful responses are automatically serialized according to the OpenAPI response schema and best‑match content-type.
Framework Support
Works with both Express and Fastify adapters.
Next Steps
- Options — Full configuration reference
- Decorators — Per-route serialization overrides
- Manual Serialization — Programmatic response serialization
