@nest-openapi/validator 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 nest-openapi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,111 +1,194 @@
1
- <p align="center">
2
- <img src="./docs/public/nest-openapi-logo.png" alt="nest-openapi-logo" height="84" />
3
- </p>
4
-
5
- <h1 align="center">@nest-openapi</h1>
6
-
7
- <p align="center"><strong>OpenAPI‑first utilities for NestJS</strong></p>
8
-
9
- <p align="center">
10
- Single source of truth · Drop‑in for NestJS · Fast by design
11
- </p>
12
-
13
- ![GitHub License](https://img.shields.io/github/license/ts-oas/nest-openapi)
14
-
15
- ## Overview
16
-
17
- `@nest-openapi` is a modern, modular set of utilities for building OpenAPI‑driven NestJS apps.
18
-
19
- - **Single Source of Truth** — The OpenAPI spec is the contract; validation and serialization derive from it.
20
- - **Drop‑in for NestJS** — Works with existing controllers and routes.
21
- - **Fast by Design** — AJV validation and fast-json-stringify serialization with caching and precompilation.
22
- - **Express & Fastify** — Platform‑agnostic support.
23
- - **Fine‑Grained Control** — Per‑route opt‑out and overrides.
24
-
25
- ### Packages
26
-
27
- - [**`@nest-openapi/validator`**](https://nest-openapi.github.io/validator/)Automatic request/response validation using your OpenAPI specification.
28
-
29
- - [**`@nest-openapi/serializer`**](https://nest-openapi.github.io/serializer/) — High‑performance response serialization based on your OpenAPI 3.x specification.
30
-
31
- ---
32
-
33
- ## Get Started
34
-
35
- ### @nest-openapi/validator
36
-
37
- [![NPM – validator](https://img.shields.io/npm/v/%40nest-openapi%2Fvalidator.svg)](https://www.npmjs.com/package/%40nest-openapi%2Fvalidator)
38
- ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40nest-openapi%2Fvalidator.svg)
39
-
40
- Install:
41
-
42
- ```bash
43
- npm i @nest-openapi/validator
44
- ```
45
-
46
- Minimal setup:
47
-
48
- ```typescript
49
- // app.module.ts
50
- import { Module } from "@nestjs/common";
51
- import { OpenAPIValidatorModule } from "@nest-openapi/validator";
52
- import * as openApiSpec from "./openapi.json";
53
-
54
- @Module({
55
- imports: [
56
- OpenAPIValidatorModule.forRoot({
57
- specSource: { type: "object", spec: openApiSpec },
58
- }),
59
- ],
60
- })
61
- export class AppModule {}
62
- ```
63
-
64
- All routes are automatically validated. **For advanced configuration, see [the docs](https://nest-openapi.github.io/validator/)**.
65
-
66
- ### @nest-openapi/serializer
67
-
68
- [![NPM – serializer](https://img.shields.io/npm/v/%40nest-openapi%2Fserializer.svg)](https://www.npmjs.com/package/%40nest-openapi%2Fserializer)
69
- ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/%40nest-openapi%2Fserializer.svg)
70
-
71
- Install:
72
-
73
- ```bash
74
- npm i @nest-openapi/serializer
75
- ```
76
-
77
- Minimal setup:
78
-
79
- ```typescript
80
- // app.module.ts
81
- import { Module } from "@nestjs/common";
82
- import { OpenAPISerializerModule } from "@nest-openapi/serializer";
83
- import * as openApiSpec from "./openapi.json";
84
-
85
- @Module({
86
- imports: [
87
- OpenAPISerializerModule.forRoot({
88
- specSource: { type: "object", spec: openApiSpec },
89
- responseSerialization: { enable: true, skipErrorResponses: true },
90
- }),
91
- ],
92
- })
93
- export class AppModule {}
94
- ```
95
-
96
- Successful responses are automatically serialized. **For advanced configuration, see [the docs](https://nest-openapi.github.io/serializer/)**.
97
-
98
- ---
99
-
100
- ## Compatibility
101
-
102
- - Works with NestJS v9+
103
- - Supports Express and Fastify adopters
104
-
105
- ## Contributing
106
-
107
- Issues and PRs are welcome. Please check the package folders and docs before opening an issue.
108
-
109
- ## License
110
-
111
- MIT © `@nest-openapi`
1
+ <p align="center">
2
+ <img src="./docs/public/nest-openapi-logo.png" alt="nest-openapi-logo" height="84" />
3
+ </p>
4
+
5
+ <h1 align="center">@nest-openapi</h1>
6
+
7
+ <p align="center"><strong>OpenAPI‑first utilities for NestJS</strong></p>
8
+
9
+ <p align="center">
10
+ Single source of truth · Drop‑in for NestJS · Fast by design
11
+ </p>
12
+
13
+ <p align="center">
14
+ <a href="https://deepwiki.com/ts-oas/nest-openapi"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
15
+ <a href="https://github.com/ts-oas/nest-openapi/blob/main/LICENSE">
16
+ <img src="https://img.shields.io/github/license/ts-oas/nest-openapi" alt="License" />
17
+ </a>
18
+ </p>
19
+
20
+ ---
21
+
22
+ ## Features
23
+
24
+ - **🎯 Single Source of Truth** — Your OpenAPI spec drives validation, serialization, mocking, and MCP tools.
25
+ - **⚡ Fast by Design** — AJV validation and `fast-json-stringify` serialization with caching and precompilation.
26
+ - **🔌 Drop-in Integration** — Works with existing NestJS controllers and routes
27
+ - **🎛️ Fine-Grained Control** Per-route opt-out and custom schema overrides
28
+ - **🚀 Platform Agnostic** — Supports both Express and Fastify adapters
29
+
30
+ ## Packages
31
+
32
+ | Package | Description | Version |
33
+ | ------------------------------------------------------------------------ | ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------- |
34
+ | [`@nest-openapi/validator`](https://nest-openapi.github.io/validator/) | Automatic request/response validation using your OpenAPI spec | [![npm](https://img.shields.io/npm/v/@nest-openapi/validator.svg)](https://www.npmjs.com/package/@nest-openapi/validator) |
35
+ | [`@nest-openapi/serializer`](https://nest-openapi.github.io/serializer/) | High-performance response serialization based on your OpenAPI spec | [![npm](https://img.shields.io/npm/v/@nest-openapi/serializer.svg)](https://www.npmjs.com/package/@nest-openapi/serializer) |
36
+ | [`@nest-openapi/mock`](https://nest-openapi.github.io/mock/) | Spec-driven mock server for generating realistic mock responses | [![npm](https://img.shields.io/npm/v/@nest-openapi/mock.svg)](https://www.npmjs.com/package/@nest-openapi/mock) |
37
+ | [`@nest-openapi/mcp`](https://nest-openapi.github.io/mcp/) | Spec-driven MCP server for exposing OpenAPI operations as tools | [![npm](https://img.shields.io/npm/v/@nest-openapi/mcp.svg)](https://www.npmjs.com/package/@nest-openapi/mcp) |
38
+
39
+ ## Quick Start
40
+
41
+ ### Validator
42
+
43
+ ```bash
44
+ npm i @nest-openapi/validator
45
+ ```
46
+
47
+ ```typescript
48
+ import { Module } from "@nestjs/common";
49
+ import { OpenAPIValidatorModule } from "@nest-openapi/validator";
50
+ import * as openApiSpec from "./openapi.json";
51
+
52
+ @Module({
53
+ imports: [
54
+ OpenAPIValidatorModule.forRoot({
55
+ specSource: { type: "object", spec: openApiSpec },
56
+ }),
57
+ ],
58
+ })
59
+ export class AppModule {}
60
+ ```
61
+
62
+ **All routes are automatically validated.** See [full documentation](https://nest-openapi.github.io/validator/) for advanced configuration.
63
+
64
+ ### Serializer
65
+
66
+ ```bash
67
+ npm i @nest-openapi/serializer
68
+ ```
69
+
70
+ ```typescript
71
+ import { Module } from "@nestjs/common";
72
+ import { OpenAPISerializerModule } from "@nest-openapi/serializer";
73
+ import * as openApiSpec from "./openapi.json";
74
+
75
+ @Module({
76
+ imports: [
77
+ OpenAPISerializerModule.forRoot({
78
+ specSource: { type: "object", spec: openApiSpec },
79
+ responseSerialization: { enable: true, skipErrorResponses: true },
80
+ }),
81
+ ],
82
+ })
83
+ export class AppModule {}
84
+ ```
85
+
86
+ **Responses are automatically serialized.** See [full documentation](https://nest-openapi.github.io/serializer/) for advanced configuration.
87
+
88
+ ### Mock
89
+
90
+ ```bash
91
+ npm i @nest-openapi/mock
92
+ ```
93
+
94
+ ```typescript
95
+ import { Module } from "@nestjs/common";
96
+ import { OpenAPIMockModule } from "@nest-openapi/mock";
97
+ import * as openApiSpec from "./openapi.json";
98
+
99
+ @Module({
100
+ imports: [
101
+ OpenAPIMockModule.forRoot({
102
+ specSource: { type: "object", spec: openApiSpec },
103
+ enable: process.env.NODE_ENV === "development",
104
+ mockByDefault: true,
105
+ }),
106
+ ],
107
+ })
108
+ export class AppModule {}
109
+ ```
110
+
111
+ **Routes return mocked responses when enabled.** See [full documentation](https://nest-openapi.github.io/mock/) for advanced configuration.
112
+
113
+ ### MCP
114
+
115
+ ```bash
116
+ npm i @nest-openapi/mcp
117
+ ```
118
+
119
+ ```typescript
120
+ import { Module } from "@nestjs/common";
121
+ import { OpenAPIMcpModule } from "@nest-openapi/mcp";
122
+ import * as openApiSpec from "./openapi.json";
123
+
124
+ @Module({
125
+ imports: [
126
+ OpenAPIMcpModule.forRoot({
127
+ specSource: { type: "object", spec: openApiSpec },
128
+ http: { path: "/mcp" },
129
+ executor: { baseUrl: "http://127.0.0.1:3000" },
130
+ }),
131
+ ],
132
+ })
133
+ export class AppModule {}
134
+ ```
135
+
136
+ **Expose OpenAPI operations as MCP tools.** See [full documentation](https://nest-openapi.github.io/mcp/) for advanced configuration.
137
+
138
+ ## Usage Examples
139
+
140
+ ### Manual Validation
141
+
142
+ ```typescript
143
+ import { Inject, Injectable } from "@nestjs/common";
144
+ import {
145
+ OPENAPI_VALIDATOR,
146
+ OpenAPIValidatorService,
147
+ } from "@nest-openapi/validator";
148
+
149
+ @Injectable()
150
+ export class MyService {
151
+ constructor(
152
+ @Inject(OPENAPI_VALIDATOR)
153
+ private readonly validator: OpenAPIValidatorService,
154
+ ) {}
155
+
156
+ validate(ctx: HttpArgumentsHost) {
157
+ const errors = this.validator.validateRequest(ctx, { body: true });
158
+ if (errors.length > 0) {
159
+ // Handle validation errors
160
+ }
161
+ }
162
+ }
163
+ ```
164
+
165
+ ### Per-Route Overrides
166
+
167
+ ```typescript
168
+ import { Controller, Post } from "@nestjs/common";
169
+ import { Validate } from "@nest-openapi/validator";
170
+ import { Serialize } from "@nest-openapi/serializer";
171
+
172
+ @Controller("books")
173
+ export class BooksController {
174
+ @Post()
175
+ @Validate({ request: { query: false }, response: true })
176
+ @Serialize({ disable: true })
177
+ create(@Body() dto: CreateBookDto): Book {
178
+ return this.booksService.create(dto);
179
+ }
180
+ }
181
+ ```
182
+
183
+ ## Compatibility
184
+
185
+ - Works with NestJS v9+
186
+ - Supports Express and Fastify adapters
187
+
188
+ ## Contributing
189
+
190
+ Issues and PRs are welcome. Please check the package folders and docs before opening an issue.
191
+
192
+ ## License
193
+
194
+ MIT © [@nest-openapi](https://github.com/ts-oas/nest-openapi)
package/dist/index.cjs CHANGED
@@ -301,7 +301,7 @@ ${JSON.stringify(data, null, 2)}`);
301
301
  });
302
302
  continue;
303
303
  }
304
- if (value !== void 0 && param.schema) {
304
+ if (param.schema) {
305
305
  const schema = this.runtime.schemaResolver.resolveSchema(param.schema);
306
306
  if (schema) {
307
307
  const paramValue = { value };
package/dist/index.js CHANGED
@@ -265,7 +265,7 @@ ${JSON.stringify(data, null, 2)}`);
265
265
  });
266
266
  continue;
267
267
  }
268
- if (value !== void 0 && param.schema) {
268
+ if (param.schema) {
269
269
  const schema = this.runtime.schemaResolver.resolveSchema(param.schema);
270
270
  if (schema) {
271
271
  const paramValue = { value };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nest-openapi/validator",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Automatic request/response validation for NestJS using your OpenAPI specifications",
5
5
  "sideEffects": false,
6
6
  "keywords": [
@@ -13,6 +13,19 @@
13
13
  "typescript",
14
14
  "schema"
15
15
  ],
16
+ "homepage": "https://nest-openapi.github.io/",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/ts-oas/nest-openapi.git"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "author": "Alireza Malek",
25
+ "license": "MIT",
26
+ "bugs": {
27
+ "url": "https://github.com/ts-oas/nest-openapi/issues"
28
+ },
16
29
  "type": "module",
17
30
  "main": "./dist/index.cjs",
18
31
  "types": "./dist/index.d.ts",
@@ -27,29 +40,6 @@
27
40
  "README.md",
28
41
  "LICENSE"
29
42
  ],
30
- "scripts": {
31
- "build": "tsup src/index.ts --format esm,cjs --dts --target node20 --outDir dist --clean --external rxjs --external ajv --external @nestjs/common --external @nestjs/core",
32
- "test": "jest",
33
- "test:watch": "jest --watch",
34
- "test:cov": "jest --coverage",
35
- "prepack": "node -e \"const fs=require('fs');const path=require('path');fs.copyFileSync(path.resolve(__dirname,'..','..','README.md'), path.resolve(__dirname,'README.md'));\"",
36
- "postpack": "node -e \"const fs=require('fs');const path=require('path');try{fs.unlinkSync(path.resolve(__dirname,'README.md'))}catch(_){}\"",
37
- "lint": "eslint .",
38
- "lint:fix": "eslint . --fix"
39
- },
40
- "homepage": "https://nest-openapi.github.io/",
41
- "repository": {
42
- "type": "git",
43
- "url": "https://github.com/ts-oas/nest-openapi.git"
44
- },
45
- "publishConfig": {
46
- "access": "public"
47
- },
48
- "author": "Alireza Malek",
49
- "license": "MIT",
50
- "bugs": {
51
- "url": "https://github.com/ts-oas/nest-openapi/issues"
52
- },
53
43
  "peerDependencies": {
54
44
  "@nestjs/common": "^9.0.0 || ^10.0.0 || ^11.0.0",
55
45
  "@nestjs/core": "^9.0.0 || ^10.0.0 || ^11.0.0",
@@ -62,12 +52,11 @@
62
52
  }
63
53
  },
64
54
  "dependencies": {
65
- "@nest-openapi/runtime": "^0.1.1",
55
+ "@nest-openapi/runtime": "^0.1.2",
66
56
  "ajv": "^8.0.0",
67
57
  "rxjs": "^7.2.0"
68
58
  },
69
59
  "devDependencies": {
70
- "@nest-openapi/runtime": "workspace:^",
71
60
  "@nestjs/common": "^11.0.0",
72
61
  "@nestjs/core": "^11.0.0",
73
62
  "@nestjs/platform-express": "^11.1.3",
@@ -82,7 +71,8 @@
82
71
  "supertest": "^7.1.0",
83
72
  "ts-jest": "^29.0.0",
84
73
  "tsup": "^8.5.0",
85
- "typescript": "^5.9.0"
74
+ "typescript": "^5.9.0",
75
+ "@nest-openapi/runtime": "^0.1.2"
86
76
  },
87
77
  "jest": {
88
78
  "moduleFileExtensions": [
@@ -101,5 +91,13 @@
101
91
  ],
102
92
  "coverageDirectory": "coverage",
103
93
  "testEnvironment": "node"
94
+ },
95
+ "scripts": {
96
+ "build": "tsup src/index.ts --format esm,cjs --dts --target node20 --outDir dist --clean --external rxjs --external ajv --external @nestjs/common --external @nestjs/core",
97
+ "test": "jest",
98
+ "test:watch": "jest --watch",
99
+ "test:cov": "jest --coverage",
100
+ "lint": "eslint .",
101
+ "lint:fix": "eslint . --fix"
104
102
  }
105
- }
103
+ }