zod-openapi 4.1.2 → 4.2.1
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 +1 -1
- package/dist/api.cjs +1 -0
- package/dist/api.d.mts +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.mjs +3 -2
- package/dist/components.chunk.cjs +32 -8
- package/dist/components.chunk.mjs +33 -9
- package/dist/create/parameters.d.ts +4 -3
- package/dist/extend.cjs +4 -0
- package/dist/extend.d.mts +1 -1
- package/dist/extend.d.ts +1 -1
- package/dist/extend.mjs +5 -0
- package/dist/extendZod.chunk.cjs +12 -11
- package/dist/extendZod.chunk.mjs +12 -11
- package/dist/extendZod.d.ts +0 -1
- package/dist/extendZodTypes.chunk.cjs +5 -0
- package/dist/extendZodTypes.chunk.mjs +6 -0
- package/dist/extendZodTypes.d.ts +6 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -805,7 +805,7 @@ As an example `z.string().nullable()` will be rendered differently
|
|
|
805
805
|
- ZodSet
|
|
806
806
|
- Treated as an array with `uniqueItems` (you may need to add a pre-process to convert it to a set)
|
|
807
807
|
- ZodString
|
|
808
|
-
- `format` mapping for `.url()`, `.uuid()`, `.email()`, `.datetime()`, `.date()`, `.time()`, `.duration()`
|
|
808
|
+
- `format` mapping for `.url()`, `.uuid()`, `.email()`, `.datetime()`, `.date()`, `.time()`, `.duration()`, `.ip({ version: 'v4' })`, `.ip({ version: 'v6' })`, `.cidr({ version: 'v4' })`, `.cidr({ version: 'v6' })`
|
|
809
809
|
- `minLength`/`maxLength` mapping for `.length()`, `.min()`, `.max()`
|
|
810
810
|
- `pattern` mapping for `.regex()`, `.startsWith()`, `.endsWith()`, `.includes()`
|
|
811
811
|
- `contentEncoding` mapping for `.base64()` for OpenAPI 3.1.0+
|
package/dist/api.cjs
CHANGED
|
@@ -5,3 +5,4 @@ exports.createComponents = components.createComponents;
|
|
|
5
5
|
exports.createMediaTypeSchema = components.createMediaTypeSchema;
|
|
6
6
|
exports.createParamOrRef = components.createParamOrRef;
|
|
7
7
|
exports.getDefaultComponents = components.getDefaultComponents;
|
|
8
|
+
exports.getZodObject = components.getZodObject;
|
package/dist/api.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ComponentsObject, createComponents, getDefaultComponents } from './create/components.js';
|
|
2
2
|
export { createMediaTypeSchema } from './create/content.js';
|
|
3
|
-
export { createParamOrRef } from './create/parameters.js';
|
|
3
|
+
export { createParamOrRef, getZodObject } from './create/parameters.js';
|
package/dist/api.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { ComponentsObject, createComponents, getDefaultComponents } from './create/components.js';
|
|
2
2
|
export { createMediaTypeSchema } from './create/content.js';
|
|
3
|
-
export { createParamOrRef } from './create/parameters.js';
|
|
3
|
+
export { createParamOrRef, getZodObject } from './create/parameters.js';
|
package/dist/api.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { createComponents, createMediaTypeSchema, createParamOrRef, getDefaultComponents } from "./components.chunk.mjs";
|
|
1
|
+
import { createComponents, createMediaTypeSchema, createParamOrRef, getDefaultComponents, getZodObject } from "./components.chunk.mjs";
|
|
2
2
|
export {
|
|
3
3
|
createComponents,
|
|
4
4
|
createMediaTypeSchema,
|
|
5
5
|
createParamOrRef,
|
|
6
|
-
getDefaultComponents
|
|
6
|
+
getDefaultComponents,
|
|
7
|
+
getZodObject
|
|
7
8
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
const extendZodTypes = require("./extendZodTypes.chunk.cjs");
|
|
2
3
|
const isZodType = (zodType, typeName) => {
|
|
3
4
|
var _a;
|
|
4
5
|
return ((_a = zodType == null ? void 0 : zodType._def) == null ? void 0 : _a.typeName) === typeName;
|
|
@@ -1161,6 +1162,7 @@ const mapIncludes = (zodStringChecks) => {
|
|
|
1161
1162
|
});
|
|
1162
1163
|
};
|
|
1163
1164
|
const mapStringFormat = (zodStringChecks) => {
|
|
1165
|
+
var _a, _b, _c, _d;
|
|
1164
1166
|
if (zodStringChecks.uuid) {
|
|
1165
1167
|
return "uuid";
|
|
1166
1168
|
}
|
|
@@ -1182,6 +1184,18 @@ const mapStringFormat = (zodStringChecks) => {
|
|
|
1182
1184
|
if (zodStringChecks.url) {
|
|
1183
1185
|
return "uri";
|
|
1184
1186
|
}
|
|
1187
|
+
if ((_a = zodStringChecks.ip) == null ? void 0 : _a.every((ip) => ip.version === "v4")) {
|
|
1188
|
+
return "ipv4";
|
|
1189
|
+
}
|
|
1190
|
+
if ((_b = zodStringChecks.ip) == null ? void 0 : _b.every((ip) => ip.version === "v6")) {
|
|
1191
|
+
return "ipv6";
|
|
1192
|
+
}
|
|
1193
|
+
if ((_c = zodStringChecks.cidr) == null ? void 0 : _c.every((ip) => ip.version === "v4")) {
|
|
1194
|
+
return "ipv4";
|
|
1195
|
+
}
|
|
1196
|
+
if ((_d = zodStringChecks.cidr) == null ? void 0 : _d.every((ip) => ip.version === "v6")) {
|
|
1197
|
+
return "ipv6";
|
|
1198
|
+
}
|
|
1185
1199
|
return void 0;
|
|
1186
1200
|
};
|
|
1187
1201
|
const mapContentEncoding = (zodStringChecks) => {
|
|
@@ -1525,8 +1539,16 @@ const createSchemaOrRef = (zodSchema, state, onlyRef) => {
|
|
|
1525
1539
|
if (existingRef) {
|
|
1526
1540
|
return existingRef;
|
|
1527
1541
|
}
|
|
1528
|
-
const previous = ((_a = zodSchema._def.zodOpenApi) == null ? void 0 : _a.
|
|
1529
|
-
|
|
1542
|
+
const previous = ((_a = zodSchema._def.zodOpenApi) == null ? void 0 : _a[extendZodTypes.previousSymbol]) ? createSchemaOrRef(
|
|
1543
|
+
zodSchema._def.zodOpenApi[extendZodTypes.previousSymbol],
|
|
1544
|
+
state,
|
|
1545
|
+
true
|
|
1546
|
+
) : void 0;
|
|
1547
|
+
const current = ((_b = zodSchema._def.zodOpenApi) == null ? void 0 : _b[extendZodTypes.currentSymbol]) && zodSchema._def.zodOpenApi[extendZodTypes.currentSymbol] !== zodSchema ? createSchemaOrRef(
|
|
1548
|
+
zodSchema._def.zodOpenApi[extendZodTypes.currentSymbol],
|
|
1549
|
+
state,
|
|
1550
|
+
true
|
|
1551
|
+
) : void 0;
|
|
1530
1552
|
const ref = ((_d = (_c = zodSchema._def.zodOpenApi) == null ? void 0 : _c.openapi) == null ? void 0 : _d.ref) ?? (component == null ? void 0 : component.ref);
|
|
1531
1553
|
if (ref) {
|
|
1532
1554
|
return current ? createNewSchema({ zodSchema, previous: current, state }) : createNewRef({ ref, zodSchema, previous, state });
|
|
@@ -1675,7 +1697,7 @@ const createParameters = (type, zodObjectType, components, subpath, documentOpti
|
|
|
1675
1697
|
if (!zodObjectType) {
|
|
1676
1698
|
return [];
|
|
1677
1699
|
}
|
|
1678
|
-
const zodObject = getZodObject(zodObjectType).shape;
|
|
1700
|
+
const zodObject = getZodObject(zodObjectType, "input").shape;
|
|
1679
1701
|
return Object.entries(zodObject).map(
|
|
1680
1702
|
([key, zodSchema]) => createParamOrRef(
|
|
1681
1703
|
zodSchema,
|
|
@@ -1758,18 +1780,19 @@ const getZodObject = (schema, type) => {
|
|
|
1758
1780
|
return schema;
|
|
1759
1781
|
}
|
|
1760
1782
|
if (isZodType(schema, "ZodLazy")) {
|
|
1761
|
-
return getZodObject(schema.schema);
|
|
1783
|
+
return getZodObject(schema.schema, type);
|
|
1762
1784
|
}
|
|
1763
1785
|
if (isZodType(schema, "ZodEffects")) {
|
|
1764
|
-
return getZodObject(schema.innerType());
|
|
1786
|
+
return getZodObject(schema.innerType(), type);
|
|
1765
1787
|
}
|
|
1766
1788
|
if (isZodType(schema, "ZodBranded")) {
|
|
1767
|
-
return getZodObject(schema.unwrap());
|
|
1789
|
+
return getZodObject(schema.unwrap(), type);
|
|
1768
1790
|
}
|
|
1769
1791
|
if (isZodType(schema, "ZodPipeline")) {
|
|
1770
|
-
{
|
|
1771
|
-
return getZodObject(schema._def.in);
|
|
1792
|
+
if (type === "input") {
|
|
1793
|
+
return getZodObject(schema._def.in, type);
|
|
1772
1794
|
}
|
|
1795
|
+
return getZodObject(schema._def.out, type);
|
|
1773
1796
|
}
|
|
1774
1797
|
throw new Error("failed to find ZodObject in schema");
|
|
1775
1798
|
};
|
|
@@ -2408,3 +2431,4 @@ exports.createPaths = createPaths;
|
|
|
2408
2431
|
exports.createSchema = createSchema;
|
|
2409
2432
|
exports.createSchemaComponents = createSchemaComponents;
|
|
2410
2433
|
exports.getDefaultComponents = getDefaultComponents;
|
|
2434
|
+
exports.getZodObject = getZodObject;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { previousSymbol, currentSymbol } from "./extendZodTypes.chunk.mjs";
|
|
1
2
|
const isZodType = (zodType, typeName) => {
|
|
2
3
|
var _a;
|
|
3
4
|
return ((_a = zodType == null ? void 0 : zodType._def) == null ? void 0 : _a.typeName) === typeName;
|
|
@@ -1160,6 +1161,7 @@ const mapIncludes = (zodStringChecks) => {
|
|
|
1160
1161
|
});
|
|
1161
1162
|
};
|
|
1162
1163
|
const mapStringFormat = (zodStringChecks) => {
|
|
1164
|
+
var _a, _b, _c, _d;
|
|
1163
1165
|
if (zodStringChecks.uuid) {
|
|
1164
1166
|
return "uuid";
|
|
1165
1167
|
}
|
|
@@ -1181,6 +1183,18 @@ const mapStringFormat = (zodStringChecks) => {
|
|
|
1181
1183
|
if (zodStringChecks.url) {
|
|
1182
1184
|
return "uri";
|
|
1183
1185
|
}
|
|
1186
|
+
if ((_a = zodStringChecks.ip) == null ? void 0 : _a.every((ip) => ip.version === "v4")) {
|
|
1187
|
+
return "ipv4";
|
|
1188
|
+
}
|
|
1189
|
+
if ((_b = zodStringChecks.ip) == null ? void 0 : _b.every((ip) => ip.version === "v6")) {
|
|
1190
|
+
return "ipv6";
|
|
1191
|
+
}
|
|
1192
|
+
if ((_c = zodStringChecks.cidr) == null ? void 0 : _c.every((ip) => ip.version === "v4")) {
|
|
1193
|
+
return "ipv4";
|
|
1194
|
+
}
|
|
1195
|
+
if ((_d = zodStringChecks.cidr) == null ? void 0 : _d.every((ip) => ip.version === "v6")) {
|
|
1196
|
+
return "ipv6";
|
|
1197
|
+
}
|
|
1184
1198
|
return void 0;
|
|
1185
1199
|
};
|
|
1186
1200
|
const mapContentEncoding = (zodStringChecks) => {
|
|
@@ -1524,8 +1538,16 @@ const createSchemaOrRef = (zodSchema, state, onlyRef) => {
|
|
|
1524
1538
|
if (existingRef) {
|
|
1525
1539
|
return existingRef;
|
|
1526
1540
|
}
|
|
1527
|
-
const previous = ((_a = zodSchema._def.zodOpenApi) == null ? void 0 : _a
|
|
1528
|
-
|
|
1541
|
+
const previous = ((_a = zodSchema._def.zodOpenApi) == null ? void 0 : _a[previousSymbol]) ? createSchemaOrRef(
|
|
1542
|
+
zodSchema._def.zodOpenApi[previousSymbol],
|
|
1543
|
+
state,
|
|
1544
|
+
true
|
|
1545
|
+
) : void 0;
|
|
1546
|
+
const current = ((_b = zodSchema._def.zodOpenApi) == null ? void 0 : _b[currentSymbol]) && zodSchema._def.zodOpenApi[currentSymbol] !== zodSchema ? createSchemaOrRef(
|
|
1547
|
+
zodSchema._def.zodOpenApi[currentSymbol],
|
|
1548
|
+
state,
|
|
1549
|
+
true
|
|
1550
|
+
) : void 0;
|
|
1529
1551
|
const ref = ((_d = (_c = zodSchema._def.zodOpenApi) == null ? void 0 : _c.openapi) == null ? void 0 : _d.ref) ?? (component == null ? void 0 : component.ref);
|
|
1530
1552
|
if (ref) {
|
|
1531
1553
|
return current ? createNewSchema({ zodSchema, previous: current, state }) : createNewRef({ ref, zodSchema, previous, state });
|
|
@@ -1674,7 +1696,7 @@ const createParameters = (type, zodObjectType, components, subpath, documentOpti
|
|
|
1674
1696
|
if (!zodObjectType) {
|
|
1675
1697
|
return [];
|
|
1676
1698
|
}
|
|
1677
|
-
const zodObject = getZodObject(zodObjectType).shape;
|
|
1699
|
+
const zodObject = getZodObject(zodObjectType, "input").shape;
|
|
1678
1700
|
return Object.entries(zodObject).map(
|
|
1679
1701
|
([key, zodSchema]) => createParamOrRef(
|
|
1680
1702
|
zodSchema,
|
|
@@ -1757,18 +1779,19 @@ const getZodObject = (schema, type) => {
|
|
|
1757
1779
|
return schema;
|
|
1758
1780
|
}
|
|
1759
1781
|
if (isZodType(schema, "ZodLazy")) {
|
|
1760
|
-
return getZodObject(schema.schema);
|
|
1782
|
+
return getZodObject(schema.schema, type);
|
|
1761
1783
|
}
|
|
1762
1784
|
if (isZodType(schema, "ZodEffects")) {
|
|
1763
|
-
return getZodObject(schema.innerType());
|
|
1785
|
+
return getZodObject(schema.innerType(), type);
|
|
1764
1786
|
}
|
|
1765
1787
|
if (isZodType(schema, "ZodBranded")) {
|
|
1766
|
-
return getZodObject(schema.unwrap());
|
|
1788
|
+
return getZodObject(schema.unwrap(), type);
|
|
1767
1789
|
}
|
|
1768
1790
|
if (isZodType(schema, "ZodPipeline")) {
|
|
1769
|
-
{
|
|
1770
|
-
return getZodObject(schema._def.in);
|
|
1791
|
+
if (type === "input") {
|
|
1792
|
+
return getZodObject(schema._def.in, type);
|
|
1771
1793
|
}
|
|
1794
|
+
return getZodObject(schema._def.out, type);
|
|
1772
1795
|
}
|
|
1773
1796
|
throw new Error("failed to find ZodObject in schema");
|
|
1774
1797
|
};
|
|
@@ -2407,5 +2430,6 @@ export {
|
|
|
2407
2430
|
createPaths,
|
|
2408
2431
|
createSchema,
|
|
2409
2432
|
createSchemaComponents,
|
|
2410
|
-
getDefaultComponents
|
|
2433
|
+
getDefaultComponents,
|
|
2434
|
+
getZodObject
|
|
2411
2435
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { ZodType } from 'zod';
|
|
1
|
+
import { ZodType, AnyZodObject } from 'zod';
|
|
2
2
|
import { ParameterObject, ReferenceObject } from '../openapi3-ts/dist/model/openapi31.js';
|
|
3
3
|
import { ComponentsObject } from './components.js';
|
|
4
|
-
import { ZodOpenApiParameters, CreateDocumentOptions } from './document.js';
|
|
4
|
+
import { ZodOpenApiParameters, CreateDocumentOptions, ZodObjectInputType } from './document.js';
|
|
5
5
|
|
|
6
6
|
declare const createParamOrRef: (zodSchema: ZodType, components: ComponentsObject, subpath: string[], type?: keyof ZodOpenApiParameters, name?: string, documentOptions?: CreateDocumentOptions) => ParameterObject | ReferenceObject;
|
|
7
|
+
declare const getZodObject: (schema: ZodObjectInputType, type: "input" | "output") => AnyZodObject;
|
|
7
8
|
|
|
8
|
-
export { createParamOrRef };
|
|
9
|
+
export { createParamOrRef, getZodObject };
|
package/dist/extend.cjs
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
3
|
const zod = require("zod");
|
|
3
4
|
const extendZod = require("./extendZod.chunk.cjs");
|
|
5
|
+
const extendZodTypes = require("./extendZodTypes.chunk.cjs");
|
|
4
6
|
extendZod.extendZodWithOpenApi(zod.z);
|
|
7
|
+
exports.currentSymbol = extendZodTypes.currentSymbol;
|
|
8
|
+
exports.previousSymbol = extendZodTypes.previousSymbol;
|
package/dist/extend.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export { currentSymbol, previousSymbol } from './extendZodTypes.js';
|
package/dist/extend.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export { currentSymbol, previousSymbol } from './extendZodTypes.js';
|
package/dist/extend.mjs
CHANGED
package/dist/extendZod.chunk.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
const extendZodTypes = require("./extendZodTypes.chunk.cjs");
|
|
2
3
|
const mergeOpenApi = (openapi, {
|
|
3
4
|
ref: _ref,
|
|
4
5
|
refType: _refType,
|
|
@@ -24,9 +25,9 @@ function extendZodWithOpenApi(zod) {
|
|
|
24
25
|
)
|
|
25
26
|
}
|
|
26
27
|
});
|
|
27
|
-
result._def.zodOpenApi.
|
|
28
|
+
result._def.zodOpenApi[extendZodTypes.currentSymbol] = result;
|
|
28
29
|
if (zodOpenApi) {
|
|
29
|
-
result._def.zodOpenApi.
|
|
30
|
+
result._def.zodOpenApi[extendZodTypes.previousSymbol] = this;
|
|
30
31
|
}
|
|
31
32
|
return result;
|
|
32
33
|
};
|
|
@@ -37,13 +38,13 @@ function extendZodWithOpenApi(zod) {
|
|
|
37
38
|
if (def.zodOpenApi) {
|
|
38
39
|
const cloned = { ...def.zodOpenApi };
|
|
39
40
|
cloned.openapi = mergeOpenApi({ description: args[0] }, cloned.openapi);
|
|
40
|
-
cloned.
|
|
41
|
-
cloned.
|
|
41
|
+
cloned[extendZodTypes.previousSymbol] = this;
|
|
42
|
+
cloned[extendZodTypes.currentSymbol] = result;
|
|
42
43
|
def.zodOpenApi = cloned;
|
|
43
44
|
} else {
|
|
44
45
|
def.zodOpenApi = {
|
|
45
46
|
openapi: { description: args[0] },
|
|
46
|
-
|
|
47
|
+
[extendZodTypes.currentSymbol]: result
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
return result;
|
|
@@ -55,11 +56,11 @@ function extendZodWithOpenApi(zod) {
|
|
|
55
56
|
if (zodOpenApi) {
|
|
56
57
|
const cloned = { ...zodOpenApi };
|
|
57
58
|
cloned.openapi = mergeOpenApi({}, cloned.openapi);
|
|
58
|
-
cloned.
|
|
59
|
+
cloned[extendZodTypes.previousSymbol] = this;
|
|
59
60
|
extendResult._def.zodOpenApi = cloned;
|
|
60
61
|
} else {
|
|
61
62
|
extendResult._def.zodOpenApi = {
|
|
62
|
-
|
|
63
|
+
[extendZodTypes.previousSymbol]: this
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
66
|
return extendResult;
|
|
@@ -71,8 +72,8 @@ function extendZodWithOpenApi(zod) {
|
|
|
71
72
|
if (zodOpenApi) {
|
|
72
73
|
const cloned = { ...zodOpenApi };
|
|
73
74
|
cloned.openapi = mergeOpenApi({}, cloned.openapi);
|
|
74
|
-
delete cloned.
|
|
75
|
-
delete cloned.
|
|
75
|
+
delete cloned[extendZodTypes.previousSymbol];
|
|
76
|
+
delete cloned[extendZodTypes.currentSymbol];
|
|
76
77
|
omitResult._def.zodOpenApi = cloned;
|
|
77
78
|
}
|
|
78
79
|
return omitResult;
|
|
@@ -84,8 +85,8 @@ function extendZodWithOpenApi(zod) {
|
|
|
84
85
|
if (zodOpenApi) {
|
|
85
86
|
const cloned = { ...zodOpenApi };
|
|
86
87
|
cloned.openapi = mergeOpenApi({}, cloned.openapi);
|
|
87
|
-
delete cloned.
|
|
88
|
-
delete cloned.
|
|
88
|
+
delete cloned[extendZodTypes.previousSymbol];
|
|
89
|
+
delete cloned[extendZodTypes.currentSymbol];
|
|
89
90
|
pickResult._def.zodOpenApi = cloned;
|
|
90
91
|
}
|
|
91
92
|
return pickResult;
|
package/dist/extendZod.chunk.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { currentSymbol, previousSymbol } from "./extendZodTypes.chunk.mjs";
|
|
1
2
|
const mergeOpenApi = (openapi, {
|
|
2
3
|
ref: _ref,
|
|
3
4
|
refType: _refType,
|
|
@@ -23,9 +24,9 @@ function extendZodWithOpenApi(zod) {
|
|
|
23
24
|
)
|
|
24
25
|
}
|
|
25
26
|
});
|
|
26
|
-
result._def.zodOpenApi
|
|
27
|
+
result._def.zodOpenApi[currentSymbol] = result;
|
|
27
28
|
if (zodOpenApi) {
|
|
28
|
-
result._def.zodOpenApi
|
|
29
|
+
result._def.zodOpenApi[previousSymbol] = this;
|
|
29
30
|
}
|
|
30
31
|
return result;
|
|
31
32
|
};
|
|
@@ -36,13 +37,13 @@ function extendZodWithOpenApi(zod) {
|
|
|
36
37
|
if (def.zodOpenApi) {
|
|
37
38
|
const cloned = { ...def.zodOpenApi };
|
|
38
39
|
cloned.openapi = mergeOpenApi({ description: args[0] }, cloned.openapi);
|
|
39
|
-
cloned
|
|
40
|
-
cloned
|
|
40
|
+
cloned[previousSymbol] = this;
|
|
41
|
+
cloned[currentSymbol] = result;
|
|
41
42
|
def.zodOpenApi = cloned;
|
|
42
43
|
} else {
|
|
43
44
|
def.zodOpenApi = {
|
|
44
45
|
openapi: { description: args[0] },
|
|
45
|
-
|
|
46
|
+
[currentSymbol]: result
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
49
|
return result;
|
|
@@ -54,11 +55,11 @@ function extendZodWithOpenApi(zod) {
|
|
|
54
55
|
if (zodOpenApi) {
|
|
55
56
|
const cloned = { ...zodOpenApi };
|
|
56
57
|
cloned.openapi = mergeOpenApi({}, cloned.openapi);
|
|
57
|
-
cloned
|
|
58
|
+
cloned[previousSymbol] = this;
|
|
58
59
|
extendResult._def.zodOpenApi = cloned;
|
|
59
60
|
} else {
|
|
60
61
|
extendResult._def.zodOpenApi = {
|
|
61
|
-
|
|
62
|
+
[previousSymbol]: this
|
|
62
63
|
};
|
|
63
64
|
}
|
|
64
65
|
return extendResult;
|
|
@@ -70,8 +71,8 @@ function extendZodWithOpenApi(zod) {
|
|
|
70
71
|
if (zodOpenApi) {
|
|
71
72
|
const cloned = { ...zodOpenApi };
|
|
72
73
|
cloned.openapi = mergeOpenApi({}, cloned.openapi);
|
|
73
|
-
delete cloned
|
|
74
|
-
delete cloned
|
|
74
|
+
delete cloned[previousSymbol];
|
|
75
|
+
delete cloned[currentSymbol];
|
|
75
76
|
omitResult._def.zodOpenApi = cloned;
|
|
76
77
|
}
|
|
77
78
|
return omitResult;
|
|
@@ -83,8 +84,8 @@ function extendZodWithOpenApi(zod) {
|
|
|
83
84
|
if (zodOpenApi) {
|
|
84
85
|
const cloned = { ...zodOpenApi };
|
|
85
86
|
cloned.openapi = mergeOpenApi({}, cloned.openapi);
|
|
86
|
-
delete cloned
|
|
87
|
-
delete cloned
|
|
87
|
+
delete cloned[previousSymbol];
|
|
88
|
+
delete cloned[currentSymbol];
|
|
88
89
|
pickResult._def.zodOpenApi = cloned;
|
|
89
90
|
}
|
|
90
91
|
return pickResult;
|
package/dist/extendZod.d.ts
CHANGED
package/dist/extendZodTypes.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ import { ParameterObject, ExampleObject, ReferenceObject, HeaderObject, SchemaOb
|
|
|
5
5
|
|
|
6
6
|
type SchemaObject = SchemaObject$1 & SchemaObject$2;
|
|
7
7
|
type ReplaceDate<T> = T extends Date ? Date | string : T;
|
|
8
|
+
declare const currentSymbol: unique symbol;
|
|
9
|
+
declare const previousSymbol: unique symbol;
|
|
8
10
|
/**
|
|
9
11
|
* zod-openapi metadata
|
|
10
12
|
*/
|
|
@@ -64,12 +66,12 @@ interface ZodOpenApiMetadataDef {
|
|
|
64
66
|
/**
|
|
65
67
|
* Used to keep track of the Zod Schema had `.openapi` called on it
|
|
66
68
|
*/
|
|
67
|
-
|
|
69
|
+
[currentSymbol]?: ZodTypeAny;
|
|
68
70
|
/**
|
|
69
71
|
* Used to keep track of the previous Zod Schema that had `.openapi` called on it if another `.openapi` is called.
|
|
70
72
|
* This can also be present when .extend is called on an object.
|
|
71
73
|
*/
|
|
72
|
-
|
|
74
|
+
[previousSymbol]?: ZodTypeAny;
|
|
73
75
|
}
|
|
74
76
|
interface ZodOpenApiExtendMetadata {
|
|
75
77
|
extends: ZodObject<any, any, any, any, any>;
|
|
@@ -88,3 +90,5 @@ declare module 'zod' {
|
|
|
88
90
|
extendMetadata?: ZodOpenApiExtendMetadata;
|
|
89
91
|
}
|
|
90
92
|
}
|
|
93
|
+
|
|
94
|
+
export { currentSymbol, previousSymbol };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-openapi",
|
|
3
|
-
"version": "4.1
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "Convert Zod Schemas to OpenAPI v3.x documentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -74,13 +74,13 @@
|
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@arethetypeswrong/cli": "0.17.1",
|
|
76
76
|
"@crackle/cli": "0.15.5",
|
|
77
|
-
"@redocly/cli": "1.
|
|
77
|
+
"@redocly/cli": "1.26.0",
|
|
78
78
|
"@types/node": "^20.3.0",
|
|
79
79
|
"eslint-plugin-zod-openapi": "^1.0.0-beta.0",
|
|
80
80
|
"openapi3-ts": "4.4.0",
|
|
81
81
|
"skuba": "9.1.0",
|
|
82
82
|
"yaml": "2.6.1",
|
|
83
|
-
"zod": "3.
|
|
83
|
+
"zod": "3.24.1"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"zod": "^3.21.4"
|
|
@@ -97,6 +97,6 @@
|
|
|
97
97
|
"entryPoint": "src/index.ts",
|
|
98
98
|
"template": "oss-npm-package",
|
|
99
99
|
"type": "package",
|
|
100
|
-
"version": "9.
|
|
100
|
+
"version": "9.1.0"
|
|
101
101
|
}
|
|
102
102
|
}
|