zod-openapi 5.4.1 → 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-DTiQQs5D.js → components-8XHv_FhV.js} +28 -45
- package/dist/{components-y0WDbAMK.cjs → components-BPKWviAb.cjs} +28 -45
- 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 +2 -2
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 };
|
|
@@ -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)) {
|
|
@@ -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,6 +360,7 @@ 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
366
|
const meta = globalRegistry$1.get(context.zodSchema);
|
|
@@ -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 {
|
|
@@ -32,12 +32,9 @@ const isAnyZodType = (schema) => typeof schema === "object" && schema !== null &
|
|
|
32
32
|
//#endregion
|
|
33
33
|
//#region src/create/examples.ts
|
|
34
34
|
const createExamples = (examples, registry$1, path) => {
|
|
35
|
-
if (!examples) return
|
|
35
|
+
if (!examples) return;
|
|
36
36
|
const examplesObject = {};
|
|
37
|
-
for (const [name, example] of Object.entries(examples))
|
|
38
|
-
const exampleObject = registry$1.addExample(example, [...path, name]);
|
|
39
|
-
examplesObject[name] = exampleObject;
|
|
40
|
-
}
|
|
37
|
+
for (const [name, example] of Object.entries(examples)) examplesObject[name] = registry$1.addExample(example, [...path, name]);
|
|
41
38
|
return examplesObject;
|
|
42
39
|
};
|
|
43
40
|
|
|
@@ -46,13 +43,11 @@ const createExamples = (examples, registry$1, path) => {
|
|
|
46
43
|
const createMediaTypeObject = (mediaType, ctx, path) => {
|
|
47
44
|
const { schema, examples,...rest } = mediaType;
|
|
48
45
|
const mediaTypeObject = rest;
|
|
49
|
-
if (isAnyZodType(schema)) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
mediaTypeObject.schema = schemaObject;
|
|
55
|
-
} 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;
|
|
56
51
|
if (examples) mediaTypeObject.examples = createExamples(examples, ctx.registry, [...path, "examples"]);
|
|
57
52
|
return mediaTypeObject;
|
|
58
53
|
};
|
|
@@ -83,14 +78,11 @@ const isRequired = (zodType, io) => {
|
|
|
83
78
|
//#endregion
|
|
84
79
|
//#region src/create/headers.ts
|
|
85
80
|
const createHeaders = (headers, registry$1, path) => {
|
|
86
|
-
if (!headers) return
|
|
81
|
+
if (!headers) return;
|
|
87
82
|
if (isAnyZodType(headers)) {
|
|
88
83
|
const zodObject = unwrapZodObject(headers, "output", path);
|
|
89
84
|
const headersObject = {};
|
|
90
|
-
for (const [key, zodSchema] of Object.entries(zodObject._zod.def.shape))
|
|
91
|
-
const header = registry$1.addHeader(zodSchema, [...path, key]);
|
|
92
|
-
headersObject[key] = header;
|
|
93
|
-
}
|
|
85
|
+
for (const [key, zodSchema] of Object.entries(zodObject._zod.def.shape)) headersObject[key] = registry$1.addHeader(zodSchema, [...path, key]);
|
|
94
86
|
return headersObject;
|
|
95
87
|
}
|
|
96
88
|
return headers;
|
|
@@ -99,19 +91,16 @@ const createHeaders = (headers, registry$1, path) => {
|
|
|
99
91
|
//#endregion
|
|
100
92
|
//#region src/create/links.ts
|
|
101
93
|
const createLinks = (links, registry$1, path) => {
|
|
102
|
-
if (!links) return
|
|
94
|
+
if (!links) return;
|
|
103
95
|
const linksObject = {};
|
|
104
|
-
for (const [name, link] of Object.entries(links))
|
|
105
|
-
const linkObject = registry$1.addLink(link, [...path, name]);
|
|
106
|
-
linksObject[name] = linkObject;
|
|
107
|
-
}
|
|
96
|
+
for (const [name, link] of Object.entries(links)) linksObject[name] = registry$1.addLink(link, [...path, name]);
|
|
108
97
|
return linksObject;
|
|
109
98
|
};
|
|
110
99
|
|
|
111
100
|
//#endregion
|
|
112
101
|
//#region src/create/parameters.ts
|
|
113
102
|
const createManualParameters = (parameters, registry$1, path) => {
|
|
114
|
-
if (!parameters) return
|
|
103
|
+
if (!parameters) return;
|
|
115
104
|
const parameterObjects = [];
|
|
116
105
|
for (const parameter of parameters) {
|
|
117
106
|
if (isAnyZodType(parameter)) {
|
|
@@ -124,7 +113,7 @@ const createManualParameters = (parameters, registry$1, path) => {
|
|
|
124
113
|
return parameterObjects;
|
|
125
114
|
};
|
|
126
115
|
const createParameters = (requestParams, registry$1, path) => {
|
|
127
|
-
if (!requestParams) return
|
|
116
|
+
if (!requestParams) return;
|
|
128
117
|
const parameterObjects = [];
|
|
129
118
|
for (const [location, schema] of Object.entries(requestParams ?? {})) {
|
|
130
119
|
const zodObject = unwrapZodObject(schema, "input", path);
|
|
@@ -150,7 +139,7 @@ const isISpecificationExtension = (key) => key.startsWith("x-");
|
|
|
150
139
|
//#endregion
|
|
151
140
|
//#region src/create/callbacks.ts
|
|
152
141
|
const createCallbacks = (callbacks, registry$1, path) => {
|
|
153
|
-
if (!callbacks) return
|
|
142
|
+
if (!callbacks) return;
|
|
154
143
|
const callbacksObject = {};
|
|
155
144
|
for (const [name, value] of Object.entries(callbacks)) {
|
|
156
145
|
if (isISpecificationExtension(name)) {
|
|
@@ -165,7 +154,7 @@ const createCallbacks = (callbacks, registry$1, path) => {
|
|
|
165
154
|
//#endregion
|
|
166
155
|
//#region src/create/responses.ts
|
|
167
156
|
const createResponses = (responses, registry$1, path) => {
|
|
168
|
-
if (!responses) return
|
|
157
|
+
if (!responses) return;
|
|
169
158
|
const responsesObject = {};
|
|
170
159
|
for (const [statusCode, response] of Object.entries(responses)) {
|
|
171
160
|
if (!response) continue;
|
|
@@ -177,8 +166,7 @@ const createResponses = (responses, registry$1, path) => {
|
|
|
177
166
|
responsesObject[statusCode] = response;
|
|
178
167
|
continue;
|
|
179
168
|
}
|
|
180
|
-
|
|
181
|
-
responsesObject[statusCode] = responseObject;
|
|
169
|
+
responsesObject[statusCode] = registry$1.addResponse(response, [...path, statusCode]);
|
|
182
170
|
}
|
|
183
171
|
return responsesObject;
|
|
184
172
|
};
|
|
@@ -200,7 +188,7 @@ const createOperation = (operation, registry$1, path) => {
|
|
|
200
188
|
return operationObject;
|
|
201
189
|
};
|
|
202
190
|
const createPaths = (paths, registry$1, path) => {
|
|
203
|
-
if (!paths) return
|
|
191
|
+
if (!paths) return;
|
|
204
192
|
const pathsObject = {};
|
|
205
193
|
for (const [singlePath, pathItemObject] of Object.entries(paths)) {
|
|
206
194
|
if (isISpecificationExtension(singlePath)) {
|
|
@@ -323,8 +311,7 @@ const renameComponents = (components, outputIds, ctx, refPath) => {
|
|
|
323
311
|
componentDependencies.set(key, { dependencies });
|
|
324
312
|
}
|
|
325
313
|
for (const [key] of stringifiedComponents) {
|
|
326
|
-
|
|
327
|
-
if (!registeredComponent) continue;
|
|
314
|
+
if (!ctx.registry.components.schemas.ids.get(key)) continue;
|
|
328
315
|
if (isDependencyPure(componentDependencies, stringifiedComponents, ctx.registry, key)) continue;
|
|
329
316
|
const newName = outputIds.get(key) ?? `${key}${ctx.opts.outputIdSuffix ?? "Output"}`;
|
|
330
317
|
componentsToRename.set(key, newName);
|
|
@@ -352,11 +339,7 @@ const isDependencyPure = (componentDependencies, stringifiedComponents, registry
|
|
|
352
339
|
|
|
353
340
|
//#endregion
|
|
354
341
|
//#region src/create/schema/schema.ts
|
|
355
|
-
const createSchema = (schema, ctx = {
|
|
356
|
-
registry: createRegistry(),
|
|
357
|
-
io: "output",
|
|
358
|
-
opts: {}
|
|
359
|
-
}) => {
|
|
342
|
+
const createSchema = (schema, ctx = {}) => {
|
|
360
343
|
ctx.registry ??= createRegistry({ schemas: ctx.schemaComponents });
|
|
361
344
|
ctx.opts ??= {};
|
|
362
345
|
ctx.io ??= "output";
|
|
@@ -402,6 +385,7 @@ const createSchemas = (schemas, ctx) => {
|
|
|
402
385
|
zodRegistry.add((0, zod_v4.object)(entries), { id: "zodOpenApiCreateSchema" });
|
|
403
386
|
for (const [id, { zodType }] of ctx.registry.components.schemas.manual) zodRegistry.add(zodType, { id });
|
|
404
387
|
const outputIds = /* @__PURE__ */ new Map();
|
|
388
|
+
const defsName = satisfiesVersion(ctx.openapiVersion ?? "3.1.0", "3.1.0") ? "$defs" : "definitions";
|
|
405
389
|
const jsonSchema = (0, zod_v4.toJSONSchema)(zodRegistry, {
|
|
406
390
|
override(context) {
|
|
407
391
|
const meta = zod_v4.globalRegistry.get(context.zodSchema);
|
|
@@ -430,10 +414,10 @@ const createSchemas = (schemas, ctx) => {
|
|
|
430
414
|
reused: ctx.opts.reused,
|
|
431
415
|
cycles: ctx.opts.cycles,
|
|
432
416
|
target: satisfiesVersion(ctx.openapiVersion ?? "3.1.0", "3.1.0") ? void 0 : "openapi-3.0",
|
|
433
|
-
uri: (id) => id === "__shared" ? `#ZOD_OPENAPI/${id}` : `#ZOD_OPENAPI/__shared#/$
|
|
417
|
+
uri: (id) => id === "__shared" ? `#ZOD_OPENAPI/${id}` : `#ZOD_OPENAPI/__shared#/${defsName}/${id}`
|
|
434
418
|
});
|
|
435
|
-
const components = jsonSchema.schemas.__shared
|
|
436
|
-
jsonSchema.schemas.__shared ??= {
|
|
419
|
+
const components = jsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
420
|
+
jsonSchema.schemas.__shared ??= { [defsName]: components };
|
|
437
421
|
const dynamicComponents = /* @__PURE__ */ new Map();
|
|
438
422
|
for (const [key, value] of Object.entries(components)) {
|
|
439
423
|
deleteInvalidJsonSchemaFields(value);
|
|
@@ -452,15 +436,14 @@ const createSchemas = (schemas, ctx) => {
|
|
|
452
436
|
deleteInvalidJsonSchemaFields(manualComponent);
|
|
453
437
|
}
|
|
454
438
|
const manualUsed = {};
|
|
455
|
-
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) => {
|
|
456
440
|
const dynamic = dynamicComponents.get(match);
|
|
457
441
|
if (dynamic) return dynamic;
|
|
458
|
-
|
|
459
|
-
if (manualComponent) manualUsed[match] = true;
|
|
442
|
+
if (ctx.registry.components.schemas.manual.get(match)) manualUsed[match] = true;
|
|
460
443
|
return `"${refPath}${match}"`;
|
|
461
444
|
}));
|
|
462
|
-
const parsedComponents = parsedJsonSchema.schemas.__shared
|
|
463
|
-
parsedJsonSchema.schemas.__shared ??= {
|
|
445
|
+
const parsedComponents = parsedJsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
446
|
+
parsedJsonSchema.schemas.__shared ??= { [defsName]: parsedComponents };
|
|
464
447
|
for (const [key] of ctx.registry.components.schemas.manual) {
|
|
465
448
|
const manualComponent = parsedJsonSchema.schemas[key];
|
|
466
449
|
if (!manualComponent) continue;
|
|
@@ -486,7 +469,7 @@ const createSchemas = (schemas, ctx) => {
|
|
|
486
469
|
return `"${refPath}${match}"`;
|
|
487
470
|
}));
|
|
488
471
|
const renamedSchemas = renamedJsonSchema.schemas.zodOpenApiCreateSchema?.properties;
|
|
489
|
-
const renamedComponents = renamedJsonSchema.schemas.__shared
|
|
472
|
+
const renamedComponents = renamedJsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
490
473
|
delete renamedJsonSchema.schemas.zodOpenApiCreateSchema;
|
|
491
474
|
delete renamedJsonSchema.schemas.__shared;
|
|
492
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",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
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"
|