zod-openapi 5.4.0 → 5.4.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/dist/api.cjs +1 -1
- package/dist/api.js +1 -1
- package/dist/{components-D0GND9iu.js → components-8XHv_FhV.js} +31 -48
- package/dist/{components-C8ab2kZS.cjs → components-BPKWviAb.cjs} +34 -49
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -1
- package/package.json +5 -5
package/dist/api.cjs
CHANGED
package/dist/api.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { createComponents, createRegistry, isAnyZodType, unwrapZodObject } from "./components-
|
|
1
|
+
import { createComponents, createRegistry, isAnyZodType, unwrapZodObject } from "./components-8XHv_FhV.js";
|
|
2
2
|
|
|
3
3
|
export { createComponents, createRegistry, isAnyZodType, unwrapZodObject };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { globalRegistry } from "zod/v4/core";
|
|
2
|
-
import { object, registry, toJSONSchema as toJSONSchema$1 } from "zod/v4";
|
|
2
|
+
import { globalRegistry as globalRegistry$1, object, registry, toJSONSchema as toJSONSchema$1 } from "zod/v4";
|
|
3
3
|
|
|
4
4
|
//#region src/zod.ts
|
|
5
5
|
const isAnyZodType = (schema) => typeof schema === "object" && schema !== null && "_zod" in schema;
|
|
@@ -7,12 +7,9 @@ const isAnyZodType = (schema) => typeof schema === "object" && schema !== null &
|
|
|
7
7
|
//#endregion
|
|
8
8
|
//#region src/create/examples.ts
|
|
9
9
|
const createExamples = (examples, registry$1, path) => {
|
|
10
|
-
if (!examples) return
|
|
10
|
+
if (!examples) return;
|
|
11
11
|
const examplesObject = {};
|
|
12
|
-
for (const [name, example] of Object.entries(examples))
|
|
13
|
-
const exampleObject = registry$1.addExample(example, [...path, name]);
|
|
14
|
-
examplesObject[name] = exampleObject;
|
|
15
|
-
}
|
|
12
|
+
for (const [name, example] of Object.entries(examples)) examplesObject[name] = registry$1.addExample(example, [...path, name]);
|
|
16
13
|
return examplesObject;
|
|
17
14
|
};
|
|
18
15
|
|
|
@@ -21,13 +18,11 @@ const createExamples = (examples, registry$1, path) => {
|
|
|
21
18
|
const createMediaTypeObject = (mediaType, ctx, path) => {
|
|
22
19
|
const { schema, examples,...rest } = mediaType;
|
|
23
20
|
const mediaTypeObject = rest;
|
|
24
|
-
if (isAnyZodType(schema)) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
mediaTypeObject.schema = schemaObject;
|
|
30
|
-
} else mediaTypeObject.schema = schema;
|
|
21
|
+
if (isAnyZodType(schema)) mediaTypeObject.schema = ctx.registry.addSchema(schema, [...path, "schema"], {
|
|
22
|
+
io: ctx.io,
|
|
23
|
+
source: { type: "mediaType" }
|
|
24
|
+
});
|
|
25
|
+
else mediaTypeObject.schema = schema;
|
|
31
26
|
if (examples) mediaTypeObject.examples = createExamples(examples, ctx.registry, [...path, "examples"]);
|
|
32
27
|
return mediaTypeObject;
|
|
33
28
|
};
|
|
@@ -58,14 +53,11 @@ const isRequired = (zodType, io) => {
|
|
|
58
53
|
//#endregion
|
|
59
54
|
//#region src/create/headers.ts
|
|
60
55
|
const createHeaders = (headers, registry$1, path) => {
|
|
61
|
-
if (!headers) return
|
|
56
|
+
if (!headers) return;
|
|
62
57
|
if (isAnyZodType(headers)) {
|
|
63
58
|
const zodObject = unwrapZodObject(headers, "output", path);
|
|
64
59
|
const headersObject = {};
|
|
65
|
-
for (const [key, zodSchema] of Object.entries(zodObject._zod.def.shape))
|
|
66
|
-
const header = registry$1.addHeader(zodSchema, [...path, key]);
|
|
67
|
-
headersObject[key] = header;
|
|
68
|
-
}
|
|
60
|
+
for (const [key, zodSchema] of Object.entries(zodObject._zod.def.shape)) headersObject[key] = registry$1.addHeader(zodSchema, [...path, key]);
|
|
69
61
|
return headersObject;
|
|
70
62
|
}
|
|
71
63
|
return headers;
|
|
@@ -74,19 +66,16 @@ const createHeaders = (headers, registry$1, path) => {
|
|
|
74
66
|
//#endregion
|
|
75
67
|
//#region src/create/links.ts
|
|
76
68
|
const createLinks = (links, registry$1, path) => {
|
|
77
|
-
if (!links) return
|
|
69
|
+
if (!links) return;
|
|
78
70
|
const linksObject = {};
|
|
79
|
-
for (const [name, link] of Object.entries(links))
|
|
80
|
-
const linkObject = registry$1.addLink(link, [...path, name]);
|
|
81
|
-
linksObject[name] = linkObject;
|
|
82
|
-
}
|
|
71
|
+
for (const [name, link] of Object.entries(links)) linksObject[name] = registry$1.addLink(link, [...path, name]);
|
|
83
72
|
return linksObject;
|
|
84
73
|
};
|
|
85
74
|
|
|
86
75
|
//#endregion
|
|
87
76
|
//#region src/create/parameters.ts
|
|
88
77
|
const createManualParameters = (parameters, registry$1, path) => {
|
|
89
|
-
if (!parameters) return
|
|
78
|
+
if (!parameters) return;
|
|
90
79
|
const parameterObjects = [];
|
|
91
80
|
for (const parameter of parameters) {
|
|
92
81
|
if (isAnyZodType(parameter)) {
|
|
@@ -99,7 +88,7 @@ const createManualParameters = (parameters, registry$1, path) => {
|
|
|
99
88
|
return parameterObjects;
|
|
100
89
|
};
|
|
101
90
|
const createParameters = (requestParams, registry$1, path) => {
|
|
102
|
-
if (!requestParams) return
|
|
91
|
+
if (!requestParams) return;
|
|
103
92
|
const parameterObjects = [];
|
|
104
93
|
for (const [location, schema] of Object.entries(requestParams ?? {})) {
|
|
105
94
|
const zodObject = unwrapZodObject(schema, "input", path);
|
|
@@ -125,7 +114,7 @@ const isISpecificationExtension = (key) => key.startsWith("x-");
|
|
|
125
114
|
//#endregion
|
|
126
115
|
//#region src/create/callbacks.ts
|
|
127
116
|
const createCallbacks = (callbacks, registry$1, path) => {
|
|
128
|
-
if (!callbacks) return
|
|
117
|
+
if (!callbacks) return;
|
|
129
118
|
const callbacksObject = {};
|
|
130
119
|
for (const [name, value] of Object.entries(callbacks)) {
|
|
131
120
|
if (isISpecificationExtension(name)) {
|
|
@@ -140,7 +129,7 @@ const createCallbacks = (callbacks, registry$1, path) => {
|
|
|
140
129
|
//#endregion
|
|
141
130
|
//#region src/create/responses.ts
|
|
142
131
|
const createResponses = (responses, registry$1, path) => {
|
|
143
|
-
if (!responses) return
|
|
132
|
+
if (!responses) return;
|
|
144
133
|
const responsesObject = {};
|
|
145
134
|
for (const [statusCode, response] of Object.entries(responses)) {
|
|
146
135
|
if (!response) continue;
|
|
@@ -152,8 +141,7 @@ const createResponses = (responses, registry$1, path) => {
|
|
|
152
141
|
responsesObject[statusCode] = response;
|
|
153
142
|
continue;
|
|
154
143
|
}
|
|
155
|
-
|
|
156
|
-
responsesObject[statusCode] = responseObject;
|
|
144
|
+
responsesObject[statusCode] = registry$1.addResponse(response, [...path, statusCode]);
|
|
157
145
|
}
|
|
158
146
|
return responsesObject;
|
|
159
147
|
};
|
|
@@ -175,7 +163,7 @@ const createOperation = (operation, registry$1, path) => {
|
|
|
175
163
|
return operationObject;
|
|
176
164
|
};
|
|
177
165
|
const createPaths = (paths, registry$1, path) => {
|
|
178
|
-
if (!paths) return
|
|
166
|
+
if (!paths) return;
|
|
179
167
|
const pathsObject = {};
|
|
180
168
|
for (const [singlePath, pathItemObject] of Object.entries(paths)) {
|
|
181
169
|
if (isISpecificationExtension(singlePath)) {
|
|
@@ -230,7 +218,7 @@ const override = (ctx) => {
|
|
|
230
218
|
}
|
|
231
219
|
ctx.jsonSchema.discriminator.mapping = mapping;
|
|
232
220
|
}
|
|
233
|
-
const meta = ctx.zodSchema
|
|
221
|
+
const meta = globalRegistry$1.get(ctx.zodSchema);
|
|
234
222
|
if (typeof meta?.unionOneOf === "boolean") {
|
|
235
223
|
if (meta.unionOneOf) {
|
|
236
224
|
ctx.jsonSchema.oneOf = ctx.jsonSchema.anyOf;
|
|
@@ -298,8 +286,7 @@ const renameComponents = (components, outputIds, ctx, refPath) => {
|
|
|
298
286
|
componentDependencies.set(key, { dependencies });
|
|
299
287
|
}
|
|
300
288
|
for (const [key] of stringifiedComponents) {
|
|
301
|
-
|
|
302
|
-
if (!registeredComponent) continue;
|
|
289
|
+
if (!ctx.registry.components.schemas.ids.get(key)) continue;
|
|
303
290
|
if (isDependencyPure(componentDependencies, stringifiedComponents, ctx.registry, key)) continue;
|
|
304
291
|
const newName = outputIds.get(key) ?? `${key}${ctx.opts.outputIdSuffix ?? "Output"}`;
|
|
305
292
|
componentsToRename.set(key, newName);
|
|
@@ -327,11 +314,7 @@ const isDependencyPure = (componentDependencies, stringifiedComponents, registry
|
|
|
327
314
|
|
|
328
315
|
//#endregion
|
|
329
316
|
//#region src/create/schema/schema.ts
|
|
330
|
-
const createSchema = (schema, ctx = {
|
|
331
|
-
registry: createRegistry(),
|
|
332
|
-
io: "output",
|
|
333
|
-
opts: {}
|
|
334
|
-
}) => {
|
|
317
|
+
const createSchema = (schema, ctx = {}) => {
|
|
335
318
|
ctx.registry ??= createRegistry({ schemas: ctx.schemaComponents });
|
|
336
319
|
ctx.opts ??= {};
|
|
337
320
|
ctx.io ??= "output";
|
|
@@ -377,9 +360,10 @@ const createSchemas = (schemas, ctx) => {
|
|
|
377
360
|
zodRegistry.add(object(entries), { id: "zodOpenApiCreateSchema" });
|
|
378
361
|
for (const [id, { zodType }] of ctx.registry.components.schemas.manual) zodRegistry.add(zodType, { id });
|
|
379
362
|
const outputIds = /* @__PURE__ */ new Map();
|
|
363
|
+
const defsName = satisfiesVersion(ctx.openapiVersion ?? "3.1.0", "3.1.0") ? "$defs" : "definitions";
|
|
380
364
|
const jsonSchema = toJSONSchema$1(zodRegistry, {
|
|
381
365
|
override(context) {
|
|
382
|
-
const meta = context.zodSchema
|
|
366
|
+
const meta = globalRegistry$1.get(context.zodSchema);
|
|
383
367
|
if (meta?.outputId && meta?.id) outputIds.set(meta.id, meta.outputId);
|
|
384
368
|
if (context.jsonSchema.$ref) return;
|
|
385
369
|
const enrichedContext = {
|
|
@@ -405,10 +389,10 @@ const createSchemas = (schemas, ctx) => {
|
|
|
405
389
|
reused: ctx.opts.reused,
|
|
406
390
|
cycles: ctx.opts.cycles,
|
|
407
391
|
target: satisfiesVersion(ctx.openapiVersion ?? "3.1.0", "3.1.0") ? void 0 : "openapi-3.0",
|
|
408
|
-
uri: (id) => id === "__shared" ? `#ZOD_OPENAPI/${id}` : `#ZOD_OPENAPI/__shared#/$
|
|
392
|
+
uri: (id) => id === "__shared" ? `#ZOD_OPENAPI/${id}` : `#ZOD_OPENAPI/__shared#/${defsName}/${id}`
|
|
409
393
|
});
|
|
410
|
-
const components = jsonSchema.schemas.__shared
|
|
411
|
-
jsonSchema.schemas.__shared ??= {
|
|
394
|
+
const components = jsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
395
|
+
jsonSchema.schemas.__shared ??= { [defsName]: components };
|
|
412
396
|
const dynamicComponents = /* @__PURE__ */ new Map();
|
|
413
397
|
for (const [key, value] of Object.entries(components)) {
|
|
414
398
|
deleteInvalidJsonSchemaFields(value);
|
|
@@ -427,15 +411,14 @@ const createSchemas = (schemas, ctx) => {
|
|
|
427
411
|
deleteInvalidJsonSchemaFields(manualComponent);
|
|
428
412
|
}
|
|
429
413
|
const manualUsed = {};
|
|
430
|
-
const parsedJsonSchema = JSON.parse(JSON.stringify(jsonSchema).replace(/"#ZOD_OPENAPI\/__shared
|
|
414
|
+
const parsedJsonSchema = JSON.parse(JSON.stringify(jsonSchema).replace(/"#ZOD_OPENAPI\/__shared#\/(?:\$defs|definitions)\/([^"]+)"/g, (_, match) => {
|
|
431
415
|
const dynamic = dynamicComponents.get(match);
|
|
432
416
|
if (dynamic) return dynamic;
|
|
433
|
-
|
|
434
|
-
if (manualComponent) manualUsed[match] = true;
|
|
417
|
+
if (ctx.registry.components.schemas.manual.get(match)) manualUsed[match] = true;
|
|
435
418
|
return `"${refPath}${match}"`;
|
|
436
419
|
}));
|
|
437
|
-
const parsedComponents = parsedJsonSchema.schemas.__shared
|
|
438
|
-
parsedJsonSchema.schemas.__shared ??= {
|
|
420
|
+
const parsedComponents = parsedJsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
421
|
+
parsedJsonSchema.schemas.__shared ??= { [defsName]: parsedComponents };
|
|
439
422
|
for (const [key] of ctx.registry.components.schemas.manual) {
|
|
440
423
|
const manualComponent = parsedJsonSchema.schemas[key];
|
|
441
424
|
if (!manualComponent) continue;
|
|
@@ -461,7 +444,7 @@ const createSchemas = (schemas, ctx) => {
|
|
|
461
444
|
return `"${refPath}${match}"`;
|
|
462
445
|
}));
|
|
463
446
|
const renamedSchemas = renamedJsonSchema.schemas.zodOpenApiCreateSchema?.properties;
|
|
464
|
-
const renamedComponents = renamedJsonSchema.schemas.__shared
|
|
447
|
+
const renamedComponents = renamedJsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
465
448
|
delete renamedJsonSchema.schemas.zodOpenApiCreateSchema;
|
|
466
449
|
delete renamedJsonSchema.schemas.__shared;
|
|
467
450
|
return {
|
|
@@ -21,8 +21,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
let zod_v4_core = require("zod/v4/core");
|
|
25
|
+
zod_v4_core = __toESM(zod_v4_core);
|
|
26
|
+
let zod_v4 = require("zod/v4");
|
|
27
|
+
zod_v4 = __toESM(zod_v4);
|
|
26
28
|
|
|
27
29
|
//#region src/zod.ts
|
|
28
30
|
const isAnyZodType = (schema) => typeof schema === "object" && schema !== null && "_zod" in schema;
|
|
@@ -30,12 +32,9 @@ const isAnyZodType = (schema) => typeof schema === "object" && schema !== null &
|
|
|
30
32
|
//#endregion
|
|
31
33
|
//#region src/create/examples.ts
|
|
32
34
|
const createExamples = (examples, registry$1, path) => {
|
|
33
|
-
if (!examples) return
|
|
35
|
+
if (!examples) return;
|
|
34
36
|
const examplesObject = {};
|
|
35
|
-
for (const [name, example] of Object.entries(examples))
|
|
36
|
-
const exampleObject = registry$1.addExample(example, [...path, name]);
|
|
37
|
-
examplesObject[name] = exampleObject;
|
|
38
|
-
}
|
|
37
|
+
for (const [name, example] of Object.entries(examples)) examplesObject[name] = registry$1.addExample(example, [...path, name]);
|
|
39
38
|
return examplesObject;
|
|
40
39
|
};
|
|
41
40
|
|
|
@@ -44,13 +43,11 @@ const createExamples = (examples, registry$1, path) => {
|
|
|
44
43
|
const createMediaTypeObject = (mediaType, ctx, path) => {
|
|
45
44
|
const { schema, examples,...rest } = mediaType;
|
|
46
45
|
const mediaTypeObject = rest;
|
|
47
|
-
if (isAnyZodType(schema)) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
mediaTypeObject.schema = schemaObject;
|
|
53
|
-
} else mediaTypeObject.schema = schema;
|
|
46
|
+
if (isAnyZodType(schema)) mediaTypeObject.schema = ctx.registry.addSchema(schema, [...path, "schema"], {
|
|
47
|
+
io: ctx.io,
|
|
48
|
+
source: { type: "mediaType" }
|
|
49
|
+
});
|
|
50
|
+
else mediaTypeObject.schema = schema;
|
|
54
51
|
if (examples) mediaTypeObject.examples = createExamples(examples, ctx.registry, [...path, "examples"]);
|
|
55
52
|
return mediaTypeObject;
|
|
56
53
|
};
|
|
@@ -81,14 +78,11 @@ const isRequired = (zodType, io) => {
|
|
|
81
78
|
//#endregion
|
|
82
79
|
//#region src/create/headers.ts
|
|
83
80
|
const createHeaders = (headers, registry$1, path) => {
|
|
84
|
-
if (!headers) return
|
|
81
|
+
if (!headers) return;
|
|
85
82
|
if (isAnyZodType(headers)) {
|
|
86
83
|
const zodObject = unwrapZodObject(headers, "output", path);
|
|
87
84
|
const headersObject = {};
|
|
88
|
-
for (const [key, zodSchema] of Object.entries(zodObject._zod.def.shape))
|
|
89
|
-
const header = registry$1.addHeader(zodSchema, [...path, key]);
|
|
90
|
-
headersObject[key] = header;
|
|
91
|
-
}
|
|
85
|
+
for (const [key, zodSchema] of Object.entries(zodObject._zod.def.shape)) headersObject[key] = registry$1.addHeader(zodSchema, [...path, key]);
|
|
92
86
|
return headersObject;
|
|
93
87
|
}
|
|
94
88
|
return headers;
|
|
@@ -97,19 +91,16 @@ const createHeaders = (headers, registry$1, path) => {
|
|
|
97
91
|
//#endregion
|
|
98
92
|
//#region src/create/links.ts
|
|
99
93
|
const createLinks = (links, registry$1, path) => {
|
|
100
|
-
if (!links) return
|
|
94
|
+
if (!links) return;
|
|
101
95
|
const linksObject = {};
|
|
102
|
-
for (const [name, link] of Object.entries(links))
|
|
103
|
-
const linkObject = registry$1.addLink(link, [...path, name]);
|
|
104
|
-
linksObject[name] = linkObject;
|
|
105
|
-
}
|
|
96
|
+
for (const [name, link] of Object.entries(links)) linksObject[name] = registry$1.addLink(link, [...path, name]);
|
|
106
97
|
return linksObject;
|
|
107
98
|
};
|
|
108
99
|
|
|
109
100
|
//#endregion
|
|
110
101
|
//#region src/create/parameters.ts
|
|
111
102
|
const createManualParameters = (parameters, registry$1, path) => {
|
|
112
|
-
if (!parameters) return
|
|
103
|
+
if (!parameters) return;
|
|
113
104
|
const parameterObjects = [];
|
|
114
105
|
for (const parameter of parameters) {
|
|
115
106
|
if (isAnyZodType(parameter)) {
|
|
@@ -122,7 +113,7 @@ const createManualParameters = (parameters, registry$1, path) => {
|
|
|
122
113
|
return parameterObjects;
|
|
123
114
|
};
|
|
124
115
|
const createParameters = (requestParams, registry$1, path) => {
|
|
125
|
-
if (!requestParams) return
|
|
116
|
+
if (!requestParams) return;
|
|
126
117
|
const parameterObjects = [];
|
|
127
118
|
for (const [location, schema] of Object.entries(requestParams ?? {})) {
|
|
128
119
|
const zodObject = unwrapZodObject(schema, "input", path);
|
|
@@ -148,7 +139,7 @@ const isISpecificationExtension = (key) => key.startsWith("x-");
|
|
|
148
139
|
//#endregion
|
|
149
140
|
//#region src/create/callbacks.ts
|
|
150
141
|
const createCallbacks = (callbacks, registry$1, path) => {
|
|
151
|
-
if (!callbacks) return
|
|
142
|
+
if (!callbacks) return;
|
|
152
143
|
const callbacksObject = {};
|
|
153
144
|
for (const [name, value] of Object.entries(callbacks)) {
|
|
154
145
|
if (isISpecificationExtension(name)) {
|
|
@@ -163,7 +154,7 @@ const createCallbacks = (callbacks, registry$1, path) => {
|
|
|
163
154
|
//#endregion
|
|
164
155
|
//#region src/create/responses.ts
|
|
165
156
|
const createResponses = (responses, registry$1, path) => {
|
|
166
|
-
if (!responses) return
|
|
157
|
+
if (!responses) return;
|
|
167
158
|
const responsesObject = {};
|
|
168
159
|
for (const [statusCode, response] of Object.entries(responses)) {
|
|
169
160
|
if (!response) continue;
|
|
@@ -175,8 +166,7 @@ const createResponses = (responses, registry$1, path) => {
|
|
|
175
166
|
responsesObject[statusCode] = response;
|
|
176
167
|
continue;
|
|
177
168
|
}
|
|
178
|
-
|
|
179
|
-
responsesObject[statusCode] = responseObject;
|
|
169
|
+
responsesObject[statusCode] = registry$1.addResponse(response, [...path, statusCode]);
|
|
180
170
|
}
|
|
181
171
|
return responsesObject;
|
|
182
172
|
};
|
|
@@ -198,7 +188,7 @@ const createOperation = (operation, registry$1, path) => {
|
|
|
198
188
|
return operationObject;
|
|
199
189
|
};
|
|
200
190
|
const createPaths = (paths, registry$1, path) => {
|
|
201
|
-
if (!paths) return
|
|
191
|
+
if (!paths) return;
|
|
202
192
|
const pathsObject = {};
|
|
203
193
|
for (const [singlePath, pathItemObject] of Object.entries(paths)) {
|
|
204
194
|
if (isISpecificationExtension(singlePath)) {
|
|
@@ -253,7 +243,7 @@ const override = (ctx) => {
|
|
|
253
243
|
}
|
|
254
244
|
ctx.jsonSchema.discriminator.mapping = mapping;
|
|
255
245
|
}
|
|
256
|
-
const meta = ctx.zodSchema
|
|
246
|
+
const meta = zod_v4.globalRegistry.get(ctx.zodSchema);
|
|
257
247
|
if (typeof meta?.unionOneOf === "boolean") {
|
|
258
248
|
if (meta.unionOneOf) {
|
|
259
249
|
ctx.jsonSchema.oneOf = ctx.jsonSchema.anyOf;
|
|
@@ -321,8 +311,7 @@ const renameComponents = (components, outputIds, ctx, refPath) => {
|
|
|
321
311
|
componentDependencies.set(key, { dependencies });
|
|
322
312
|
}
|
|
323
313
|
for (const [key] of stringifiedComponents) {
|
|
324
|
-
|
|
325
|
-
if (!registeredComponent) continue;
|
|
314
|
+
if (!ctx.registry.components.schemas.ids.get(key)) continue;
|
|
326
315
|
if (isDependencyPure(componentDependencies, stringifiedComponents, ctx.registry, key)) continue;
|
|
327
316
|
const newName = outputIds.get(key) ?? `${key}${ctx.opts.outputIdSuffix ?? "Output"}`;
|
|
328
317
|
componentsToRename.set(key, newName);
|
|
@@ -350,11 +339,7 @@ const isDependencyPure = (componentDependencies, stringifiedComponents, registry
|
|
|
350
339
|
|
|
351
340
|
//#endregion
|
|
352
341
|
//#region src/create/schema/schema.ts
|
|
353
|
-
const createSchema = (schema, ctx = {
|
|
354
|
-
registry: createRegistry(),
|
|
355
|
-
io: "output",
|
|
356
|
-
opts: {}
|
|
357
|
-
}) => {
|
|
342
|
+
const createSchema = (schema, ctx = {}) => {
|
|
358
343
|
ctx.registry ??= createRegistry({ schemas: ctx.schemaComponents });
|
|
359
344
|
ctx.opts ??= {};
|
|
360
345
|
ctx.io ??= "output";
|
|
@@ -400,9 +385,10 @@ const createSchemas = (schemas, ctx) => {
|
|
|
400
385
|
zodRegistry.add((0, zod_v4.object)(entries), { id: "zodOpenApiCreateSchema" });
|
|
401
386
|
for (const [id, { zodType }] of ctx.registry.components.schemas.manual) zodRegistry.add(zodType, { id });
|
|
402
387
|
const outputIds = /* @__PURE__ */ new Map();
|
|
388
|
+
const defsName = satisfiesVersion(ctx.openapiVersion ?? "3.1.0", "3.1.0") ? "$defs" : "definitions";
|
|
403
389
|
const jsonSchema = (0, zod_v4.toJSONSchema)(zodRegistry, {
|
|
404
390
|
override(context) {
|
|
405
|
-
const meta = context.zodSchema
|
|
391
|
+
const meta = zod_v4.globalRegistry.get(context.zodSchema);
|
|
406
392
|
if (meta?.outputId && meta?.id) outputIds.set(meta.id, meta.outputId);
|
|
407
393
|
if (context.jsonSchema.$ref) return;
|
|
408
394
|
const enrichedContext = {
|
|
@@ -428,10 +414,10 @@ const createSchemas = (schemas, ctx) => {
|
|
|
428
414
|
reused: ctx.opts.reused,
|
|
429
415
|
cycles: ctx.opts.cycles,
|
|
430
416
|
target: satisfiesVersion(ctx.openapiVersion ?? "3.1.0", "3.1.0") ? void 0 : "openapi-3.0",
|
|
431
|
-
uri: (id) => id === "__shared" ? `#ZOD_OPENAPI/${id}` : `#ZOD_OPENAPI/__shared#/$
|
|
417
|
+
uri: (id) => id === "__shared" ? `#ZOD_OPENAPI/${id}` : `#ZOD_OPENAPI/__shared#/${defsName}/${id}`
|
|
432
418
|
});
|
|
433
|
-
const components = jsonSchema.schemas.__shared
|
|
434
|
-
jsonSchema.schemas.__shared ??= {
|
|
419
|
+
const components = jsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
420
|
+
jsonSchema.schemas.__shared ??= { [defsName]: components };
|
|
435
421
|
const dynamicComponents = /* @__PURE__ */ new Map();
|
|
436
422
|
for (const [key, value] of Object.entries(components)) {
|
|
437
423
|
deleteInvalidJsonSchemaFields(value);
|
|
@@ -450,15 +436,14 @@ const createSchemas = (schemas, ctx) => {
|
|
|
450
436
|
deleteInvalidJsonSchemaFields(manualComponent);
|
|
451
437
|
}
|
|
452
438
|
const manualUsed = {};
|
|
453
|
-
const parsedJsonSchema = JSON.parse(JSON.stringify(jsonSchema).replace(/"#ZOD_OPENAPI\/__shared
|
|
439
|
+
const parsedJsonSchema = JSON.parse(JSON.stringify(jsonSchema).replace(/"#ZOD_OPENAPI\/__shared#\/(?:\$defs|definitions)\/([^"]+)"/g, (_, match) => {
|
|
454
440
|
const dynamic = dynamicComponents.get(match);
|
|
455
441
|
if (dynamic) return dynamic;
|
|
456
|
-
|
|
457
|
-
if (manualComponent) manualUsed[match] = true;
|
|
442
|
+
if (ctx.registry.components.schemas.manual.get(match)) manualUsed[match] = true;
|
|
458
443
|
return `"${refPath}${match}"`;
|
|
459
444
|
}));
|
|
460
|
-
const parsedComponents = parsedJsonSchema.schemas.__shared
|
|
461
|
-
parsedJsonSchema.schemas.__shared ??= {
|
|
445
|
+
const parsedComponents = parsedJsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
446
|
+
parsedJsonSchema.schemas.__shared ??= { [defsName]: parsedComponents };
|
|
462
447
|
for (const [key] of ctx.registry.components.schemas.manual) {
|
|
463
448
|
const manualComponent = parsedJsonSchema.schemas[key];
|
|
464
449
|
if (!manualComponent) continue;
|
|
@@ -484,7 +469,7 @@ const createSchemas = (schemas, ctx) => {
|
|
|
484
469
|
return `"${refPath}${match}"`;
|
|
485
470
|
}));
|
|
486
471
|
const renamedSchemas = renamedJsonSchema.schemas.zodOpenApiCreateSchema?.properties;
|
|
487
|
-
const renamedComponents = renamedJsonSchema.schemas.__shared
|
|
472
|
+
const renamedComponents = renamedJsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
488
473
|
delete renamedJsonSchema.schemas.zodOpenApiCreateSchema;
|
|
489
474
|
delete renamedJsonSchema.schemas.__shared;
|
|
490
475
|
return {
|
package/dist/index.cjs
CHANGED
package/dist/index.d.cts
CHANGED
|
@@ -2,9 +2,7 @@ import { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry
|
|
|
2
2
|
import * as core from "zod/v4/core";
|
|
3
3
|
|
|
4
4
|
//#region rolldown:runtime
|
|
5
|
-
|
|
6
|
-
export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentsObject, ContactObject, ContentObject, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject };
|
|
7
|
-
}
|
|
5
|
+
|
|
8
6
|
//#endregion
|
|
9
7
|
//#region src/create/schema/schema.d.ts
|
|
10
8
|
interface SchemaResult {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,9 +2,7 @@ import { BaseParameterObject, CallbackObject, CallbacksObject, ComponentRegistry
|
|
|
2
2
|
import * as core from "zod/v4/core";
|
|
3
3
|
|
|
4
4
|
//#region rolldown:runtime
|
|
5
|
-
|
|
6
|
-
export { BaseParameterObject, CallbackObject, CallbacksObject, ComponentsObject, ContactObject, ContentObject, DiscriminatorObject, EncodingObject, EncodingPropertyObject, ExampleObject, ExamplesObject, ExternalDocumentationObject, HeaderObject, HeadersObject, IExtensionName, IExtensionType, ISpecificationExtension, InfoObject, LicenseObject, LinkObject, LinkParametersObject, LinksObject, MediaTypeObject, OAuthFlowObject, OAuthFlowsObject, OpenAPIObject, OperationObject, ParameterLocation, ParameterObject, ParameterStyle, PathItemObject, PathObject, PathsObject, ReferenceObject, RequestBodyObject, ResponseObject, ResponsesObject, SchemaObject, SchemaObjectType, SchemasObject, ScopesObject, SecurityRequirementObject, SecuritySchemeObject, SecuritySchemeType, ServerObject, ServerVariableObject, TagObject, XmlObject };
|
|
7
|
-
}
|
|
5
|
+
|
|
8
6
|
//#endregion
|
|
9
7
|
//#region src/create/schema/schema.d.ts
|
|
10
8
|
interface SchemaResult {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createComponents, createPaths, createRegistry, createSchema } from "./components-
|
|
1
|
+
import { createComponents, createPaths, createRegistry, createSchema } from "./components-8XHv_FhV.js";
|
|
2
2
|
|
|
3
3
|
//#region src/create/document.ts
|
|
4
4
|
const createDocument = (zodOpenApiObject, opts = {}) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-openapi",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.2",
|
|
4
4
|
"description": "Convert Zod Schemas to OpenAPI v3.x documentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -45,18 +45,18 @@
|
|
|
45
45
|
"@arethetypeswrong/cli": "0.18.2",
|
|
46
46
|
"@changesets/changelog-github": "0.5.1",
|
|
47
47
|
"@changesets/cli": "2.29.6",
|
|
48
|
-
"@redocly/cli": "2.0.
|
|
48
|
+
"@redocly/cli": "2.0.8",
|
|
49
49
|
"@types/node": "22.15.21",
|
|
50
50
|
"@vitest/coverage-v8": "3.2.4",
|
|
51
51
|
"@zod-openapi/openapi3-ts": "1.0.0",
|
|
52
52
|
"ajv": "8.17.1",
|
|
53
53
|
"eslint-plugin-import-zod": "1.2.0",
|
|
54
54
|
"eslint-plugin-zod-openapi": "2.0.0",
|
|
55
|
-
"skuba": "12.
|
|
56
|
-
"tsdown": "0.14.
|
|
55
|
+
"skuba": "12.2.0",
|
|
56
|
+
"tsdown": "0.14.2",
|
|
57
57
|
"vitest": "3.2.4",
|
|
58
58
|
"yaml": "2.8.1",
|
|
59
|
-
"zod": "4.1.
|
|
59
|
+
"zod": "4.1.11"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"zod": "^3.25.74 || ^4.0.0"
|