@nest-openapi/validator 0.1.0 → 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/README.md +194 -326
- package/dist/index.cjs +41 -48
- package/dist/index.d.cts +9 -8
- package/dist/index.d.ts +9 -8
- package/dist/index.js +41 -48
- package/package.json +22 -22
package/README.md
CHANGED
|
@@ -1,326 +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
|
|
8
|
-
|
|
9
|
-
<p align="center">
|
|
10
|
-
Single source of truth · Drop
|
|
11
|
-
</p>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
@
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
import {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
import {
|
|
169
|
-
import {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
@
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
### Error Response Validation
|
|
200
|
-
|
|
201
|
-
By default, the response validation interceptor only validates successful responses that flow through the normal pipeline. However, error responses (like `NotFoundException`, `BadRequestException`, etc.) bypass interceptors and go through exception filters.
|
|
202
|
-
|
|
203
|
-
To validate error responses, inject the validator service in your exception filter:
|
|
204
|
-
|
|
205
|
-
```typescript
|
|
206
|
-
import {
|
|
207
|
-
Catch,
|
|
208
|
-
ExceptionFilter,
|
|
209
|
-
ArgumentsHost,
|
|
210
|
-
Injectable,
|
|
211
|
-
Inject,
|
|
212
|
-
} from "@nestjs/common";
|
|
213
|
-
import {
|
|
214
|
-
OPENAPI_VALIDATOR,
|
|
215
|
-
OpenApiValidatorService,
|
|
216
|
-
} from "@nest-openapi/validator";
|
|
217
|
-
|
|
218
|
-
@Catch()
|
|
219
|
-
@Injectable()
|
|
220
|
-
export class GlobalExceptionFilter implements ExceptionFilter {
|
|
221
|
-
constructor(
|
|
222
|
-
@Inject(OPENAPI_VALIDATOR)
|
|
223
|
-
private readonly validator: OpenApiValidatorService
|
|
224
|
-
) {}
|
|
225
|
-
|
|
226
|
-
catch(exception: any, host: ArgumentsHost) {
|
|
227
|
-
const ctx = host.switchToHttp();
|
|
228
|
-
const response = ctx.getResponse();
|
|
229
|
-
|
|
230
|
-
const status = exception.getStatus?.() || 500;
|
|
231
|
-
const responseBody = {
|
|
232
|
-
message: exception.message,
|
|
233
|
-
statusCode: status,
|
|
234
|
-
timestamp: new Date().toISOString(),
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
const validationErrors = this.validator.validateResponse(
|
|
238
|
-
ctx,
|
|
239
|
-
status,
|
|
240
|
-
responseBody
|
|
241
|
-
);
|
|
242
|
-
|
|
243
|
-
if (validationErrors.length > 0) {
|
|
244
|
-
console.warn("Error response validation failed:", validationErrors);
|
|
245
|
-
// Handle validation errors as needed
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
response.status(status).json(responseBody);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
```
|
|
252
|
-
|
|
253
|
-
Then register your exception filter:
|
|
254
|
-
|
|
255
|
-
```typescript
|
|
256
|
-
// app.module.ts
|
|
257
|
-
@Module({
|
|
258
|
-
providers: [
|
|
259
|
-
{
|
|
260
|
-
provide: APP_FILTER,
|
|
261
|
-
useClass: GlobalExceptionFilter,
|
|
262
|
-
},
|
|
263
|
-
],
|
|
264
|
-
})
|
|
265
|
-
export class AppModule {}
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
## Error Handling
|
|
269
|
-
|
|
270
|
-
### Handle Validation Errors
|
|
271
|
-
|
|
272
|
-
By default, the library throws:
|
|
273
|
-
|
|
274
|
-
- `BadRequestException` for request validation failures, with detailed validation errors.
|
|
275
|
-
- `InternalServerErrorException` for response validation failures (without detailed errors, unless you provide a custom handler).
|
|
276
|
-
|
|
277
|
-
Validation errors follow the AJV `ErrorObject` format, extended with a `validationType` property:
|
|
278
|
-
|
|
279
|
-
```json
|
|
280
|
-
{
|
|
281
|
-
"message": "Validation failed",
|
|
282
|
-
"errors": [
|
|
283
|
-
{
|
|
284
|
-
"validationType": "body",
|
|
285
|
-
"instancePath": "/title",
|
|
286
|
-
"schemaPath": "#/properties/title/type",
|
|
287
|
-
"keyword": "type",
|
|
288
|
-
"params": { "type": "string" },
|
|
289
|
-
"message": "must be string"
|
|
290
|
-
}
|
|
291
|
-
]
|
|
292
|
-
}
|
|
293
|
-
```
|
|
294
|
-
|
|
295
|
-
You can override this behavior using the onValidationFailed handler option in [requestValidation](#requestvalidation) or [responseValidation](#responsevalidation).
|
|
296
|
-
|
|
297
|
-
Inside your handler, you can whether:
|
|
298
|
-
|
|
299
|
-
- Transform the error list and throw a custom exception.
|
|
300
|
-
- Log and ignore errors (return without throwing).
|
|
301
|
-
|
|
302
|
-
```typescript
|
|
303
|
-
OpenApiValidatorModule.forRoot({
|
|
304
|
-
specSource: { type: "object", spec: openApiSpec },
|
|
305
|
-
requestValidation: {
|
|
306
|
-
enable: true,
|
|
307
|
-
onValidationFailed: (context, errors) => {
|
|
308
|
-
// Custom error handling
|
|
309
|
-
throw new BadRequestException({
|
|
310
|
-
status: "validation_failed",
|
|
311
|
-
issues: errors.map((e) => ({
|
|
312
|
-
path: e.instancePath,
|
|
313
|
-
message: e.message,
|
|
314
|
-
received: e.data,
|
|
315
|
-
})),
|
|
316
|
-
});
|
|
317
|
-
},
|
|
318
|
-
},
|
|
319
|
-
});
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
## Performance and Compatibility
|
|
323
|
-
|
|
324
|
-
- Optional schema [pre-compilation](#configuration-options) removes first-hit latency at the cost of longer startup.
|
|
325
|
-
- Express and Fastify adopters are supported.
|
|
326
|
-
- Supports NestJS version >= 9
|
|
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 | [](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 | [](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 | [](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 | [](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
|
@@ -40,8 +40,8 @@ var __decorateParam = (index, decorator) => (target, key) => decorator(target, k
|
|
|
40
40
|
var index_exports = {};
|
|
41
41
|
__export(index_exports, {
|
|
42
42
|
OPENAPI_VALIDATOR: () => OPENAPI_VALIDATOR,
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
OpenAPIValidatorModule: () => OpenAPIValidatorModule,
|
|
44
|
+
OpenAPIValidatorService: () => OpenAPIValidatorService,
|
|
45
45
|
Validate: () => Validate
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -54,9 +54,14 @@ var import_core3 = require("@nestjs/core");
|
|
|
54
54
|
var import_common = require("@nestjs/common");
|
|
55
55
|
var import_runtime = require("@nest-openapi/runtime");
|
|
56
56
|
var import_ajv = __toESM(require("ajv"), 1);
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var
|
|
57
|
+
|
|
58
|
+
// src/types/validator-options.interface.ts
|
|
59
|
+
var OPENAPI_VALIDATOR_RUNTIME = Symbol("OPENAPI_VALIDATOR_RUNTIME");
|
|
60
|
+
var OPENAPI_VALIDATOR_OPTIONS = Symbol("OPENAPI_VALIDATOR_OPTIONS");
|
|
61
|
+
|
|
62
|
+
// src/services/openapi-validator.service.ts
|
|
63
|
+
var OPENAPI_VALIDATOR = Symbol("OPENAPI_VALIDATOR");
|
|
64
|
+
var OpenAPIValidatorService = class {
|
|
60
65
|
constructor(runtime, options) {
|
|
61
66
|
this.runtime = runtime;
|
|
62
67
|
this.options = options;
|
|
@@ -78,7 +83,7 @@ var OpenApiValidatorService = class {
|
|
|
78
83
|
${JSON.stringify(opts, null, 2)}`);
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
|
-
logger = new import_common.Logger("
|
|
86
|
+
logger = new import_common.Logger("OpenAPIValidator");
|
|
82
87
|
ajv;
|
|
83
88
|
openApiSpec;
|
|
84
89
|
debugLog;
|
|
@@ -296,7 +301,7 @@ ${JSON.stringify(data, null, 2)}`);
|
|
|
296
301
|
});
|
|
297
302
|
continue;
|
|
298
303
|
}
|
|
299
|
-
if (
|
|
304
|
+
if (param.schema) {
|
|
300
305
|
const schema = this.runtime.schemaResolver.resolveSchema(param.schema);
|
|
301
306
|
if (schema) {
|
|
302
307
|
const paramValue = { value };
|
|
@@ -337,11 +342,11 @@ ${JSON.stringify(data, null, 2)}`);
|
|
|
337
342
|
};
|
|
338
343
|
}
|
|
339
344
|
};
|
|
340
|
-
|
|
345
|
+
OpenAPIValidatorService = __decorateClass([
|
|
341
346
|
(0, import_common.Injectable)(),
|
|
342
|
-
__decorateParam(0, (0, import_common.Inject)(
|
|
347
|
+
__decorateParam(0, (0, import_common.Inject)(OPENAPI_VALIDATOR_RUNTIME)),
|
|
343
348
|
__decorateParam(1, (0, import_common.Inject)(OPENAPI_VALIDATOR_OPTIONS))
|
|
344
|
-
],
|
|
349
|
+
], OpenAPIValidatorService);
|
|
345
350
|
|
|
346
351
|
// src/interceptors/request-validation.interceptor.ts
|
|
347
352
|
var import_common3 = require("@nestjs/common");
|
|
@@ -350,8 +355,8 @@ var import_runtime3 = require("@nest-openapi/runtime");
|
|
|
350
355
|
|
|
351
356
|
// src/decorators/validate.decorator.ts
|
|
352
357
|
var import_common2 = require("@nestjs/common");
|
|
353
|
-
var
|
|
354
|
-
var Validate = (options = {}) => (0, import_common2.SetMetadata)(
|
|
358
|
+
var VALIDATE_OVERRIDE = Symbol("VALIDATE_OVERRIDE");
|
|
359
|
+
var Validate = (options = {}) => (0, import_common2.SetMetadata)(VALIDATE_OVERRIDE, options);
|
|
355
360
|
|
|
356
361
|
// src/interceptors/request-validation.interceptor.ts
|
|
357
362
|
var RequestValidationInterceptor = class {
|
|
@@ -360,7 +365,7 @@ var RequestValidationInterceptor = class {
|
|
|
360
365
|
this.reflector = reflector;
|
|
361
366
|
this.debugLog = import_runtime3.DebugUtil.createDebugFn(this.logger, this.validatorService.validationOptions.debug || false);
|
|
362
367
|
}
|
|
363
|
-
logger = new import_common3.Logger("
|
|
368
|
+
logger = new import_common3.Logger("OpenAPIValidator");
|
|
364
369
|
debugLog;
|
|
365
370
|
async intercept(context, next) {
|
|
366
371
|
if (!this.validatorService.openApiSpec) {
|
|
@@ -394,7 +399,7 @@ var RequestValidationInterceptor = class {
|
|
|
394
399
|
}
|
|
395
400
|
getValidationDecorator(context) {
|
|
396
401
|
const validateMetadata = this.reflector.getAllAndOverride(
|
|
397
|
-
|
|
402
|
+
VALIDATE_OVERRIDE,
|
|
398
403
|
[context.getHandler(), context.getClass()]
|
|
399
404
|
);
|
|
400
405
|
if (validateMetadata) {
|
|
@@ -437,7 +442,7 @@ var ResponseValidationInterceptor = class {
|
|
|
437
442
|
this.reflector = reflector;
|
|
438
443
|
this.debugLog = import_runtime5.DebugUtil.createDebugFn(this.logger, this.validatorService.validationOptions.debug || false);
|
|
439
444
|
}
|
|
440
|
-
logger = new import_common4.Logger("
|
|
445
|
+
logger = new import_common4.Logger("OpenAPIValidator");
|
|
441
446
|
debugLog;
|
|
442
447
|
intercept(context, next) {
|
|
443
448
|
if (!this.validatorService.openApiSpec) {
|
|
@@ -477,7 +482,7 @@ var ResponseValidationInterceptor = class {
|
|
|
477
482
|
}
|
|
478
483
|
shouldValidateResponse(context) {
|
|
479
484
|
const validateMetadata = this.reflector.getAllAndOverride(
|
|
480
|
-
|
|
485
|
+
VALIDATE_OVERRIDE,
|
|
481
486
|
[context.getHandler(), context.getClass()]
|
|
482
487
|
);
|
|
483
488
|
if (validateMetadata) {
|
|
@@ -501,7 +506,7 @@ ResponseValidationInterceptor = __decorateClass([
|
|
|
501
506
|
|
|
502
507
|
// src/modules/openapi-validator.module.ts
|
|
503
508
|
var import_runtime7 = require("@nest-openapi/runtime");
|
|
504
|
-
var
|
|
509
|
+
var OpenAPIValidatorModule = class {
|
|
505
510
|
/**
|
|
506
511
|
* Configure the OpenAPI validator module with static options
|
|
507
512
|
*/
|
|
@@ -525,16 +530,12 @@ var OpenApiValidatorModule = class {
|
|
|
525
530
|
},
|
|
526
531
|
// Core services
|
|
527
532
|
{
|
|
528
|
-
provide:
|
|
529
|
-
useFactory: async (
|
|
530
|
-
|
|
531
|
-
await svc.onModuleInit();
|
|
532
|
-
return svc;
|
|
533
|
-
},
|
|
534
|
-
inject: [import_runtime7.OPENAPI_RUNTIME_OPTIONS]
|
|
533
|
+
provide: OPENAPI_VALIDATOR_RUNTIME,
|
|
534
|
+
useFactory: async (opts) => import_runtime7.OpenAPIRuntimePool.getOrCreate({ specSource: opts.specSource, debug: opts.debug }),
|
|
535
|
+
inject: [OPENAPI_VALIDATOR_OPTIONS]
|
|
535
536
|
},
|
|
536
|
-
|
|
537
|
-
{ provide: OPENAPI_VALIDATOR, useExisting:
|
|
537
|
+
OpenAPIValidatorService,
|
|
538
|
+
{ provide: OPENAPI_VALIDATOR, useExisting: OpenAPIValidatorService },
|
|
538
539
|
// Interceptors
|
|
539
540
|
{ provide: import_core3.APP_INTERCEPTOR, useClass: RequestValidationInterceptor }
|
|
540
541
|
];
|
|
@@ -545,13 +546,11 @@ var OpenApiValidatorModule = class {
|
|
|
545
546
|
});
|
|
546
547
|
}
|
|
547
548
|
return {
|
|
548
|
-
module:
|
|
549
|
+
module: OpenAPIValidatorModule,
|
|
549
550
|
providers,
|
|
550
551
|
exports: [
|
|
551
|
-
OPENAPI_VALIDATOR_OPTIONS,
|
|
552
552
|
OPENAPI_VALIDATOR,
|
|
553
|
-
|
|
554
|
-
OpenApiValidatorService
|
|
553
|
+
OpenAPIValidatorService
|
|
555
554
|
]
|
|
556
555
|
};
|
|
557
556
|
}
|
|
@@ -586,16 +585,12 @@ var OpenApiValidatorModule = class {
|
|
|
586
585
|
},
|
|
587
586
|
// Core services
|
|
588
587
|
{
|
|
589
|
-
provide:
|
|
590
|
-
useFactory: async (
|
|
591
|
-
|
|
592
|
-
await svc.onModuleInit();
|
|
593
|
-
return svc;
|
|
594
|
-
},
|
|
595
|
-
inject: [import_runtime7.OPENAPI_RUNTIME_OPTIONS]
|
|
588
|
+
provide: OPENAPI_VALIDATOR_RUNTIME,
|
|
589
|
+
useFactory: async (opts) => import_runtime7.OpenAPIRuntimePool.getOrCreate({ specSource: opts.specSource, debug: opts.debug }),
|
|
590
|
+
inject: [OPENAPI_VALIDATOR_OPTIONS]
|
|
596
591
|
},
|
|
597
|
-
|
|
598
|
-
{ provide: OPENAPI_VALIDATOR, useExisting:
|
|
592
|
+
OpenAPIValidatorService,
|
|
593
|
+
{ provide: OPENAPI_VALIDATOR, useExisting: OpenAPIValidatorService },
|
|
599
594
|
// Interceptors
|
|
600
595
|
{ provide: import_core3.APP_INTERCEPTOR, useClass: RequestValidationInterceptor },
|
|
601
596
|
// Conditionally add response validation
|
|
@@ -607,30 +602,28 @@ var OpenApiValidatorModule = class {
|
|
|
607
602
|
}
|
|
608
603
|
return { intercept: (_ctx, next) => next.handle() };
|
|
609
604
|
},
|
|
610
|
-
inject: [OPENAPI_VALIDATOR_OPTIONS,
|
|
605
|
+
inject: [OPENAPI_VALIDATOR_OPTIONS, OpenAPIValidatorService, import_core3.Reflector]
|
|
611
606
|
}
|
|
612
607
|
];
|
|
613
608
|
return {
|
|
614
|
-
module:
|
|
609
|
+
module: OpenAPIValidatorModule,
|
|
615
610
|
imports: options.imports || [],
|
|
616
611
|
providers,
|
|
617
612
|
exports: [
|
|
618
|
-
OPENAPI_VALIDATOR_OPTIONS,
|
|
619
613
|
OPENAPI_VALIDATOR,
|
|
620
|
-
|
|
621
|
-
OpenApiValidatorService
|
|
614
|
+
OpenAPIValidatorService
|
|
622
615
|
]
|
|
623
616
|
};
|
|
624
617
|
}
|
|
625
618
|
};
|
|
626
|
-
|
|
619
|
+
OpenAPIValidatorModule = __decorateClass([
|
|
627
620
|
(0, import_common5.Global)(),
|
|
628
621
|
(0, import_common5.Module)({})
|
|
629
|
-
],
|
|
622
|
+
], OpenAPIValidatorModule);
|
|
630
623
|
// Annotate the CommonJS export names for ESM import in node:
|
|
631
624
|
0 && (module.exports = {
|
|
632
625
|
OPENAPI_VALIDATOR,
|
|
633
|
-
|
|
634
|
-
|
|
626
|
+
OpenAPIValidatorModule,
|
|
627
|
+
OpenAPIValidatorService,
|
|
635
628
|
Validate
|
|
636
629
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _nestjs_common from '@nestjs/common';
|
|
2
2
|
import { ExecutionContext, DynamicModule, OnApplicationBootstrap } from '@nestjs/common';
|
|
3
3
|
import Ajv, { ErrorObject, Options } from 'ajv';
|
|
4
|
-
import { SpecSource, OpenAPISpec,
|
|
4
|
+
import { SpecSource, OpenAPISpec, OpenAPIRuntimeService } from '@nest-openapi/runtime';
|
|
5
5
|
import { HttpArgumentsHost } from '@nestjs/common/interfaces';
|
|
6
6
|
|
|
7
7
|
interface ValidationError extends ErrorObject {
|
|
@@ -88,7 +88,7 @@ interface ValidatorOptions {
|
|
|
88
88
|
debug?: boolean;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
declare class
|
|
91
|
+
declare class OpenAPIValidatorModule {
|
|
92
92
|
/**
|
|
93
93
|
* Configure the OpenAPI validator module with static options
|
|
94
94
|
*/
|
|
@@ -103,15 +103,15 @@ declare class OpenApiValidatorModule {
|
|
|
103
103
|
}): DynamicModule;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
declare const OPENAPI_VALIDATOR
|
|
107
|
-
declare class
|
|
106
|
+
declare const OPENAPI_VALIDATOR: unique symbol;
|
|
107
|
+
declare class OpenAPIValidatorService implements OnApplicationBootstrap {
|
|
108
108
|
private readonly runtime;
|
|
109
109
|
private readonly options;
|
|
110
110
|
private readonly logger;
|
|
111
111
|
private ajv;
|
|
112
112
|
openApiSpec: OpenAPISpec;
|
|
113
113
|
private debugLog;
|
|
114
|
-
constructor(runtime:
|
|
114
|
+
constructor(runtime: OpenAPIRuntimeService, options: ValidatorOptions);
|
|
115
115
|
onApplicationBootstrap(): Promise<void>;
|
|
116
116
|
private get isSpecLoaded();
|
|
117
117
|
get validationOptions(): ValidatorOptions;
|
|
@@ -137,7 +137,8 @@ declare class OpenApiValidatorService implements OnApplicationBootstrap {
|
|
|
137
137
|
private getParameterSchema;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
declare const VALIDATE_OVERRIDE: unique symbol;
|
|
141
|
+
interface ValidateOverrideOptions {
|
|
141
142
|
request?: boolean | {
|
|
142
143
|
params?: boolean;
|
|
143
144
|
query?: boolean;
|
|
@@ -173,6 +174,6 @@ interface ValidateOptions {
|
|
|
173
174
|
* }
|
|
174
175
|
* ```
|
|
175
176
|
*/
|
|
176
|
-
declare const Validate: (options?:
|
|
177
|
+
declare const Validate: (options?: ValidateOverrideOptions) => _nestjs_common.CustomDecorator<typeof VALIDATE_OVERRIDE>;
|
|
177
178
|
|
|
178
|
-
export { OPENAPI_VALIDATOR,
|
|
179
|
+
export { OPENAPI_VALIDATOR, OpenAPIValidatorModule, OpenAPIValidatorService, Validate, type ValidateOverrideOptions, type ValidationError, type ValidationErrorResponse, type ValidatorOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _nestjs_common from '@nestjs/common';
|
|
2
2
|
import { ExecutionContext, DynamicModule, OnApplicationBootstrap } from '@nestjs/common';
|
|
3
3
|
import Ajv, { ErrorObject, Options } from 'ajv';
|
|
4
|
-
import { SpecSource, OpenAPISpec,
|
|
4
|
+
import { SpecSource, OpenAPISpec, OpenAPIRuntimeService } from '@nest-openapi/runtime';
|
|
5
5
|
import { HttpArgumentsHost } from '@nestjs/common/interfaces';
|
|
6
6
|
|
|
7
7
|
interface ValidationError extends ErrorObject {
|
|
@@ -88,7 +88,7 @@ interface ValidatorOptions {
|
|
|
88
88
|
debug?: boolean;
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
declare class
|
|
91
|
+
declare class OpenAPIValidatorModule {
|
|
92
92
|
/**
|
|
93
93
|
* Configure the OpenAPI validator module with static options
|
|
94
94
|
*/
|
|
@@ -103,15 +103,15 @@ declare class OpenApiValidatorModule {
|
|
|
103
103
|
}): DynamicModule;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
declare const OPENAPI_VALIDATOR
|
|
107
|
-
declare class
|
|
106
|
+
declare const OPENAPI_VALIDATOR: unique symbol;
|
|
107
|
+
declare class OpenAPIValidatorService implements OnApplicationBootstrap {
|
|
108
108
|
private readonly runtime;
|
|
109
109
|
private readonly options;
|
|
110
110
|
private readonly logger;
|
|
111
111
|
private ajv;
|
|
112
112
|
openApiSpec: OpenAPISpec;
|
|
113
113
|
private debugLog;
|
|
114
|
-
constructor(runtime:
|
|
114
|
+
constructor(runtime: OpenAPIRuntimeService, options: ValidatorOptions);
|
|
115
115
|
onApplicationBootstrap(): Promise<void>;
|
|
116
116
|
private get isSpecLoaded();
|
|
117
117
|
get validationOptions(): ValidatorOptions;
|
|
@@ -137,7 +137,8 @@ declare class OpenApiValidatorService implements OnApplicationBootstrap {
|
|
|
137
137
|
private getParameterSchema;
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
|
|
140
|
+
declare const VALIDATE_OVERRIDE: unique symbol;
|
|
141
|
+
interface ValidateOverrideOptions {
|
|
141
142
|
request?: boolean | {
|
|
142
143
|
params?: boolean;
|
|
143
144
|
query?: boolean;
|
|
@@ -173,6 +174,6 @@ interface ValidateOptions {
|
|
|
173
174
|
* }
|
|
174
175
|
* ```
|
|
175
176
|
*/
|
|
176
|
-
declare const Validate: (options?:
|
|
177
|
+
declare const Validate: (options?: ValidateOverrideOptions) => _nestjs_common.CustomDecorator<typeof VALIDATE_OVERRIDE>;
|
|
177
178
|
|
|
178
|
-
export { OPENAPI_VALIDATOR,
|
|
179
|
+
export { OPENAPI_VALIDATOR, OpenAPIValidatorModule, OpenAPIValidatorService, Validate, type ValidateOverrideOptions, type ValidationError, type ValidationErrorResponse, type ValidatorOptions };
|
package/dist/index.js
CHANGED
|
@@ -16,11 +16,16 @@ import { APP_INTERCEPTOR, Reflector as Reflector3 } from "@nestjs/core";
|
|
|
16
16
|
|
|
17
17
|
// src/services/openapi-validator.service.ts
|
|
18
18
|
import { Injectable, Logger, Inject } from "@nestjs/common";
|
|
19
|
-
import {
|
|
19
|
+
import { DebugUtil, PlatformUtil } from "@nest-openapi/runtime";
|
|
20
20
|
import Ajv from "ajv";
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var
|
|
21
|
+
|
|
22
|
+
// src/types/validator-options.interface.ts
|
|
23
|
+
var OPENAPI_VALIDATOR_RUNTIME = Symbol("OPENAPI_VALIDATOR_RUNTIME");
|
|
24
|
+
var OPENAPI_VALIDATOR_OPTIONS = Symbol("OPENAPI_VALIDATOR_OPTIONS");
|
|
25
|
+
|
|
26
|
+
// src/services/openapi-validator.service.ts
|
|
27
|
+
var OPENAPI_VALIDATOR = Symbol("OPENAPI_VALIDATOR");
|
|
28
|
+
var OpenAPIValidatorService = class {
|
|
24
29
|
constructor(runtime, options) {
|
|
25
30
|
this.runtime = runtime;
|
|
26
31
|
this.options = options;
|
|
@@ -42,7 +47,7 @@ var OpenApiValidatorService = class {
|
|
|
42
47
|
${JSON.stringify(opts, null, 2)}`);
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
|
-
logger = new Logger("
|
|
50
|
+
logger = new Logger("OpenAPIValidator");
|
|
46
51
|
ajv;
|
|
47
52
|
openApiSpec;
|
|
48
53
|
debugLog;
|
|
@@ -260,7 +265,7 @@ ${JSON.stringify(data, null, 2)}`);
|
|
|
260
265
|
});
|
|
261
266
|
continue;
|
|
262
267
|
}
|
|
263
|
-
if (
|
|
268
|
+
if (param.schema) {
|
|
264
269
|
const schema = this.runtime.schemaResolver.resolveSchema(param.schema);
|
|
265
270
|
if (schema) {
|
|
266
271
|
const paramValue = { value };
|
|
@@ -301,11 +306,11 @@ ${JSON.stringify(data, null, 2)}`);
|
|
|
301
306
|
};
|
|
302
307
|
}
|
|
303
308
|
};
|
|
304
|
-
|
|
309
|
+
OpenAPIValidatorService = __decorateClass([
|
|
305
310
|
Injectable(),
|
|
306
|
-
__decorateParam(0, Inject(
|
|
311
|
+
__decorateParam(0, Inject(OPENAPI_VALIDATOR_RUNTIME)),
|
|
307
312
|
__decorateParam(1, Inject(OPENAPI_VALIDATOR_OPTIONS))
|
|
308
|
-
],
|
|
313
|
+
], OpenAPIValidatorService);
|
|
309
314
|
|
|
310
315
|
// src/interceptors/request-validation.interceptor.ts
|
|
311
316
|
import {
|
|
@@ -319,8 +324,8 @@ import { DebugUtil as DebugUtil2 } from "@nest-openapi/runtime";
|
|
|
319
324
|
|
|
320
325
|
// src/decorators/validate.decorator.ts
|
|
321
326
|
import { SetMetadata } from "@nestjs/common";
|
|
322
|
-
var
|
|
323
|
-
var Validate = (options = {}) => SetMetadata(
|
|
327
|
+
var VALIDATE_OVERRIDE = Symbol("VALIDATE_OVERRIDE");
|
|
328
|
+
var Validate = (options = {}) => SetMetadata(VALIDATE_OVERRIDE, options);
|
|
324
329
|
|
|
325
330
|
// src/interceptors/request-validation.interceptor.ts
|
|
326
331
|
var RequestValidationInterceptor = class {
|
|
@@ -329,7 +334,7 @@ var RequestValidationInterceptor = class {
|
|
|
329
334
|
this.reflector = reflector;
|
|
330
335
|
this.debugLog = DebugUtil2.createDebugFn(this.logger, this.validatorService.validationOptions.debug || false);
|
|
331
336
|
}
|
|
332
|
-
logger = new Logger2("
|
|
337
|
+
logger = new Logger2("OpenAPIValidator");
|
|
333
338
|
debugLog;
|
|
334
339
|
async intercept(context, next) {
|
|
335
340
|
if (!this.validatorService.openApiSpec) {
|
|
@@ -363,7 +368,7 @@ var RequestValidationInterceptor = class {
|
|
|
363
368
|
}
|
|
364
369
|
getValidationDecorator(context) {
|
|
365
370
|
const validateMetadata = this.reflector.getAllAndOverride(
|
|
366
|
-
|
|
371
|
+
VALIDATE_OVERRIDE,
|
|
367
372
|
[context.getHandler(), context.getClass()]
|
|
368
373
|
);
|
|
369
374
|
if (validateMetadata) {
|
|
@@ -411,7 +416,7 @@ var ResponseValidationInterceptor = class {
|
|
|
411
416
|
this.reflector = reflector;
|
|
412
417
|
this.debugLog = DebugUtil3.createDebugFn(this.logger, this.validatorService.validationOptions.debug || false);
|
|
413
418
|
}
|
|
414
|
-
logger = new Logger3("
|
|
419
|
+
logger = new Logger3("OpenAPIValidator");
|
|
415
420
|
debugLog;
|
|
416
421
|
intercept(context, next) {
|
|
417
422
|
if (!this.validatorService.openApiSpec) {
|
|
@@ -451,7 +456,7 @@ var ResponseValidationInterceptor = class {
|
|
|
451
456
|
}
|
|
452
457
|
shouldValidateResponse(context) {
|
|
453
458
|
const validateMetadata = this.reflector.getAllAndOverride(
|
|
454
|
-
|
|
459
|
+
VALIDATE_OVERRIDE,
|
|
455
460
|
[context.getHandler(), context.getClass()]
|
|
456
461
|
);
|
|
457
462
|
if (validateMetadata) {
|
|
@@ -474,8 +479,8 @@ ResponseValidationInterceptor = __decorateClass([
|
|
|
474
479
|
], ResponseValidationInterceptor);
|
|
475
480
|
|
|
476
481
|
// src/modules/openapi-validator.module.ts
|
|
477
|
-
import {
|
|
478
|
-
var
|
|
482
|
+
import { OPENAPI_RUNTIME_OPTIONS, OpenAPIRuntimePool } from "@nest-openapi/runtime";
|
|
483
|
+
var OpenAPIValidatorModule = class {
|
|
479
484
|
/**
|
|
480
485
|
* Configure the OpenAPI validator module with static options
|
|
481
486
|
*/
|
|
@@ -499,16 +504,12 @@ var OpenApiValidatorModule = class {
|
|
|
499
504
|
},
|
|
500
505
|
// Core services
|
|
501
506
|
{
|
|
502
|
-
provide:
|
|
503
|
-
useFactory: async (
|
|
504
|
-
|
|
505
|
-
await svc.onModuleInit();
|
|
506
|
-
return svc;
|
|
507
|
-
},
|
|
508
|
-
inject: [OPENAPI_RUNTIME_OPTIONS]
|
|
507
|
+
provide: OPENAPI_VALIDATOR_RUNTIME,
|
|
508
|
+
useFactory: async (opts) => OpenAPIRuntimePool.getOrCreate({ specSource: opts.specSource, debug: opts.debug }),
|
|
509
|
+
inject: [OPENAPI_VALIDATOR_OPTIONS]
|
|
509
510
|
},
|
|
510
|
-
|
|
511
|
-
{ provide: OPENAPI_VALIDATOR, useExisting:
|
|
511
|
+
OpenAPIValidatorService,
|
|
512
|
+
{ provide: OPENAPI_VALIDATOR, useExisting: OpenAPIValidatorService },
|
|
512
513
|
// Interceptors
|
|
513
514
|
{ provide: APP_INTERCEPTOR, useClass: RequestValidationInterceptor }
|
|
514
515
|
];
|
|
@@ -519,13 +520,11 @@ var OpenApiValidatorModule = class {
|
|
|
519
520
|
});
|
|
520
521
|
}
|
|
521
522
|
return {
|
|
522
|
-
module:
|
|
523
|
+
module: OpenAPIValidatorModule,
|
|
523
524
|
providers,
|
|
524
525
|
exports: [
|
|
525
|
-
OPENAPI_VALIDATOR_OPTIONS,
|
|
526
526
|
OPENAPI_VALIDATOR,
|
|
527
|
-
|
|
528
|
-
OpenApiValidatorService
|
|
527
|
+
OpenAPIValidatorService
|
|
529
528
|
]
|
|
530
529
|
};
|
|
531
530
|
}
|
|
@@ -560,16 +559,12 @@ var OpenApiValidatorModule = class {
|
|
|
560
559
|
},
|
|
561
560
|
// Core services
|
|
562
561
|
{
|
|
563
|
-
provide:
|
|
564
|
-
useFactory: async (
|
|
565
|
-
|
|
566
|
-
await svc.onModuleInit();
|
|
567
|
-
return svc;
|
|
568
|
-
},
|
|
569
|
-
inject: [OPENAPI_RUNTIME_OPTIONS]
|
|
562
|
+
provide: OPENAPI_VALIDATOR_RUNTIME,
|
|
563
|
+
useFactory: async (opts) => OpenAPIRuntimePool.getOrCreate({ specSource: opts.specSource, debug: opts.debug }),
|
|
564
|
+
inject: [OPENAPI_VALIDATOR_OPTIONS]
|
|
570
565
|
},
|
|
571
|
-
|
|
572
|
-
{ provide: OPENAPI_VALIDATOR, useExisting:
|
|
566
|
+
OpenAPIValidatorService,
|
|
567
|
+
{ provide: OPENAPI_VALIDATOR, useExisting: OpenAPIValidatorService },
|
|
573
568
|
// Interceptors
|
|
574
569
|
{ provide: APP_INTERCEPTOR, useClass: RequestValidationInterceptor },
|
|
575
570
|
// Conditionally add response validation
|
|
@@ -581,29 +576,27 @@ var OpenApiValidatorModule = class {
|
|
|
581
576
|
}
|
|
582
577
|
return { intercept: (_ctx, next) => next.handle() };
|
|
583
578
|
},
|
|
584
|
-
inject: [OPENAPI_VALIDATOR_OPTIONS,
|
|
579
|
+
inject: [OPENAPI_VALIDATOR_OPTIONS, OpenAPIValidatorService, Reflector3]
|
|
585
580
|
}
|
|
586
581
|
];
|
|
587
582
|
return {
|
|
588
|
-
module:
|
|
583
|
+
module: OpenAPIValidatorModule,
|
|
589
584
|
imports: options.imports || [],
|
|
590
585
|
providers,
|
|
591
586
|
exports: [
|
|
592
|
-
OPENAPI_VALIDATOR_OPTIONS,
|
|
593
587
|
OPENAPI_VALIDATOR,
|
|
594
|
-
|
|
595
|
-
OpenApiValidatorService
|
|
588
|
+
OpenAPIValidatorService
|
|
596
589
|
]
|
|
597
590
|
};
|
|
598
591
|
}
|
|
599
592
|
};
|
|
600
|
-
|
|
593
|
+
OpenAPIValidatorModule = __decorateClass([
|
|
601
594
|
Global(),
|
|
602
595
|
Module({})
|
|
603
|
-
],
|
|
596
|
+
], OpenAPIValidatorModule);
|
|
604
597
|
export {
|
|
605
598
|
OPENAPI_VALIDATOR,
|
|
606
|
-
|
|
607
|
-
|
|
599
|
+
OpenAPIValidatorModule,
|
|
600
|
+
OpenAPIValidatorService,
|
|
608
601
|
Validate
|
|
609
602
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nest-openapi/validator",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Automatic request/response validation for NestJS using OpenAPI specifications",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "Automatic request/response validation for NestJS using your OpenAPI specifications",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"keywords": [
|
|
7
7
|
"nest",
|
|
@@ -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,24 +40,11 @@
|
|
|
27
40
|
"README.md",
|
|
28
41
|
"LICENSE"
|
|
29
42
|
],
|
|
30
|
-
"homepage": "https://nest-openapi.github.io/",
|
|
31
|
-
"repository": {
|
|
32
|
-
"type": "git",
|
|
33
|
-
"url": "https://github.com/ts-oas/nest-openapi.git"
|
|
34
|
-
},
|
|
35
|
-
"publishConfig": {
|
|
36
|
-
"access": "public"
|
|
37
|
-
},
|
|
38
|
-
"author": "Alireza Malek",
|
|
39
|
-
"license": "MIT",
|
|
40
|
-
"bugs": {
|
|
41
|
-
"url": "https://github.com/ts-oas/nest-openapi/issues"
|
|
42
|
-
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"@nestjs/common": "^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
45
45
|
"@nestjs/core": "^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
46
46
|
"ajv": "^8.0.0",
|
|
47
|
-
"reflect-metadata": "^0.
|
|
47
|
+
"reflect-metadata": "^0.2.2"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
50
50
|
"ajv": {
|
|
@@ -52,8 +52,9 @@
|
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@nest-openapi/runtime": "^0.1.
|
|
56
|
-
"ajv": "^8.0.0"
|
|
55
|
+
"@nest-openapi/runtime": "^0.1.2",
|
|
56
|
+
"ajv": "^8.0.0",
|
|
57
|
+
"rxjs": "^7.2.0"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
60
|
"@nestjs/common": "^11.0.0",
|
|
@@ -66,13 +67,12 @@
|
|
|
66
67
|
"@typescript-eslint/parser": "^8.35.1",
|
|
67
68
|
"eslint": "^9.30.1",
|
|
68
69
|
"jest": "^29.0.0",
|
|
69
|
-
"reflect-metadata": "^0.
|
|
70
|
-
"rxjs": "^7.2.0",
|
|
70
|
+
"reflect-metadata": "^0.2.2",
|
|
71
71
|
"supertest": "^7.1.0",
|
|
72
72
|
"ts-jest": "^29.0.0",
|
|
73
73
|
"tsup": "^8.5.0",
|
|
74
|
-
"typescript": "^5.
|
|
75
|
-
"@nest-openapi/runtime": "^0.1.
|
|
74
|
+
"typescript": "^5.9.0",
|
|
75
|
+
"@nest-openapi/runtime": "^0.1.2"
|
|
76
76
|
},
|
|
77
77
|
"jest": {
|
|
78
78
|
"moduleFileExtensions": [
|