zod-openapi 5.4.1 → 5.4.3
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
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-DV_-zLJ6.js";
|
|
2
2
|
|
|
3
3
|
export { createComponents, createRegistry, isAnyZodType, unwrapZodObject };
|
|
@@ -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,14 +311,12 @@ 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);
|
|
331
318
|
components[newName] = components[key];
|
|
332
319
|
delete components[key];
|
|
333
|
-
continue;
|
|
334
320
|
}
|
|
335
321
|
return componentsToRename;
|
|
336
322
|
};
|
|
@@ -352,11 +338,7 @@ const isDependencyPure = (componentDependencies, stringifiedComponents, registry
|
|
|
352
338
|
|
|
353
339
|
//#endregion
|
|
354
340
|
//#region src/create/schema/schema.ts
|
|
355
|
-
const createSchema = (schema, ctx = {
|
|
356
|
-
registry: createRegistry(),
|
|
357
|
-
io: "output",
|
|
358
|
-
opts: {}
|
|
359
|
-
}) => {
|
|
341
|
+
const createSchema = (schema, ctx = {}) => {
|
|
360
342
|
ctx.registry ??= createRegistry({ schemas: ctx.schemaComponents });
|
|
361
343
|
ctx.opts ??= {};
|
|
362
344
|
ctx.io ??= "output";
|
|
@@ -402,6 +384,7 @@ const createSchemas = (schemas, ctx) => {
|
|
|
402
384
|
zodRegistry.add((0, zod_v4.object)(entries), { id: "zodOpenApiCreateSchema" });
|
|
403
385
|
for (const [id, { zodType }] of ctx.registry.components.schemas.manual) zodRegistry.add(zodType, { id });
|
|
404
386
|
const outputIds = /* @__PURE__ */ new Map();
|
|
387
|
+
const defsName = satisfiesVersion(ctx.openapiVersion ?? "3.1.0", "3.1.0") ? "$defs" : "definitions";
|
|
405
388
|
const jsonSchema = (0, zod_v4.toJSONSchema)(zodRegistry, {
|
|
406
389
|
override(context) {
|
|
407
390
|
const meta = zod_v4.globalRegistry.get(context.zodSchema);
|
|
@@ -430,10 +413,10 @@ const createSchemas = (schemas, ctx) => {
|
|
|
430
413
|
reused: ctx.opts.reused,
|
|
431
414
|
cycles: ctx.opts.cycles,
|
|
432
415
|
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#/$
|
|
416
|
+
uri: (id) => id === "__shared" ? `#ZOD_OPENAPI/${id}` : `#ZOD_OPENAPI/__shared#/${defsName}/${id}`
|
|
434
417
|
});
|
|
435
|
-
const components = jsonSchema.schemas.__shared
|
|
436
|
-
jsonSchema.schemas.__shared ??= {
|
|
418
|
+
const components = jsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
419
|
+
jsonSchema.schemas.__shared ??= { [defsName]: components };
|
|
437
420
|
const dynamicComponents = /* @__PURE__ */ new Map();
|
|
438
421
|
for (const [key, value] of Object.entries(components)) {
|
|
439
422
|
deleteInvalidJsonSchemaFields(value);
|
|
@@ -452,15 +435,14 @@ const createSchemas = (schemas, ctx) => {
|
|
|
452
435
|
deleteInvalidJsonSchemaFields(manualComponent);
|
|
453
436
|
}
|
|
454
437
|
const manualUsed = {};
|
|
455
|
-
const parsedJsonSchema = JSON.parse(JSON.stringify(jsonSchema).replace(/"#ZOD_OPENAPI\/__shared
|
|
438
|
+
const parsedJsonSchema = JSON.parse(JSON.stringify(jsonSchema).replace(/"#ZOD_OPENAPI\/__shared#\/(?:\$defs|definitions)\/([^"]+)"/g, (_, match) => {
|
|
456
439
|
const dynamic = dynamicComponents.get(match);
|
|
457
440
|
if (dynamic) return dynamic;
|
|
458
|
-
|
|
459
|
-
if (manualComponent) manualUsed[match] = true;
|
|
441
|
+
if (ctx.registry.components.schemas.manual.get(match)) manualUsed[match] = true;
|
|
460
442
|
return `"${refPath}${match}"`;
|
|
461
443
|
}));
|
|
462
|
-
const parsedComponents = parsedJsonSchema.schemas.__shared
|
|
463
|
-
parsedJsonSchema.schemas.__shared ??= {
|
|
444
|
+
const parsedComponents = parsedJsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
445
|
+
parsedJsonSchema.schemas.__shared ??= { [defsName]: parsedComponents };
|
|
464
446
|
for (const [key] of ctx.registry.components.schemas.manual) {
|
|
465
447
|
const manualComponent = parsedJsonSchema.schemas[key];
|
|
466
448
|
if (!manualComponent) continue;
|
|
@@ -486,7 +468,7 @@ const createSchemas = (schemas, ctx) => {
|
|
|
486
468
|
return `"${refPath}${match}"`;
|
|
487
469
|
}));
|
|
488
470
|
const renamedSchemas = renamedJsonSchema.schemas.zodOpenApiCreateSchema?.properties;
|
|
489
|
-
const renamedComponents = renamedJsonSchema.schemas.__shared
|
|
471
|
+
const renamedComponents = renamedJsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
490
472
|
delete renamedJsonSchema.schemas.zodOpenApiCreateSchema;
|
|
491
473
|
delete renamedJsonSchema.schemas.__shared;
|
|
492
474
|
return {
|
|
@@ -923,8 +905,7 @@ const createIOSchemas = (ctx) => {
|
|
|
923
905
|
};
|
|
924
906
|
const createManualSchemas = (registry$1) => {
|
|
925
907
|
for (const [key, value] of registry$1.components.schemas.manual) if (!value.input.used) {
|
|
926
|
-
const
|
|
927
|
-
const schema = value[io].schemaObject;
|
|
908
|
+
const schema = value[zod_v4_core.globalRegistry.get(value.zodType)?.unusedIO ?? "output"].schemaObject;
|
|
928
909
|
registry$1.components.schemas.ids.set(key, schema);
|
|
929
910
|
}
|
|
930
911
|
};
|
|
@@ -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,14 +286,12 @@ 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);
|
|
306
293
|
components[newName] = components[key];
|
|
307
294
|
delete components[key];
|
|
308
|
-
continue;
|
|
309
295
|
}
|
|
310
296
|
return componentsToRename;
|
|
311
297
|
};
|
|
@@ -327,11 +313,7 @@ const isDependencyPure = (componentDependencies, stringifiedComponents, registry
|
|
|
327
313
|
|
|
328
314
|
//#endregion
|
|
329
315
|
//#region src/create/schema/schema.ts
|
|
330
|
-
const createSchema = (schema, ctx = {
|
|
331
|
-
registry: createRegistry(),
|
|
332
|
-
io: "output",
|
|
333
|
-
opts: {}
|
|
334
|
-
}) => {
|
|
316
|
+
const createSchema = (schema, ctx = {}) => {
|
|
335
317
|
ctx.registry ??= createRegistry({ schemas: ctx.schemaComponents });
|
|
336
318
|
ctx.opts ??= {};
|
|
337
319
|
ctx.io ??= "output";
|
|
@@ -377,6 +359,7 @@ const createSchemas = (schemas, ctx) => {
|
|
|
377
359
|
zodRegistry.add(object(entries), { id: "zodOpenApiCreateSchema" });
|
|
378
360
|
for (const [id, { zodType }] of ctx.registry.components.schemas.manual) zodRegistry.add(zodType, { id });
|
|
379
361
|
const outputIds = /* @__PURE__ */ new Map();
|
|
362
|
+
const defsName = satisfiesVersion(ctx.openapiVersion ?? "3.1.0", "3.1.0") ? "$defs" : "definitions";
|
|
380
363
|
const jsonSchema = toJSONSchema$1(zodRegistry, {
|
|
381
364
|
override(context) {
|
|
382
365
|
const meta = globalRegistry$1.get(context.zodSchema);
|
|
@@ -405,10 +388,10 @@ const createSchemas = (schemas, ctx) => {
|
|
|
405
388
|
reused: ctx.opts.reused,
|
|
406
389
|
cycles: ctx.opts.cycles,
|
|
407
390
|
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#/$
|
|
391
|
+
uri: (id) => id === "__shared" ? `#ZOD_OPENAPI/${id}` : `#ZOD_OPENAPI/__shared#/${defsName}/${id}`
|
|
409
392
|
});
|
|
410
|
-
const components = jsonSchema.schemas.__shared
|
|
411
|
-
jsonSchema.schemas.__shared ??= {
|
|
393
|
+
const components = jsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
394
|
+
jsonSchema.schemas.__shared ??= { [defsName]: components };
|
|
412
395
|
const dynamicComponents = /* @__PURE__ */ new Map();
|
|
413
396
|
for (const [key, value] of Object.entries(components)) {
|
|
414
397
|
deleteInvalidJsonSchemaFields(value);
|
|
@@ -427,15 +410,14 @@ const createSchemas = (schemas, ctx) => {
|
|
|
427
410
|
deleteInvalidJsonSchemaFields(manualComponent);
|
|
428
411
|
}
|
|
429
412
|
const manualUsed = {};
|
|
430
|
-
const parsedJsonSchema = JSON.parse(JSON.stringify(jsonSchema).replace(/"#ZOD_OPENAPI\/__shared
|
|
413
|
+
const parsedJsonSchema = JSON.parse(JSON.stringify(jsonSchema).replace(/"#ZOD_OPENAPI\/__shared#\/(?:\$defs|definitions)\/([^"]+)"/g, (_, match) => {
|
|
431
414
|
const dynamic = dynamicComponents.get(match);
|
|
432
415
|
if (dynamic) return dynamic;
|
|
433
|
-
|
|
434
|
-
if (manualComponent) manualUsed[match] = true;
|
|
416
|
+
if (ctx.registry.components.schemas.manual.get(match)) manualUsed[match] = true;
|
|
435
417
|
return `"${refPath}${match}"`;
|
|
436
418
|
}));
|
|
437
|
-
const parsedComponents = parsedJsonSchema.schemas.__shared
|
|
438
|
-
parsedJsonSchema.schemas.__shared ??= {
|
|
419
|
+
const parsedComponents = parsedJsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
420
|
+
parsedJsonSchema.schemas.__shared ??= { [defsName]: parsedComponents };
|
|
439
421
|
for (const [key] of ctx.registry.components.schemas.manual) {
|
|
440
422
|
const manualComponent = parsedJsonSchema.schemas[key];
|
|
441
423
|
if (!manualComponent) continue;
|
|
@@ -461,7 +443,7 @@ const createSchemas = (schemas, ctx) => {
|
|
|
461
443
|
return `"${refPath}${match}"`;
|
|
462
444
|
}));
|
|
463
445
|
const renamedSchemas = renamedJsonSchema.schemas.zodOpenApiCreateSchema?.properties;
|
|
464
|
-
const renamedComponents = renamedJsonSchema.schemas.__shared
|
|
446
|
+
const renamedComponents = renamedJsonSchema.schemas.__shared?.[defsName] ?? {};
|
|
465
447
|
delete renamedJsonSchema.schemas.zodOpenApiCreateSchema;
|
|
466
448
|
delete renamedJsonSchema.schemas.__shared;
|
|
467
449
|
return {
|
|
@@ -898,8 +880,7 @@ const createIOSchemas = (ctx) => {
|
|
|
898
880
|
};
|
|
899
881
|
const createManualSchemas = (registry$1) => {
|
|
900
882
|
for (const [key, value] of registry$1.components.schemas.manual) if (!value.input.used) {
|
|
901
|
-
const
|
|
902
|
-
const schema = value[io].schemaObject;
|
|
883
|
+
const schema = value[globalRegistry.get(value.zodType)?.unusedIO ?? "output"].schemaObject;
|
|
903
884
|
registry$1.components.schemas.ids.set(key, schema);
|
|
904
885
|
}
|
|
905
886
|
};
|
package/dist/index.cjs
CHANGED
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-DV_-zLJ6.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.3",
|
|
4
4
|
"description": "Convert Zod Schemas to OpenAPI v3.x documentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"eslint-plugin-import-zod": "1.2.0",
|
|
54
54
|
"eslint-plugin-zod-openapi": "2.0.0",
|
|
55
55
|
"skuba": "12.2.0",
|
|
56
|
-
"tsdown": "0.
|
|
56
|
+
"tsdown": "0.15.6",
|
|
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"
|