zod-openapi 0.5.2 → 0.7.0
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 +29 -16
- package/lib-commonjs/create/components.js +32 -23
- package/lib-commonjs/create/components.js.map +1 -1
- package/lib-commonjs/create/schema/index.js +20 -15
- package/lib-commonjs/create/schema/index.js.map +1 -1
- package/lib-commonjs/create/schema/manual.js +19 -0
- package/lib-commonjs/create/schema/manual.js.map +1 -0
- package/lib-commonjs/create/schema/metadata.js +1 -1
- package/lib-commonjs/create/schema/metadata.js.map +1 -1
- package/lib-commonjs/create/schema/transform.js +2 -2
- package/lib-commonjs/create/schema/transform.js.map +1 -1
- package/lib-commonjs/create/schema/unknown.js +1 -14
- package/lib-commonjs/create/schema/unknown.js.map +1 -1
- package/lib-es2015/create/components.js +32 -23
- package/lib-es2015/create/components.js.map +1 -1
- package/lib-es2015/create/schema/index.js +21 -16
- package/lib-es2015/create/schema/index.js.map +1 -1
- package/lib-es2015/create/schema/manual.js +15 -0
- package/lib-es2015/create/schema/manual.js.map +1 -0
- package/lib-es2015/create/schema/metadata.js +1 -1
- package/lib-es2015/create/schema/metadata.js.map +1 -1
- package/lib-es2015/create/schema/transform.js +2 -2
- package/lib-es2015/create/schema/transform.js.map +1 -1
- package/lib-es2015/create/schema/unknown.js +1 -14
- package/lib-es2015/create/schema/unknown.js.map +1 -1
- package/lib-types/create/components.d.ts +5 -7
- package/lib-types/create/schema/index.d.ts +1 -1
- package/lib-types/create/schema/manual.d.ts +3 -0
- package/lib-types/create/schema/unknown.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# zod-openapi
|
|
2
2
|
|
|
3
|
-
A Typescript library to create full OpenAPI 3 documentation from [Zod](https://github.com/colinhacks/zod) Types.
|
|
3
|
+
A Typescript library to create full OpenAPI 3.x documentation from [Zod](https://github.com/colinhacks/zod) Types.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/zod-openapi)
|
|
6
6
|
[](https://www.npmjs.com/package/zod-openapi)
|
|
@@ -179,7 +179,7 @@ const document = createDocumentYaml(
|
|
|
179
179
|
version: '1.0.0',
|
|
180
180
|
},
|
|
181
181
|
},
|
|
182
|
-
{ options: {
|
|
182
|
+
{ options: { aliasDuplicateObjects: false } },
|
|
183
183
|
);
|
|
184
184
|
```
|
|
185
185
|
|
|
@@ -258,12 +258,17 @@ createDocument({
|
|
|
258
258
|
|
|
259
259
|
### Creating Components
|
|
260
260
|
|
|
261
|
-
OpenAPI allows you to define reusable [components](https://swagger.io/docs/specification/components/) and this library allows you to replicate that in
|
|
261
|
+
OpenAPI allows you to define reusable [components](https://swagger.io/docs/specification/components/) and this library allows you to replicate that in two separate ways.
|
|
262
|
+
|
|
263
|
+
1. Auto registering schema
|
|
264
|
+
2. Manually registering schema
|
|
262
265
|
|
|
263
266
|
#### Schema
|
|
264
267
|
|
|
265
268
|
If we take the example in `createDocument` and instead create `title` as follows
|
|
266
269
|
|
|
270
|
+
##### Auto Registering Schema
|
|
271
|
+
|
|
267
272
|
```typescript
|
|
268
273
|
const title = z.string().openapi({
|
|
269
274
|
description: 'Job title',
|
|
@@ -298,7 +303,9 @@ Wherever `title` is used in schemas across the document, it will instead be crea
|
|
|
298
303
|
|
|
299
304
|
This can be an extremely powerful way to generate better Open API documentation. There are some Open API features like [discriminator mapping](https://swagger.io/docs/specification/data-models/inheritance-and-polymorphism/) which require all schemas in the union to contain a ref.
|
|
300
305
|
|
|
301
|
-
|
|
306
|
+
##### Manually Registering Schema
|
|
307
|
+
|
|
308
|
+
Another way to register schema instead of adding a `ref` is to add it to the components directly. This will still work in the same way as `ref`. So whenever we run into that Zod type we will replace it with a reference.
|
|
302
309
|
|
|
303
310
|
eg.
|
|
304
311
|
|
|
@@ -306,7 +313,7 @@ eg.
|
|
|
306
313
|
{
|
|
307
314
|
"components": {
|
|
308
315
|
"schemas": {
|
|
309
|
-
MyJobSchema //
|
|
316
|
+
MyJobSchema // this will register this Zod Schema as MyJobSchema unless `ref` in `.openapi()` is specified on the type
|
|
310
317
|
}
|
|
311
318
|
}
|
|
312
319
|
}
|
|
@@ -316,9 +323,9 @@ eg.
|
|
|
316
323
|
|
|
317
324
|
`.transform()` is complicated because it technically comprises of two types (input & output). This means that we need to understand which type you are creating. If you are adding the ZodSchema directly to the `components` section, context is required with knowing to create an input schema or an output schema. You can do this by setting the `refType` field to `input` or `output` in `.openapi()`. This defaults to `output` by default.
|
|
318
325
|
|
|
319
|
-
|
|
326
|
+
If a registered schema with a transform is used in both a request and response schema you will receive an error because the created schema for each will be different. To override the creation type for a specific ZodEffect, add an `.openapi()` field and set the `effectType` field to `input`. This will force this library to always generate the input type even if we are creating a response type.
|
|
320
327
|
|
|
321
|
-
|
|
328
|
+
`.preprocess()` will always return the `output` type even if we are creating an input schema. If a different input type is required you can achieve this with a `.transform()` combined with a `.pipe()` or simply declare a manual `type` in `.openapi()`.
|
|
322
329
|
|
|
323
330
|
#### Parameters
|
|
324
331
|
|
|
@@ -393,7 +400,7 @@ For example in `z.string().nullable()` will be rendered differently
|
|
|
393
400
|
- ZodDiscriminatedUnion
|
|
394
401
|
- `discriminator` mapping when all schemas in the union contain a `ref`.
|
|
395
402
|
- ZodEffects
|
|
396
|
-
- `transform` support for request schemas.
|
|
403
|
+
- `transform` support for request schemas. See [Zod Effects](#zod-effects) for how to enable response schema support
|
|
397
404
|
- `pre-process` full support.
|
|
398
405
|
- `refine` full support.
|
|
399
406
|
- ZodEnum
|
|
@@ -417,6 +424,7 @@ For example in `z.string().nullable()` will be rendered differently
|
|
|
417
424
|
- `items` mapping for `.rest()`
|
|
418
425
|
- `prefixItems` mapping for OpenAPI 3.1.0+
|
|
419
426
|
- ZodUnion
|
|
427
|
+
- ZodUnknown
|
|
420
428
|
|
|
421
429
|
If this library cannot determine a type for a Zod Schema, it will throw an error. To avoid this, declare a manual `type` in the `.openapi()` section of that schema.
|
|
422
430
|
|
|
@@ -479,7 +487,7 @@ To release a new beta version
|
|
|
479
487
|
|
|
480
488
|
### [@asteasolutions/zod-to-openapi](https://github.com/asteasolutions/zod-to-openapi)
|
|
481
489
|
|
|
482
|
-
zod-openapi was created while trying to re-write
|
|
490
|
+
zod-openapi was created while trying to re-write this library to support auto registering schemas. However, the underlying structure of the library which consists of tightly coupled classes would not allow for this be done easily in a way that I envisioned. Did I really rewrite an entire library just for this? Absolutely. I believe that creating documentation should be as simple and as frictionless as possible.
|
|
483
491
|
|
|
484
492
|
#### Migration
|
|
485
493
|
|
|
@@ -509,21 +517,22 @@ registry.registerComponent('securitySchemes', 'auth', {
|
|
|
509
517
|
type: 'http',
|
|
510
518
|
scheme: 'bearer',
|
|
511
519
|
bearerFormat: 'JWT',
|
|
512
|
-
description: 'An auth token issued by oauth
|
|
520
|
+
description: 'An auth token issued by oauth',
|
|
513
521
|
});
|
|
514
522
|
// Replace with regular component declaration
|
|
515
523
|
|
|
516
524
|
const document = createDocument({
|
|
517
525
|
components: {
|
|
518
|
-
|
|
526
|
+
// declare directly in components
|
|
527
|
+
securitySchemes: {
|
|
519
528
|
auth: {
|
|
520
529
|
type: 'http',
|
|
521
530
|
scheme: 'bearer',
|
|
522
531
|
bearerFormat: 'JWT',
|
|
523
|
-
description: 'An auth token issued by oauth
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
532
|
+
description: 'An auth token issued by oauth',
|
|
533
|
+
},
|
|
534
|
+
},
|
|
535
|
+
},
|
|
527
536
|
});
|
|
528
537
|
```
|
|
529
538
|
|
|
@@ -538,6 +547,8 @@ registry.registerPath({
|
|
|
538
547
|
request: {
|
|
539
548
|
query: z.object({ a: z.string() }),
|
|
540
549
|
params: z.object({ b: z.string() }),
|
|
550
|
+
body: z.object({ c: z.string() }),
|
|
551
|
+
headers: z.object({ d: z.string() })
|
|
541
552
|
},
|
|
542
553
|
responses: {},
|
|
543
554
|
});
|
|
@@ -547,8 +558,10 @@ const getFoo: ZodOpenApiPathItemObject = {
|
|
|
547
558
|
get: {
|
|
548
559
|
requestParams: {
|
|
549
560
|
query: z.object({ a: z.string() }),
|
|
550
|
-
path: z.object({ b: z.string() }), //
|
|
561
|
+
path: z.object({ b: z.string() }), // params -> path
|
|
562
|
+
header: z.object({ c: z.string() }) // headers -> header
|
|
551
563
|
}, // renamed from request -> requestParams
|
|
564
|
+
requestBody: z.object({c: z.string() }) // request.body -> requestBody
|
|
552
565
|
responses: {},
|
|
553
566
|
},
|
|
554
567
|
};
|
|
@@ -5,7 +5,7 @@ const zod_1 = require("zod");
|
|
|
5
5
|
const metadata_1 = require("./schema/metadata");
|
|
6
6
|
const getDefaultComponents = (componentsObject, openapi = '3.1.0') => {
|
|
7
7
|
const defaultComponents = {
|
|
8
|
-
schemas:
|
|
8
|
+
schemas: new Map(),
|
|
9
9
|
parameters: {},
|
|
10
10
|
headers: {},
|
|
11
11
|
openapi,
|
|
@@ -24,26 +24,23 @@ const createSchemas = (schemas, components) => {
|
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
return Object.entries(schemas).forEach(([key, schema]) => {
|
|
27
|
-
const ref = schema instanceof zod_1.ZodType ? schema._def.openapi?.ref ?? key : key;
|
|
28
|
-
const component = components.schemas[key];
|
|
29
|
-
if (component) {
|
|
30
|
-
throw new Error(`schemaRef "${ref}" is already registered`);
|
|
31
|
-
}
|
|
32
27
|
if (schema instanceof zod_1.ZodType) {
|
|
28
|
+
const ref = schema._def.openapi?.ref ?? key;
|
|
29
|
+
const component = components.schemas.get(schema);
|
|
30
|
+
if (component) {
|
|
31
|
+
throw new Error(`schemaRef "${ref}" is already registered`);
|
|
32
|
+
}
|
|
33
33
|
const state = {
|
|
34
34
|
components,
|
|
35
35
|
type: schema._def.openapi?.refType ?? 'output',
|
|
36
36
|
};
|
|
37
|
-
components.schemas
|
|
37
|
+
components.schemas.set(schema, {
|
|
38
|
+
ref,
|
|
38
39
|
schemaObject: (0, metadata_1.createSchemaWithMetadata)(schema, state),
|
|
39
|
-
zodSchema: schema,
|
|
40
40
|
types: state.effectType ? [state.effectType] : ['input', 'output'],
|
|
41
|
-
};
|
|
41
|
+
});
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
|
-
components.schemas[ref] = {
|
|
45
|
-
schemaObject: schema,
|
|
46
|
-
};
|
|
47
44
|
});
|
|
48
45
|
};
|
|
49
46
|
const createParameters = (parameters, components) => {
|
|
@@ -77,25 +74,37 @@ const createHeaders = (headers, components) => {
|
|
|
77
74
|
const createComponentSchemaRef = (schemaRef) => `#/components/schemas/${schemaRef}`;
|
|
78
75
|
exports.createComponentSchemaRef = createComponentSchemaRef;
|
|
79
76
|
const createComponents = (componentsObject, components) => {
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
-
const
|
|
77
|
+
const combinedSchemas = createSchemaComponents(componentsObject, components.schemas);
|
|
78
|
+
const combinedParameters = createParamComponents(components.parameters);
|
|
79
|
+
const combinedHeaders = createHeaderComponents(components.headers);
|
|
80
|
+
const { schemas, parameters, headers, ...rest } = componentsObject;
|
|
83
81
|
const finalComponents = {
|
|
84
|
-
...
|
|
85
|
-
...(
|
|
86
|
-
...(
|
|
87
|
-
...(
|
|
82
|
+
...rest,
|
|
83
|
+
...(combinedSchemas && { schemas: combinedSchemas }),
|
|
84
|
+
...(combinedParameters && { parameters: combinedParameters }),
|
|
85
|
+
...(combinedHeaders && { headers: combinedHeaders }),
|
|
88
86
|
};
|
|
89
87
|
return Object.keys(finalComponents).length ? finalComponents : undefined;
|
|
90
88
|
};
|
|
91
89
|
exports.createComponents = createComponents;
|
|
92
|
-
const createSchemaComponents = (
|
|
93
|
-
const
|
|
94
|
-
if (value) {
|
|
95
|
-
acc
|
|
90
|
+
const createSchemaComponents = (componentsObject, componentMap) => {
|
|
91
|
+
const customComponents = Object.entries(componentsObject.schemas ?? {}).reduce((acc, [key, value]) => {
|
|
92
|
+
if (value instanceof zod_1.ZodType) {
|
|
93
|
+
return acc;
|
|
94
|
+
}
|
|
95
|
+
if (acc[key]) {
|
|
96
|
+
throw new Error(`Schema "${key}" is already registered`);
|
|
96
97
|
}
|
|
98
|
+
acc[key] = value;
|
|
97
99
|
return acc;
|
|
98
100
|
}, {});
|
|
101
|
+
const components = Array.from(componentMap).reduce((acc, [_zodType, value]) => {
|
|
102
|
+
if (acc[value.ref]) {
|
|
103
|
+
throw new Error(`Schema "${value.ref}" is already registered`);
|
|
104
|
+
}
|
|
105
|
+
acc[value.ref] = value.schemaObject;
|
|
106
|
+
return acc;
|
|
107
|
+
}, customComponents);
|
|
99
108
|
return Object.keys(components).length ? components : undefined;
|
|
100
109
|
};
|
|
101
110
|
const createParamComponents = (component) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/create/components.ts"],"names":[],"mappings":";;;AACA,6BAA8B;AAI9B,gDAA6D;
|
|
1
|
+
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/create/components.ts"],"names":[],"mappings":";;;AACA,6BAA8B;AAI9B,gDAA6D;AAiDtD,MAAM,oBAAoB,GAAG,CAClC,gBAGC,EACD,UAA6B,OAAO,EAClB,EAAE;IACpB,MAAM,iBAAiB,GAAqB;QAC1C,OAAO,EAAE,IAAI,GAAG,EAAE;QAClB,UAAU,EAAE,EAAE;QACd,OAAO,EAAE,EAAE;QACX,OAAO;KACR,CAAC;IACF,IAAI,CAAC,gBAAgB,EAAE;QACrB,OAAO,iBAAiB,CAAC;KAC1B;IAED,aAAa,CAAC,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAC3D,gBAAgB,CAAC,gBAAgB,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;IACjE,aAAa,CAAC,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAE3D,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAtBW,QAAA,oBAAoB,wBAsB/B;AAEF,MAAM,aAAa,GAAG,CACpB,OAA8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= require("./discriminatedUnion");
|
|
|
12
12
|
const enum_1 = require("./enum");
|
|
13
13
|
const intersection_1 = require("./intersection");
|
|
14
14
|
const literal_1 = require("./literal");
|
|
15
|
+
const manual_1 = require("./manual");
|
|
15
16
|
const metadata_1 = require("./metadata");
|
|
16
17
|
const nativeEnum_1 = require("./nativeEnum");
|
|
17
18
|
const null_1 = require("./null");
|
|
@@ -30,7 +31,7 @@ const union_1 = require("./union");
|
|
|
30
31
|
const unknown_1 = require("./unknown");
|
|
31
32
|
const createSchema = (zodSchema, state) => {
|
|
32
33
|
if (zodSchema._def.openapi?.type) {
|
|
33
|
-
return (0,
|
|
34
|
+
return (0, manual_1.createManualTypeSchema)(zodSchema);
|
|
34
35
|
}
|
|
35
36
|
if (zodSchema instanceof zod_1.ZodString) {
|
|
36
37
|
return (0, string_1.createStringSchema)(zodSchema);
|
|
@@ -107,22 +108,26 @@ const createSchema = (zodSchema, state) => {
|
|
|
107
108
|
if (zodSchema instanceof zod_1.ZodCatch) {
|
|
108
109
|
return (0, catch_1.createCatchSchema)(zodSchema, state);
|
|
109
110
|
}
|
|
110
|
-
|
|
111
|
+
if (zodSchema instanceof zod_1.ZodUnknown) {
|
|
112
|
+
return (0, unknown_1.createUnknownSchema)(zodSchema);
|
|
113
|
+
}
|
|
114
|
+
return (0, manual_1.createManualTypeSchema)(zodSchema);
|
|
111
115
|
};
|
|
112
116
|
exports.createSchema = createSchema;
|
|
113
|
-
const createRegisteredSchema = (zodSchema,
|
|
114
|
-
const component = state.components.schemas
|
|
117
|
+
const createRegisteredSchema = (zodSchema, state) => {
|
|
118
|
+
const component = state.components.schemas.get(zodSchema);
|
|
115
119
|
if (component) {
|
|
116
|
-
if (component.zodSchema !== zodSchema) {
|
|
117
|
-
throw new Error(`schemaRef "${schemaRef}" is already registered`);
|
|
118
|
-
}
|
|
119
120
|
if (!component.types?.includes(state.type)) {
|
|
120
|
-
throw new Error(`schemaRef "${
|
|
121
|
+
throw new Error(`schemaRef "${component.ref}" was created with a ZodTransform meaning that the input type is different from the output type. This type is currently being referenced in a response and request. Wrap it in a ZodPipeline, assign it a manual type or effectType`);
|
|
121
122
|
}
|
|
122
123
|
return {
|
|
123
|
-
$ref: (0, components_1.createComponentSchemaRef)(
|
|
124
|
+
$ref: (0, components_1.createComponentSchemaRef)(component.ref),
|
|
124
125
|
};
|
|
125
126
|
}
|
|
127
|
+
const schemaRef = zodSchema._def.openapi?.ref;
|
|
128
|
+
if (!schemaRef) {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
126
131
|
const newState = {
|
|
127
132
|
components: state.components,
|
|
128
133
|
type: state.type,
|
|
@@ -132,11 +137,11 @@ const createRegisteredSchema = (zodSchema, schemaRef, state) => {
|
|
|
132
137
|
if ('$ref' in schemaOrRef) {
|
|
133
138
|
throw new Error('Unexpected Error: received a reference object');
|
|
134
139
|
}
|
|
135
|
-
state.components.schemas
|
|
140
|
+
state.components.schemas.set(zodSchema, {
|
|
141
|
+
ref: schemaRef,
|
|
136
142
|
schemaObject: schemaOrRef,
|
|
137
|
-
zodSchema,
|
|
138
143
|
types: newState?.effectType ? [newState.effectType] : ['input', 'output'],
|
|
139
|
-
};
|
|
144
|
+
});
|
|
140
145
|
if (newState.effectType) {
|
|
141
146
|
state.effectType = newState.effectType;
|
|
142
147
|
}
|
|
@@ -146,9 +151,9 @@ const createRegisteredSchema = (zodSchema, schemaRef, state) => {
|
|
|
146
151
|
};
|
|
147
152
|
exports.createRegisteredSchema = createRegisteredSchema;
|
|
148
153
|
const createSchemaOrRef = (zodSchema, state) => {
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
151
|
-
return
|
|
154
|
+
const schema = (0, exports.createRegisteredSchema)(zodSchema, state);
|
|
155
|
+
if (schema) {
|
|
156
|
+
return schema;
|
|
152
157
|
}
|
|
153
158
|
return (0, metadata_1.createSchemaWithMetadata)(zodSchema, state);
|
|
154
159
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create/schema/index.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create/schema/index.ts"],"names":[],"mappings":";;;AACA,6BAyBa;AAEb,8CAIuB;AAEvB,mCAA4C;AAC5C,uCAAgD;AAChD,mCAA4C;AAC5C,iCAA0C;AAC1C,uCAAgD;AAChD,6DAAsE;AACtE,iCAA0C;AAC1C,iDAA0D;AAC1D,uCAAgD;AAChD,qCAAkD;AAClD,yCAAsD;AACtD,6CAAsD;AACtD,iCAA0C;AAC1C,yCAAkD;AAClD,qCAA8C;AAC9C,qCAA8C;AAC9C,yCAAkD;AAClD,yCAAkD;AAClD,6CAAsD;AACtD,qCAA8C;AAC9C,qCAA8C;AAC9C,qCAA8C;AAC9C,2CAAoD;AACpD,mCAA4C;AAC5C,mCAA4C;AAC5C,uCAAgD;AAQzC,MAAM,YAAY,GAAG,CAK1B,SAAsC,EACtC,KAAkB,EAC0B,EAAE;IAC9C,IAAI,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE;QAChC,OAAO,IAAA,+BAAsB,EAAC,SAAS,CAAC,CAAC;KAC1C;IAED,IAAI,SAAS,YAAY,eAAS,EAAE;QAClC,OAAO,IAAA,2BAAkB,EAAC,SAAS,CAAC,CAAC;KACtC;IAED,IAAI,SAAS,YAAY,eAAS,EAAE;QAClC,OAAO,IAAA,2BAAkB,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;KAC7C;IAED,IAAI,SAAS,YAAY,gBAAU,EAAE;QACnC,OAAO,IAAA,6BAAmB,EAAC,SAAS,CAAC,CAAC;KACvC;IAED,IAAI,SAAS,YAAY,aAAO,EAAE;QAChC,OAAO,IAAA,uBAAgB,EAAC,SAAS,CAAC,CAAC;KACpC;IAED,IAAI,SAAS,YAAY,gBAAU,EAAE;QACnC,OAAO,IAAA,6BAAmB,EAAC,SAAS,CAAC,CAAC;KACvC;IAED,IAAI,SAAS,YAAY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GAAG,CAK/B,SAAsC,EACtC,KAAkB,EAC0B,EAAE;IAC9C,MAAM,MAAM,GAAG,IAAA,8BAAsB,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACxD,IAAI,MAAM,EAAE;QACV,OAAO,MAAM,CAAC;KACf;IAED,OAAO,IAAA,mCAAwB,EAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AACpD,CAAC,CAAC;AAdW,QAAA,iBAAiB,qBAc5B"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createManualTypeSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const createManualTypeSchema = (zodSchema) => {
|
|
6
|
+
if (!zodSchema._def.openapi?.type) {
|
|
7
|
+
const zodType = zodSchema.constructor.name;
|
|
8
|
+
if (zodSchema instanceof zod_1.ZodEffects) {
|
|
9
|
+
const schemaName = `${zodType} - ${zodSchema._def.effect.type}`;
|
|
10
|
+
throw new Error(`Unknown schema ${schemaName}. Please assign it a manual 'type', wrap it in a ZodPipeline or change the 'effectType'.`);
|
|
11
|
+
}
|
|
12
|
+
throw new Error(`Unknown schema ${zodType}. Please assign it a manual 'type'.`);
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
type: zodSchema._def.openapi.type,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.createManualTypeSchema = createManualTypeSchema;
|
|
19
|
+
//# sourceMappingURL=manual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual.js","sourceRoot":"","sources":["../../../src/create/schema/manual.ts"],"names":[],"mappings":";;;AACA,6BAAsD;AAE/C,MAAM,sBAAsB,GAAG,CAKpC,SAAsC,EAClB,EAAE;IACtB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE;QACjC,MAAM,OAAO,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC;QAC3C,IAAI,SAAS,YAAY,gBAAU,EAAE;YACnC,MAAM,UAAU,GAAG,GAAG,OAAO,MAAM,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAChE,MAAM,IAAI,KAAK,CACb,kBAAkB,UAAU,0FAA0F,CACvH,CAAC;SACH;QACD,MAAM,IAAI,KAAK,CACb,kBAAkB,OAAO,qCAAqC,CAC/D,CAAC;KACH;IAED,OAAO;QACL,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI;KAClC,CAAC;AACJ,CAAC,CAAC;AAvBW,QAAA,sBAAsB,0BAuBjC"}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.enhanceWithMetadata = exports.createSchemaWithMetadata = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
const createSchemaWithMetadata = (zodSchema, state) => {
|
|
6
|
-
const {
|
|
6
|
+
const { effectType, param, header, ref, refType, ...additionalMetadata } = zodSchema._def.openapi ?? {};
|
|
7
7
|
const schemaOrRef = (0, _1.createSchema)(zodSchema, state);
|
|
8
8
|
const description = zodSchema.description;
|
|
9
9
|
return (0, exports.enhanceWithMetadata)(schemaOrRef, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/create/schema/metadata.ts"],"names":[],"mappings":";;;AAGA,wBAA8C;AAEvC,MAAM,wBAAwB,GAAG,CAKtC,SAAsC,EACtC,KAAkB,EAC0B,EAAE;IAC9C,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/create/schema/metadata.ts"],"names":[],"mappings":";;;AAGA,wBAA8C;AAEvC,MAAM,wBAAwB,GAAG,CAKtC,SAAsC,EACtC,KAAkB,EAC0B,EAAE;IAC9C,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,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C;AACJ,CAAC,CAAC;AA3BW,QAAA,mBAAmB,uBA2B9B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createTransformSchema = void 0;
|
|
4
|
-
const
|
|
4
|
+
const manual_1 = require("./manual");
|
|
5
5
|
const _1 = require(".");
|
|
6
6
|
const createTransformSchema = (zodTransform, state) => {
|
|
7
7
|
const creationType = zodTransform._def.openapi?.effectType ?? state.type;
|
|
@@ -11,7 +11,7 @@ const createTransformSchema = (zodTransform, state) => {
|
|
|
11
11
|
}
|
|
12
12
|
return (0, _1.createSchemaOrRef)(zodTransform._def.schema, state);
|
|
13
13
|
}
|
|
14
|
-
return (0,
|
|
14
|
+
return (0, manual_1.createManualTypeSchema)(zodTransform);
|
|
15
15
|
};
|
|
16
16
|
exports.createTransformSchema = createTransformSchema;
|
|
17
17
|
//# sourceMappingURL=transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/create/schema/transform.ts"],"names":[],"mappings":";;;AAGA,
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/create/schema/transform.ts"],"names":[],"mappings":";;;AAGA,qCAAkD;AAElD,wBAAmD;AAE5C,MAAM,qBAAqB,GAAG,CACnC,YAAuC,EACvC,KAAkB,EAC0B,EAAE;IAC9C,MAAM,YAAY,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,IAAI,KAAK,CAAC,IAAI,CAAC;IACzE,IAAI,YAAY,KAAK,OAAO,EAAE;QAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;YAC1B,KAAK,CAAC,UAAU,GAAG,OAAO,CAAC;SAC5B;QACD,OAAO,IAAA,oBAAiB,EAAC,YAAY,CAAC,IAAI,CAAC,MAAiB,EAAE,KAAK,CAAC,CAAC;KACtE;IAED,OAAO,IAAA,+BAAsB,EAAC,YAAY,CAAC,CAAC;AAC9C,CAAC,CAAC;AAbW,QAAA,qBAAqB,yBAahC"}
|
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createUnknownSchema = void 0;
|
|
4
|
-
const
|
|
5
|
-
const createUnknownSchema = (zodSchema) => {
|
|
6
|
-
if (!zodSchema._def.openapi?.type) {
|
|
7
|
-
const zodType = zodSchema.constructor.name;
|
|
8
|
-
if (zodSchema instanceof zod_1.ZodEffects) {
|
|
9
|
-
const schemaName = `${zodType} - ${zodSchema._def.effect.type}`;
|
|
10
|
-
throw new Error(`Unknown schema ${schemaName}. Please assign it a manual 'type', wrap it in a ZodPipeline or change the 'effectType'.`);
|
|
11
|
-
}
|
|
12
|
-
throw new Error(`Unknown schema ${zodType}. Please assign it a manual 'type'.`);
|
|
13
|
-
}
|
|
14
|
-
return {
|
|
15
|
-
type: zodSchema._def.openapi.type,
|
|
16
|
-
};
|
|
17
|
-
};
|
|
4
|
+
const createUnknownSchema = (_zodUnknown) => ({});
|
|
18
5
|
exports.createUnknownSchema = createUnknownSchema;
|
|
19
6
|
//# sourceMappingURL=unknown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../../src/create/schema/unknown.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../../src/create/schema/unknown.ts"],"names":[],"mappings":";;;AAGO,MAAM,mBAAmB,GAAG,CACjC,WAAuB,EACH,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AAFjB,QAAA,mBAAmB,uBAEF"}
|
|
@@ -2,7 +2,7 @@ import { ZodType } from 'zod';
|
|
|
2
2
|
import { createSchemaWithMetadata } from './schema/metadata';
|
|
3
3
|
export const getDefaultComponents = (componentsObject, openapi = '3.1.0') => {
|
|
4
4
|
const defaultComponents = {
|
|
5
|
-
schemas:
|
|
5
|
+
schemas: new Map(),
|
|
6
6
|
parameters: {},
|
|
7
7
|
headers: {},
|
|
8
8
|
openapi,
|
|
@@ -20,26 +20,23 @@ const createSchemas = (schemas, components) => {
|
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
return Object.entries(schemas).forEach(([key, schema]) => {
|
|
23
|
-
const ref = schema instanceof ZodType ? schema._def.openapi?.ref ?? key : key;
|
|
24
|
-
const component = components.schemas[key];
|
|
25
|
-
if (component) {
|
|
26
|
-
throw new Error(`schemaRef "${ref}" is already registered`);
|
|
27
|
-
}
|
|
28
23
|
if (schema instanceof ZodType) {
|
|
24
|
+
const ref = schema._def.openapi?.ref ?? key;
|
|
25
|
+
const component = components.schemas.get(schema);
|
|
26
|
+
if (component) {
|
|
27
|
+
throw new Error(`schemaRef "${ref}" is already registered`);
|
|
28
|
+
}
|
|
29
29
|
const state = {
|
|
30
30
|
components,
|
|
31
31
|
type: schema._def.openapi?.refType ?? 'output',
|
|
32
32
|
};
|
|
33
|
-
components.schemas
|
|
33
|
+
components.schemas.set(schema, {
|
|
34
|
+
ref,
|
|
34
35
|
schemaObject: createSchemaWithMetadata(schema, state),
|
|
35
|
-
zodSchema: schema,
|
|
36
36
|
types: state.effectType ? [state.effectType] : ['input', 'output'],
|
|
37
|
-
};
|
|
37
|
+
});
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
components.schemas[ref] = {
|
|
41
|
-
schemaObject: schema,
|
|
42
|
-
};
|
|
43
40
|
});
|
|
44
41
|
};
|
|
45
42
|
const createParameters = (parameters, components) => {
|
|
@@ -72,24 +69,36 @@ const createHeaders = (headers, components) => {
|
|
|
72
69
|
};
|
|
73
70
|
export const createComponentSchemaRef = (schemaRef) => `#/components/schemas/${schemaRef}`;
|
|
74
71
|
export const createComponents = (componentsObject, components) => {
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const
|
|
72
|
+
const combinedSchemas = createSchemaComponents(componentsObject, components.schemas);
|
|
73
|
+
const combinedParameters = createParamComponents(components.parameters);
|
|
74
|
+
const combinedHeaders = createHeaderComponents(components.headers);
|
|
75
|
+
const { schemas, parameters, headers, ...rest } = componentsObject;
|
|
78
76
|
const finalComponents = {
|
|
79
|
-
...
|
|
80
|
-
...(
|
|
81
|
-
...(
|
|
82
|
-
...(
|
|
77
|
+
...rest,
|
|
78
|
+
...(combinedSchemas && { schemas: combinedSchemas }),
|
|
79
|
+
...(combinedParameters && { parameters: combinedParameters }),
|
|
80
|
+
...(combinedHeaders && { headers: combinedHeaders }),
|
|
83
81
|
};
|
|
84
82
|
return Object.keys(finalComponents).length ? finalComponents : undefined;
|
|
85
83
|
};
|
|
86
|
-
const createSchemaComponents = (
|
|
87
|
-
const
|
|
88
|
-
if (value) {
|
|
89
|
-
acc
|
|
84
|
+
const createSchemaComponents = (componentsObject, componentMap) => {
|
|
85
|
+
const customComponents = Object.entries(componentsObject.schemas ?? {}).reduce((acc, [key, value]) => {
|
|
86
|
+
if (value instanceof ZodType) {
|
|
87
|
+
return acc;
|
|
88
|
+
}
|
|
89
|
+
if (acc[key]) {
|
|
90
|
+
throw new Error(`Schema "${key}" is already registered`);
|
|
90
91
|
}
|
|
92
|
+
acc[key] = value;
|
|
91
93
|
return acc;
|
|
92
94
|
}, {});
|
|
95
|
+
const components = Array.from(componentMap).reduce((acc, [_zodType, value]) => {
|
|
96
|
+
if (acc[value.ref]) {
|
|
97
|
+
throw new Error(`Schema "${value.ref}" is already registered`);
|
|
98
|
+
}
|
|
99
|
+
acc[value.ref] = value.schemaObject;
|
|
100
|
+
return acc;
|
|
101
|
+
}, customComponents);
|
|
93
102
|
return Object.keys(components).length ? components : undefined;
|
|
94
103
|
};
|
|
95
104
|
const createParamComponents = (component) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sourceRoot":"","sources":["../../src/create/components.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,KAA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,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,WAAoC,CAAC;SACvD;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;AACjE,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAC7B,SAAiC,EACE,EAAE;IACrC,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAEjD,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE;QACtB,IAAI,KAAK,EAAE;YACT,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,YAAkC,CAAC;SACrD;QACD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;AACjE,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ZodArray, ZodBoolean, ZodCatch, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodEffects, ZodEnum, ZodIntersection, ZodLiteral, ZodNativeEnum, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodPipeline, ZodRecord, ZodString, ZodTuple, ZodUnion, } from 'zod';
|
|
1
|
+
import { ZodArray, ZodBoolean, ZodCatch, ZodDate, ZodDefault, ZodDiscriminatedUnion, ZodEffects, ZodEnum, ZodIntersection, ZodLiteral, ZodNativeEnum, ZodNull, ZodNullable, ZodNumber, ZodObject, ZodOptional, ZodPipeline, ZodRecord, ZodString, ZodTuple, ZodUnion, ZodUnknown, } from 'zod';
|
|
2
2
|
import { createComponentSchemaRef, } from '../components';
|
|
3
3
|
import { createArraySchema } from './array';
|
|
4
4
|
import { createBooleanSchema } from './boolean';
|
|
@@ -9,6 +9,7 @@ import { createDiscriminatedUnionSchema } from './discriminatedUnion';
|
|
|
9
9
|
import { createEnumSchema } from './enum';
|
|
10
10
|
import { createIntersectionSchema } from './intersection';
|
|
11
11
|
import { createLiteralSchema } from './literal';
|
|
12
|
+
import { createManualTypeSchema } from './manual';
|
|
12
13
|
import { createSchemaWithMetadata } from './metadata';
|
|
13
14
|
import { createNativeEnumSchema } from './nativeEnum';
|
|
14
15
|
import { createNullSchema } from './null';
|
|
@@ -27,7 +28,7 @@ import { createUnionSchema } from './union';
|
|
|
27
28
|
import { createUnknownSchema } from './unknown';
|
|
28
29
|
export const createSchema = (zodSchema, state) => {
|
|
29
30
|
if (zodSchema._def.openapi?.type) {
|
|
30
|
-
return
|
|
31
|
+
return createManualTypeSchema(zodSchema);
|
|
31
32
|
}
|
|
32
33
|
if (zodSchema instanceof ZodString) {
|
|
33
34
|
return createStringSchema(zodSchema);
|
|
@@ -104,21 +105,25 @@ export const createSchema = (zodSchema, state) => {
|
|
|
104
105
|
if (zodSchema instanceof ZodCatch) {
|
|
105
106
|
return createCatchSchema(zodSchema, state);
|
|
106
107
|
}
|
|
107
|
-
|
|
108
|
+
if (zodSchema instanceof ZodUnknown) {
|
|
109
|
+
return createUnknownSchema(zodSchema);
|
|
110
|
+
}
|
|
111
|
+
return createManualTypeSchema(zodSchema);
|
|
108
112
|
};
|
|
109
|
-
export const createRegisteredSchema = (zodSchema,
|
|
110
|
-
const component = state.components.schemas
|
|
113
|
+
export const createRegisteredSchema = (zodSchema, state) => {
|
|
114
|
+
const component = state.components.schemas.get(zodSchema);
|
|
111
115
|
if (component) {
|
|
112
|
-
if (component.zodSchema !== zodSchema) {
|
|
113
|
-
throw new Error(`schemaRef "${schemaRef}" is already registered`);
|
|
114
|
-
}
|
|
115
116
|
if (!component.types?.includes(state.type)) {
|
|
116
|
-
throw new Error(`schemaRef "${
|
|
117
|
+
throw new Error(`schemaRef "${component.ref}" was created with a ZodTransform meaning that the input type is different from the output type. This type is currently being referenced in a response and request. Wrap it in a ZodPipeline, assign it a manual type or effectType`);
|
|
117
118
|
}
|
|
118
119
|
return {
|
|
119
|
-
$ref: createComponentSchemaRef(
|
|
120
|
+
$ref: createComponentSchemaRef(component.ref),
|
|
120
121
|
};
|
|
121
122
|
}
|
|
123
|
+
const schemaRef = zodSchema._def.openapi?.ref;
|
|
124
|
+
if (!schemaRef) {
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
122
127
|
const newState = {
|
|
123
128
|
components: state.components,
|
|
124
129
|
type: state.type,
|
|
@@ -128,11 +133,11 @@ export const createRegisteredSchema = (zodSchema, schemaRef, state) => {
|
|
|
128
133
|
if ('$ref' in schemaOrRef) {
|
|
129
134
|
throw new Error('Unexpected Error: received a reference object');
|
|
130
135
|
}
|
|
131
|
-
state.components.schemas
|
|
136
|
+
state.components.schemas.set(zodSchema, {
|
|
137
|
+
ref: schemaRef,
|
|
132
138
|
schemaObject: schemaOrRef,
|
|
133
|
-
zodSchema,
|
|
134
139
|
types: newState?.effectType ? [newState.effectType] : ['input', 'output'],
|
|
135
|
-
};
|
|
140
|
+
});
|
|
136
141
|
if (newState.effectType) {
|
|
137
142
|
state.effectType = newState.effectType;
|
|
138
143
|
}
|
|
@@ -141,9 +146,9 @@ export const createRegisteredSchema = (zodSchema, schemaRef, state) => {
|
|
|
141
146
|
};
|
|
142
147
|
};
|
|
143
148
|
export const createSchemaOrRef = (zodSchema, state) => {
|
|
144
|
-
const
|
|
145
|
-
if (
|
|
146
|
-
return
|
|
149
|
+
const schema = createRegisteredSchema(zodSchema, state);
|
|
150
|
+
if (schema) {
|
|
151
|
+
return schema;
|
|
147
152
|
}
|
|
148
153
|
return createSchemaWithMetadata(zodSchema, state);
|
|
149
154
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create/schema/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,OAAO,EACP,UAAU,EACV,qBAAqB,EACrB,UAAU,EACV,OAAO,EACP,eAAe,EACf,UAAU,EACV,aAAa,EACb,OAAO,EACP,WAAW,EACX,SAAS,EACT,SAAS,EACT,WAAW,EACX,WAAW,EACX,SAAS,EACT,SAAS,EACT,QAAQ,EAGR,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/create/schema/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,OAAO,EACP,UAAU,EACV,qBAAqB,EACrB,UAAU,EACV,OAAO,EACP,eAAe,EACf,UAAU,EACV,aAAa,EACb,OAAO,EACP,WAAW,EACX,SAAS,EACT,SAAS,EACT,WAAW,EACX,WAAW,EACX,SAAS,EACT,SAAS,EACT,QAAQ,EAGR,QAAQ,EACR,UAAU,GACX,MAAM,KAAK,CAAC;AAEb,OAAO,EAGL,wBAAwB,GACzB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,8BAA8B,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD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K/B,SAAsC,EACtC,KAAkB,EAC0B,EAAE;IAC9C,MAAM,MAAM,GAAG,sBAAsB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACxD,IAAI,MAAM,EAAE;QACV,OAAO,MAAM,CAAC;KACf;IAED,OAAO,wBAAwB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;AACpD,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ZodEffects } from 'zod';
|
|
2
|
+
export const createManualTypeSchema = (zodSchema) => {
|
|
3
|
+
if (!zodSchema._def.openapi?.type) {
|
|
4
|
+
const zodType = zodSchema.constructor.name;
|
|
5
|
+
if (zodSchema instanceof ZodEffects) {
|
|
6
|
+
const schemaName = `${zodType} - ${zodSchema._def.effect.type}`;
|
|
7
|
+
throw new Error(`Unknown schema ${schemaName}. Please assign it a manual 'type', wrap it in a ZodPipeline or change the 'effectType'.`);
|
|
8
|
+
}
|
|
9
|
+
throw new Error(`Unknown schema ${zodType}. Please assign it a manual 'type'.`);
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
type: zodSchema._def.openapi.type,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=manual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manual.js","sourceRoot":"","sources":["../../../src/create/schema/manual.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAuB,MAAM,KAAK,CAAC;AAEtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAKpC,SAAsC,EAClB,EAAE;IACtB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE;QACjC,MAAM,OAAO,GAAG,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC;QAC3C,IAAI,SAAS,YAAY,UAAU,EAAE;YACnC,MAAM,UAAU,GAAG,GAAG,OAAO,MAAM,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAChE,MAAM,IAAI,KAAK,CACb,kBAAkB,UAAU,0FAA0F,CACvH,CAAC;SACH;QACD,MAAM,IAAI,KAAK,CACb,kBAAkB,OAAO,qCAAqC,CAC/D,CAAC;KACH;IAED,OAAO;QACL,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI;KAClC,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createSchema } from '.';
|
|
2
2
|
export const createSchemaWithMetadata = (zodSchema, state) => {
|
|
3
|
-
const {
|
|
3
|
+
const { effectType, param, header, ref, refType, ...additionalMetadata } = zodSchema._def.openapi ?? {};
|
|
4
4
|
const schemaOrRef = createSchema(zodSchema, state);
|
|
5
5
|
const description = zodSchema.description;
|
|
6
6
|
return enhanceWithMetadata(schemaOrRef, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/create/schema/metadata.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,YAAY,EAAE,MAAM,GAAG,CAAC;AAE9C,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAKtC,SAAsC,EACtC,KAAkB,EAC0B,EAAE;IAC9C,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../../src/create/schema/metadata.ts"],"names":[],"mappings":"AAGA,OAAO,EAAe,YAAY,EAAE,MAAM,GAAG,CAAC;AAE9C,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAKtC,SAAsC,EACtC,KAAkB,EAC0B,EAAE;IAC9C,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,kBAAkB,EAAE,GACtE,SAAS,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;IAC/B,MAAM,WAAW,GAAG,YAAY,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACnD,MAAM,WAAW,GAAG,SAAS,CAAC,WAAW,CAAC;IAE1C,OAAO,mBAAmB,CAAC,WAAW,EAAE;QACtC,GAAG,CAAC,WAAW,IAAI,EAAE,WAAW,EAAE,CAAC;QACnC,GAAG,kBAAkB;KACtB,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,WAAuD,EACvD,QAAoD,EACR,EAAE;IAC9C,IAAI,MAAM,IAAI,WAAW,EAAE;QACzB,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,SAAS,CAAC,EAAE;YAC7D,OAAO,WAAW,CAAC;SACpB;QAED,OAAO;YACL,KAAK,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;SAC/B,CAAC;KACH;IAED,IAAI,WAAW,CAAC,KAAK,EAAE;QACrB,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC5C,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACrC,OAAO;YACL,GAAG,WAAW;YACd,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;SACvE,CAAC;KACH;IAED,OAAO;QACL,GAAG,WAAW;QACd,GAAG,QAAQ;KACZ,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createManualTypeSchema } from './manual';
|
|
2
2
|
import { createSchemaOrRef } from '.';
|
|
3
3
|
export const createTransformSchema = (zodTransform, state) => {
|
|
4
4
|
const creationType = zodTransform._def.openapi?.effectType ?? state.type;
|
|
@@ -8,6 +8,6 @@ export const createTransformSchema = (zodTransform, state) => {
|
|
|
8
8
|
}
|
|
9
9
|
return createSchemaOrRef(zodTransform._def.schema, state);
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return createManualTypeSchema(zodTransform);
|
|
12
12
|
};
|
|
13
13
|
//# sourceMappingURL=transform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/create/schema/transform.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../../../src/create/schema/transform.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAElD,OAAO,EAAe,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEnD,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,YAAuC,EACvC,KAAkB,EAC0B,EAAE;IAC9C,MAAM,YAAY,GAAG,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,IAAI,KAAK,CAAC,IAAI,CAAC;IACzE,IAAI,YAAY,KAAK,OAAO,EAAE;QAC5B,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;YAC1B,KAAK,CAAC,UAAU,GAAG,OAAO,CAAC;SAC5B;QACD,OAAO,iBAAiB,CAAC,YAAY,CAAC,IAAI,CAAC,MAAiB,EAAE,KAAK,CAAC,CAAC;KACtE;IAED,OAAO,sBAAsB,CAAC,YAAY,CAAC,CAAC;AAC9C,CAAC,CAAC"}
|
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export const createUnknownSchema = (zodSchema) => {
|
|
3
|
-
if (!zodSchema._def.openapi?.type) {
|
|
4
|
-
const zodType = zodSchema.constructor.name;
|
|
5
|
-
if (zodSchema instanceof ZodEffects) {
|
|
6
|
-
const schemaName = `${zodType} - ${zodSchema._def.effect.type}`;
|
|
7
|
-
throw new Error(`Unknown schema ${schemaName}. Please assign it a manual 'type', wrap it in a ZodPipeline or change the 'effectType'.`);
|
|
8
|
-
}
|
|
9
|
-
throw new Error(`Unknown schema ${zodType}. Please assign it a manual 'type'.`);
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
type: zodSchema._def.openapi.type,
|
|
13
|
-
};
|
|
14
|
-
};
|
|
1
|
+
export const createUnknownSchema = (_zodUnknown) => ({});
|
|
15
2
|
//# sourceMappingURL=unknown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../../src/create/schema/unknown.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unknown.js","sourceRoot":"","sources":["../../../src/create/schema/unknown.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,WAAuB,EACH,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC"}
|
|
@@ -3,13 +3,11 @@ import { ZodType } from 'zod';
|
|
|
3
3
|
import { ZodOpenApiComponentsObject, ZodOpenApiVersion } from './document';
|
|
4
4
|
export type CreationType = 'input' | 'output';
|
|
5
5
|
export interface SchemaComponent {
|
|
6
|
-
|
|
6
|
+
ref: string;
|
|
7
7
|
schemaObject: oas31.SchemaObject | oas31.ReferenceObject | oas30.SchemaObject | oas30.ReferenceObject;
|
|
8
|
-
types
|
|
9
|
-
}
|
|
10
|
-
interface SchemaComponentObject {
|
|
11
|
-
[ref: string]: SchemaComponent | undefined;
|
|
8
|
+
types: [CreationType, ...CreationType[]];
|
|
12
9
|
}
|
|
10
|
+
export type SchemaComponentMap = Map<ZodType, SchemaComponent>;
|
|
13
11
|
export interface ParameterComponent {
|
|
14
12
|
zodSchema?: ZodType;
|
|
15
13
|
paramObject: oas31.ParameterObject | oas31.ReferenceObject | oas30.ParameterObject | oas30.ReferenceObject;
|
|
@@ -25,12 +23,12 @@ interface HeadersComponentObject {
|
|
|
25
23
|
[ref: string]: Header | undefined;
|
|
26
24
|
}
|
|
27
25
|
export interface ComponentsObject {
|
|
28
|
-
schemas:
|
|
26
|
+
schemas: SchemaComponentMap;
|
|
29
27
|
parameters: ParametersComponentObject;
|
|
30
28
|
headers: HeadersComponentObject;
|
|
31
29
|
openapi: ZodOpenApiVersion;
|
|
32
30
|
}
|
|
33
31
|
export declare const getDefaultComponents: (componentsObject?: Pick<ZodOpenApiComponentsObject, 'schemas' | 'parameters' | 'headers'>, openapi?: ZodOpenApiVersion) => ComponentsObject;
|
|
34
32
|
export declare const createComponentSchemaRef: (schemaRef: string) => string;
|
|
35
|
-
export declare const createComponents: (componentsObject:
|
|
33
|
+
export declare const createComponents: (componentsObject: ZodOpenApiComponentsObject, components: ComponentsObject) => oas31.ComponentsObject | undefined;
|
|
36
34
|
export {};
|
|
@@ -7,5 +7,5 @@ export interface SchemaState {
|
|
|
7
7
|
effectType?: CreationType;
|
|
8
8
|
}
|
|
9
9
|
export declare const createSchema: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
10
|
-
export declare const createRegisteredSchema: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>,
|
|
10
|
+
export declare const createRegisteredSchema: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => oas31.ReferenceObject | undefined;
|
|
11
11
|
export declare const createSchemaOrRef: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, state: SchemaState) => oas31.SchemaObject | oas31.ReferenceObject;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { oas31 } from 'openapi3-ts';
|
|
2
|
-
import {
|
|
3
|
-
export declare const createUnknownSchema:
|
|
2
|
+
import { ZodUnknown } from 'zod';
|
|
3
|
+
export declare const createUnknownSchema: (_zodUnknown: ZodUnknown) => oas31.SchemaObject;
|