zod-openapi 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/components.chunk.cjs +37 -11
- package/dist/components.chunk.mjs +37 -11
- package/dist/create/parameters.d.ts +2 -2
- package/dist/create/schema/single.d.ts +4 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -276,6 +276,7 @@ const { schema, components } = createSchema(job, {
|
|
|
276
276
|
schemaType: 'input'; // This controls whether this should be rendered as a request (`input`) or response (`output`). Defaults to `output`
|
|
277
277
|
openapi: '3.0.0'; // OpenAPI version to use, defaults to `'3.1.0'`
|
|
278
278
|
components: { jobId: z.string() } // Additional components to use and create while rendering the schema
|
|
279
|
+
componentRefPath: '#/definitions/' // Defaults to #/components/schemas/
|
|
279
280
|
})
|
|
280
281
|
```
|
|
281
282
|
|
|
@@ -653,7 +653,7 @@ const createObjectSchema = (zodObject, state) => {
|
|
|
653
653
|
);
|
|
654
654
|
};
|
|
655
655
|
const createExtendedSchema = (zodObject, baseZodObject, state) => {
|
|
656
|
-
var _a;
|
|
656
|
+
var _a, _b;
|
|
657
657
|
if (!baseZodObject) {
|
|
658
658
|
return void 0;
|
|
659
659
|
}
|
|
@@ -693,7 +693,14 @@ const createExtendedSchema = (zodObject, baseZodObject, state) => {
|
|
|
693
693
|
return {
|
|
694
694
|
type: "schema",
|
|
695
695
|
schema: {
|
|
696
|
-
allOf: [
|
|
696
|
+
allOf: [
|
|
697
|
+
{
|
|
698
|
+
$ref: createComponentSchemaRef(
|
|
699
|
+
completeComponent.ref,
|
|
700
|
+
(_b = state.documentOptions) == null ? void 0 : _b.componentRefPath
|
|
701
|
+
)
|
|
702
|
+
}
|
|
703
|
+
],
|
|
697
704
|
...extendedSchema.schema
|
|
698
705
|
},
|
|
699
706
|
effects: flattenEffects([
|
|
@@ -1281,6 +1288,7 @@ const createNewSchema = (zodSchema, state) => {
|
|
|
1281
1288
|
return schemaWithMetadata;
|
|
1282
1289
|
};
|
|
1283
1290
|
const createNewRef = (ref, zodSchema, state) => {
|
|
1291
|
+
var _a;
|
|
1284
1292
|
state.components.schemas.set(zodSchema, {
|
|
1285
1293
|
type: "in-progress",
|
|
1286
1294
|
ref
|
|
@@ -1297,7 +1305,12 @@ const createNewRef = (ref, zodSchema, state) => {
|
|
|
1297
1305
|
});
|
|
1298
1306
|
return {
|
|
1299
1307
|
type: "ref",
|
|
1300
|
-
schema: {
|
|
1308
|
+
schema: {
|
|
1309
|
+
$ref: createComponentSchemaRef(
|
|
1310
|
+
ref,
|
|
1311
|
+
(_a = state.documentOptions) == null ? void 0 : _a.componentRefPath
|
|
1312
|
+
)
|
|
1313
|
+
},
|
|
1301
1314
|
effects: newSchema.effects ? [
|
|
1302
1315
|
{
|
|
1303
1316
|
type: "component",
|
|
@@ -1309,10 +1322,16 @@ const createNewRef = (ref, zodSchema, state) => {
|
|
|
1309
1322
|
};
|
|
1310
1323
|
};
|
|
1311
1324
|
const createExistingRef = (zodSchema, component, state) => {
|
|
1325
|
+
var _a, _b;
|
|
1312
1326
|
if (component && component.type === "complete") {
|
|
1313
1327
|
return {
|
|
1314
1328
|
type: "ref",
|
|
1315
|
-
schema: {
|
|
1329
|
+
schema: {
|
|
1330
|
+
$ref: createComponentSchemaRef(
|
|
1331
|
+
component.ref,
|
|
1332
|
+
(_a = state.documentOptions) == null ? void 0 : _a.componentRefPath
|
|
1333
|
+
)
|
|
1334
|
+
},
|
|
1316
1335
|
effects: component.effects ? [
|
|
1317
1336
|
{
|
|
1318
1337
|
type: "component",
|
|
@@ -1326,7 +1345,12 @@ const createExistingRef = (zodSchema, component, state) => {
|
|
|
1326
1345
|
if (component && component.type === "in-progress") {
|
|
1327
1346
|
return {
|
|
1328
1347
|
type: "ref",
|
|
1329
|
-
schema: {
|
|
1348
|
+
schema: {
|
|
1349
|
+
$ref: createComponentSchemaRef(
|
|
1350
|
+
component.ref,
|
|
1351
|
+
(_b = state.documentOptions) == null ? void 0 : _b.componentRefPath
|
|
1352
|
+
)
|
|
1353
|
+
},
|
|
1330
1354
|
effects: [
|
|
1331
1355
|
{
|
|
1332
1356
|
type: "component",
|
|
@@ -1436,7 +1460,7 @@ const createBaseParameter = (schema, components, subpath, documentOptions) => {
|
|
|
1436
1460
|
...required && { required }
|
|
1437
1461
|
};
|
|
1438
1462
|
};
|
|
1439
|
-
const createParamOrRef = (zodSchema, components, subpath,
|
|
1463
|
+
const createParamOrRef = (zodSchema, components, subpath, type, name, documentOptions) => {
|
|
1440
1464
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1441
1465
|
const component = components.parameters.get(zodSchema);
|
|
1442
1466
|
const paramType = ((_c = (_b = (_a = zodSchema._def) == null ? void 0 : _a.openapi) == null ? void 0 : _b.param) == null ? void 0 : _c.in) ?? (component == null ? void 0 : component.in) ?? type;
|
|
@@ -1494,9 +1518,9 @@ const createParameters = (type, zodObjectType, components, subpath, documentOpti
|
|
|
1494
1518
|
zodSchema,
|
|
1495
1519
|
components,
|
|
1496
1520
|
[...subpath, key],
|
|
1497
|
-
documentOptions,
|
|
1498
1521
|
type,
|
|
1499
|
-
key
|
|
1522
|
+
key,
|
|
1523
|
+
documentOptions
|
|
1500
1524
|
)
|
|
1501
1525
|
);
|
|
1502
1526
|
};
|
|
@@ -1540,6 +1564,8 @@ const createManualParameters = (parameters, components, subpath, documentOptions
|
|
|
1540
1564
|
param,
|
|
1541
1565
|
components,
|
|
1542
1566
|
[...subpath, `param index ${index}`],
|
|
1567
|
+
void 0,
|
|
1568
|
+
void 0,
|
|
1543
1569
|
documentOptions
|
|
1544
1570
|
);
|
|
1545
1571
|
}
|
|
@@ -1996,7 +2022,7 @@ const getCallbacks = (callbacks, components) => {
|
|
|
1996
2022
|
});
|
|
1997
2023
|
});
|
|
1998
2024
|
};
|
|
1999
|
-
const createComponentSchemaRef = (schemaRef) =>
|
|
2025
|
+
const createComponentSchemaRef = (schemaRef, componentPath) => `${componentPath ?? "#/components/schemas/"}${schemaRef}`;
|
|
2000
2026
|
const createComponentResponseRef = (responseRef) => `#/components/responses/${responseRef}`;
|
|
2001
2027
|
const createComponentRequestBodyRef = (requestBodyRef) => `#/components/requestBodies/${requestBodyRef}`;
|
|
2002
2028
|
const createComponentCallbackRef = (callbackRef) => `#/components/callbacks/${callbackRef}`;
|
|
@@ -2087,9 +2113,9 @@ const createParamComponents = (componentsObject, components, documentOptions) =>
|
|
|
2087
2113
|
schema,
|
|
2088
2114
|
components,
|
|
2089
2115
|
[`component parameter index ${index}`],
|
|
2090
|
-
documentOptions,
|
|
2091
2116
|
component.in,
|
|
2092
|
-
component.ref
|
|
2117
|
+
component.ref,
|
|
2118
|
+
documentOptions
|
|
2093
2119
|
);
|
|
2094
2120
|
}
|
|
2095
2121
|
});
|
|
@@ -652,7 +652,7 @@ const createObjectSchema = (zodObject, state) => {
|
|
|
652
652
|
);
|
|
653
653
|
};
|
|
654
654
|
const createExtendedSchema = (zodObject, baseZodObject, state) => {
|
|
655
|
-
var _a;
|
|
655
|
+
var _a, _b;
|
|
656
656
|
if (!baseZodObject) {
|
|
657
657
|
return void 0;
|
|
658
658
|
}
|
|
@@ -692,7 +692,14 @@ const createExtendedSchema = (zodObject, baseZodObject, state) => {
|
|
|
692
692
|
return {
|
|
693
693
|
type: "schema",
|
|
694
694
|
schema: {
|
|
695
|
-
allOf: [
|
|
695
|
+
allOf: [
|
|
696
|
+
{
|
|
697
|
+
$ref: createComponentSchemaRef(
|
|
698
|
+
completeComponent.ref,
|
|
699
|
+
(_b = state.documentOptions) == null ? void 0 : _b.componentRefPath
|
|
700
|
+
)
|
|
701
|
+
}
|
|
702
|
+
],
|
|
696
703
|
...extendedSchema.schema
|
|
697
704
|
},
|
|
698
705
|
effects: flattenEffects([
|
|
@@ -1280,6 +1287,7 @@ const createNewSchema = (zodSchema, state) => {
|
|
|
1280
1287
|
return schemaWithMetadata;
|
|
1281
1288
|
};
|
|
1282
1289
|
const createNewRef = (ref, zodSchema, state) => {
|
|
1290
|
+
var _a;
|
|
1283
1291
|
state.components.schemas.set(zodSchema, {
|
|
1284
1292
|
type: "in-progress",
|
|
1285
1293
|
ref
|
|
@@ -1296,7 +1304,12 @@ const createNewRef = (ref, zodSchema, state) => {
|
|
|
1296
1304
|
});
|
|
1297
1305
|
return {
|
|
1298
1306
|
type: "ref",
|
|
1299
|
-
schema: {
|
|
1307
|
+
schema: {
|
|
1308
|
+
$ref: createComponentSchemaRef(
|
|
1309
|
+
ref,
|
|
1310
|
+
(_a = state.documentOptions) == null ? void 0 : _a.componentRefPath
|
|
1311
|
+
)
|
|
1312
|
+
},
|
|
1300
1313
|
effects: newSchema.effects ? [
|
|
1301
1314
|
{
|
|
1302
1315
|
type: "component",
|
|
@@ -1308,10 +1321,16 @@ const createNewRef = (ref, zodSchema, state) => {
|
|
|
1308
1321
|
};
|
|
1309
1322
|
};
|
|
1310
1323
|
const createExistingRef = (zodSchema, component, state) => {
|
|
1324
|
+
var _a, _b;
|
|
1311
1325
|
if (component && component.type === "complete") {
|
|
1312
1326
|
return {
|
|
1313
1327
|
type: "ref",
|
|
1314
|
-
schema: {
|
|
1328
|
+
schema: {
|
|
1329
|
+
$ref: createComponentSchemaRef(
|
|
1330
|
+
component.ref,
|
|
1331
|
+
(_a = state.documentOptions) == null ? void 0 : _a.componentRefPath
|
|
1332
|
+
)
|
|
1333
|
+
},
|
|
1315
1334
|
effects: component.effects ? [
|
|
1316
1335
|
{
|
|
1317
1336
|
type: "component",
|
|
@@ -1325,7 +1344,12 @@ const createExistingRef = (zodSchema, component, state) => {
|
|
|
1325
1344
|
if (component && component.type === "in-progress") {
|
|
1326
1345
|
return {
|
|
1327
1346
|
type: "ref",
|
|
1328
|
-
schema: {
|
|
1347
|
+
schema: {
|
|
1348
|
+
$ref: createComponentSchemaRef(
|
|
1349
|
+
component.ref,
|
|
1350
|
+
(_b = state.documentOptions) == null ? void 0 : _b.componentRefPath
|
|
1351
|
+
)
|
|
1352
|
+
},
|
|
1329
1353
|
effects: [
|
|
1330
1354
|
{
|
|
1331
1355
|
type: "component",
|
|
@@ -1435,7 +1459,7 @@ const createBaseParameter = (schema, components, subpath, documentOptions) => {
|
|
|
1435
1459
|
...required && { required }
|
|
1436
1460
|
};
|
|
1437
1461
|
};
|
|
1438
|
-
const createParamOrRef = (zodSchema, components, subpath,
|
|
1462
|
+
const createParamOrRef = (zodSchema, components, subpath, type, name, documentOptions) => {
|
|
1439
1463
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1440
1464
|
const component = components.parameters.get(zodSchema);
|
|
1441
1465
|
const paramType = ((_c = (_b = (_a = zodSchema._def) == null ? void 0 : _a.openapi) == null ? void 0 : _b.param) == null ? void 0 : _c.in) ?? (component == null ? void 0 : component.in) ?? type;
|
|
@@ -1493,9 +1517,9 @@ const createParameters = (type, zodObjectType, components, subpath, documentOpti
|
|
|
1493
1517
|
zodSchema,
|
|
1494
1518
|
components,
|
|
1495
1519
|
[...subpath, key],
|
|
1496
|
-
documentOptions,
|
|
1497
1520
|
type,
|
|
1498
|
-
key
|
|
1521
|
+
key,
|
|
1522
|
+
documentOptions
|
|
1499
1523
|
)
|
|
1500
1524
|
);
|
|
1501
1525
|
};
|
|
@@ -1539,6 +1563,8 @@ const createManualParameters = (parameters, components, subpath, documentOptions
|
|
|
1539
1563
|
param,
|
|
1540
1564
|
components,
|
|
1541
1565
|
[...subpath, `param index ${index}`],
|
|
1566
|
+
void 0,
|
|
1567
|
+
void 0,
|
|
1542
1568
|
documentOptions
|
|
1543
1569
|
);
|
|
1544
1570
|
}
|
|
@@ -1995,7 +2021,7 @@ const getCallbacks = (callbacks, components) => {
|
|
|
1995
2021
|
});
|
|
1996
2022
|
});
|
|
1997
2023
|
};
|
|
1998
|
-
const createComponentSchemaRef = (schemaRef) =>
|
|
2024
|
+
const createComponentSchemaRef = (schemaRef, componentPath) => `${componentPath ?? "#/components/schemas/"}${schemaRef}`;
|
|
1999
2025
|
const createComponentResponseRef = (responseRef) => `#/components/responses/${responseRef}`;
|
|
2000
2026
|
const createComponentRequestBodyRef = (requestBodyRef) => `#/components/requestBodies/${requestBodyRef}`;
|
|
2001
2027
|
const createComponentCallbackRef = (callbackRef) => `#/components/callbacks/${callbackRef}`;
|
|
@@ -2086,9 +2112,9 @@ const createParamComponents = (componentsObject, components, documentOptions) =>
|
|
|
2086
2112
|
schema,
|
|
2087
2113
|
components,
|
|
2088
2114
|
[`component parameter index ${index}`],
|
|
2089
|
-
documentOptions,
|
|
2090
2115
|
component.in,
|
|
2091
|
-
component.ref
|
|
2116
|
+
component.ref,
|
|
2117
|
+
documentOptions
|
|
2092
2118
|
);
|
|
2093
2119
|
}
|
|
2094
2120
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ZodType } from 'zod';
|
|
2
2
|
import { ParameterObject, ReferenceObject } from '../openapi3-ts/dist/model/openapi31.js';
|
|
3
3
|
import { ComponentsObject } from './components.js';
|
|
4
|
-
import {
|
|
4
|
+
import { ZodOpenApiParameters, CreateDocumentOptions } from './document.js';
|
|
5
5
|
|
|
6
|
-
declare const createParamOrRef: (zodSchema: ZodType, components: ComponentsObject, subpath: string[],
|
|
6
|
+
declare const createParamOrRef: (zodSchema: ZodType, components: ComponentsObject, subpath: string[], type?: keyof ZodOpenApiParameters, name?: string, documentOptions?: CreateDocumentOptions) => ParameterObject | ReferenceObject;
|
|
7
7
|
|
|
8
8
|
export { createParamOrRef };
|
|
@@ -22,6 +22,10 @@ interface CreateSchemaOptions extends CreateDocumentOptions {
|
|
|
22
22
|
* Additional components to use and create while rendering the schema
|
|
23
23
|
*/
|
|
24
24
|
components?: Record<string, ZodType>;
|
|
25
|
+
/**
|
|
26
|
+
* The $ref path to use for the component. Defaults to `#/components/schemas/`
|
|
27
|
+
*/
|
|
28
|
+
componentRefPath?: string;
|
|
25
29
|
}
|
|
26
30
|
declare const createSchema: (zodType: ZodType, opts?: CreateSchemaOptions) => SchemaResult;
|
|
27
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod-openapi",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Convert Zod Schemas to OpenAPI v3.x documentation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -74,12 +74,12 @@
|
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@arethetypeswrong/cli": "0.16.4",
|
|
76
76
|
"@crackle/cli": "0.15.5",
|
|
77
|
-
"@redocly/cli": "1.25.
|
|
77
|
+
"@redocly/cli": "1.25.9",
|
|
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
|
-
"skuba": "9.0
|
|
82
|
-
"yaml": "2.
|
|
81
|
+
"skuba": "9.1.0",
|
|
82
|
+
"yaml": "2.6.0",
|
|
83
83
|
"zod": "3.23.8"
|
|
84
84
|
},
|
|
85
85
|
"peerDependencies": {
|