zod-openapi 3.1.1 → 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 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: [{ $ref: createComponentSchemaRef(completeComponent.ref) }],
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: { $ref: createComponentSchemaRef(ref) },
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: { $ref: createComponentSchemaRef(component.ref) },
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: { $ref: createComponentSchemaRef(component.ref) },
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",
@@ -1998,7 +2022,7 @@ const getCallbacks = (callbacks, components) => {
1998
2022
  });
1999
2023
  });
2000
2024
  };
2001
- const createComponentSchemaRef = (schemaRef) => `#/components/schemas/${schemaRef}`;
2025
+ const createComponentSchemaRef = (schemaRef, componentPath) => `${componentPath ?? "#/components/schemas/"}${schemaRef}`;
2002
2026
  const createComponentResponseRef = (responseRef) => `#/components/responses/${responseRef}`;
2003
2027
  const createComponentRequestBodyRef = (requestBodyRef) => `#/components/requestBodies/${requestBodyRef}`;
2004
2028
  const createComponentCallbackRef = (callbackRef) => `#/components/callbacks/${callbackRef}`;
@@ -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: [{ $ref: createComponentSchemaRef(completeComponent.ref) }],
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: { $ref: createComponentSchemaRef(ref) },
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: { $ref: createComponentSchemaRef(component.ref) },
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: { $ref: createComponentSchemaRef(component.ref) },
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",
@@ -1997,7 +2021,7 @@ const getCallbacks = (callbacks, components) => {
1997
2021
  });
1998
2022
  });
1999
2023
  };
2000
- const createComponentSchemaRef = (schemaRef) => `#/components/schemas/${schemaRef}`;
2024
+ const createComponentSchemaRef = (schemaRef, componentPath) => `${componentPath ?? "#/components/schemas/"}${schemaRef}`;
2001
2025
  const createComponentResponseRef = (responseRef) => `#/components/responses/${responseRef}`;
2002
2026
  const createComponentRequestBodyRef = (requestBodyRef) => `#/components/requestBodies/${requestBodyRef}`;
2003
2027
  const createComponentCallbackRef = (callbackRef) => `#/components/callbacks/${callbackRef}`;
@@ -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.1.1",
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.5",
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.1",
82
- "yaml": "2.5.1",
81
+ "skuba": "9.1.0",
82
+ "yaml": "2.6.0",
83
83
  "zod": "3.23.8"
84
84
  },
85
85
  "peerDependencies": {