zod-openapi 4.1.2 → 4.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
@@ -805,7 +805,7 @@ As an example `z.string().nullable()` will be rendered differently
805
805
  - ZodSet
806
806
  - Treated as an array with `uniqueItems` (you may need to add a pre-process to convert it to a set)
807
807
  - ZodString
808
- - `format` mapping for `.url()`, `.uuid()`, `.email()`, `.datetime()`, `.date()`, `.time()`, `.duration()`
808
+ - `format` mapping for `.url()`, `.uuid()`, `.email()`, `.datetime()`, `.date()`, `.time()`, `.duration()`, `.ip({ version: 'v4' })`, `.ip({ version: 'v6' })`, `.cidr({ version: 'v4' })`, `.cidr({ version: 'v6' })`
809
809
  - `minLength`/`maxLength` mapping for `.length()`, `.min()`, `.max()`
810
810
  - `pattern` mapping for `.regex()`, `.startsWith()`, `.endsWith()`, `.includes()`
811
811
  - `contentEncoding` mapping for `.base64()` for OpenAPI 3.1.0+
package/dist/api.cjs CHANGED
@@ -5,3 +5,4 @@ exports.createComponents = components.createComponents;
5
5
  exports.createMediaTypeSchema = components.createMediaTypeSchema;
6
6
  exports.createParamOrRef = components.createParamOrRef;
7
7
  exports.getDefaultComponents = components.getDefaultComponents;
8
+ exports.getZodObject = components.getZodObject;
package/dist/api.d.mts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { ComponentsObject, createComponents, getDefaultComponents } from './create/components.js';
2
2
  export { createMediaTypeSchema } from './create/content.js';
3
- export { createParamOrRef } from './create/parameters.js';
3
+ export { createParamOrRef, getZodObject } from './create/parameters.js';
package/dist/api.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { ComponentsObject, createComponents, getDefaultComponents } from './create/components.js';
2
2
  export { createMediaTypeSchema } from './create/content.js';
3
- export { createParamOrRef } from './create/parameters.js';
3
+ export { createParamOrRef, getZodObject } from './create/parameters.js';
package/dist/api.mjs CHANGED
@@ -1,7 +1,8 @@
1
- import { createComponents, createMediaTypeSchema, createParamOrRef, getDefaultComponents } from "./components.chunk.mjs";
1
+ import { createComponents, createMediaTypeSchema, createParamOrRef, getDefaultComponents, getZodObject } from "./components.chunk.mjs";
2
2
  export {
3
3
  createComponents,
4
4
  createMediaTypeSchema,
5
5
  createParamOrRef,
6
- getDefaultComponents
6
+ getDefaultComponents,
7
+ getZodObject
7
8
  };
@@ -1161,6 +1161,7 @@ const mapIncludes = (zodStringChecks) => {
1161
1161
  });
1162
1162
  };
1163
1163
  const mapStringFormat = (zodStringChecks) => {
1164
+ var _a, _b, _c, _d;
1164
1165
  if (zodStringChecks.uuid) {
1165
1166
  return "uuid";
1166
1167
  }
@@ -1182,6 +1183,18 @@ const mapStringFormat = (zodStringChecks) => {
1182
1183
  if (zodStringChecks.url) {
1183
1184
  return "uri";
1184
1185
  }
1186
+ if ((_a = zodStringChecks.ip) == null ? void 0 : _a.every((ip) => ip.version === "v4")) {
1187
+ return "ipv4";
1188
+ }
1189
+ if ((_b = zodStringChecks.ip) == null ? void 0 : _b.every((ip) => ip.version === "v6")) {
1190
+ return "ipv6";
1191
+ }
1192
+ if ((_c = zodStringChecks.cidr) == null ? void 0 : _c.every((ip) => ip.version === "v4")) {
1193
+ return "ipv4";
1194
+ }
1195
+ if ((_d = zodStringChecks.cidr) == null ? void 0 : _d.every((ip) => ip.version === "v6")) {
1196
+ return "ipv6";
1197
+ }
1185
1198
  return void 0;
1186
1199
  };
1187
1200
  const mapContentEncoding = (zodStringChecks) => {
@@ -1675,7 +1688,7 @@ const createParameters = (type, zodObjectType, components, subpath, documentOpti
1675
1688
  if (!zodObjectType) {
1676
1689
  return [];
1677
1690
  }
1678
- const zodObject = getZodObject(zodObjectType).shape;
1691
+ const zodObject = getZodObject(zodObjectType, "input").shape;
1679
1692
  return Object.entries(zodObject).map(
1680
1693
  ([key, zodSchema]) => createParamOrRef(
1681
1694
  zodSchema,
@@ -1758,18 +1771,19 @@ const getZodObject = (schema, type) => {
1758
1771
  return schema;
1759
1772
  }
1760
1773
  if (isZodType(schema, "ZodLazy")) {
1761
- return getZodObject(schema.schema);
1774
+ return getZodObject(schema.schema, type);
1762
1775
  }
1763
1776
  if (isZodType(schema, "ZodEffects")) {
1764
- return getZodObject(schema.innerType());
1777
+ return getZodObject(schema.innerType(), type);
1765
1778
  }
1766
1779
  if (isZodType(schema, "ZodBranded")) {
1767
- return getZodObject(schema.unwrap());
1780
+ return getZodObject(schema.unwrap(), type);
1768
1781
  }
1769
1782
  if (isZodType(schema, "ZodPipeline")) {
1770
- {
1771
- return getZodObject(schema._def.in);
1783
+ if (type === "input") {
1784
+ return getZodObject(schema._def.in, type);
1772
1785
  }
1786
+ return getZodObject(schema._def.out, type);
1773
1787
  }
1774
1788
  throw new Error("failed to find ZodObject in schema");
1775
1789
  };
@@ -2408,3 +2422,4 @@ exports.createPaths = createPaths;
2408
2422
  exports.createSchema = createSchema;
2409
2423
  exports.createSchemaComponents = createSchemaComponents;
2410
2424
  exports.getDefaultComponents = getDefaultComponents;
2425
+ exports.getZodObject = getZodObject;
@@ -1160,6 +1160,7 @@ const mapIncludes = (zodStringChecks) => {
1160
1160
  });
1161
1161
  };
1162
1162
  const mapStringFormat = (zodStringChecks) => {
1163
+ var _a, _b, _c, _d;
1163
1164
  if (zodStringChecks.uuid) {
1164
1165
  return "uuid";
1165
1166
  }
@@ -1181,6 +1182,18 @@ const mapStringFormat = (zodStringChecks) => {
1181
1182
  if (zodStringChecks.url) {
1182
1183
  return "uri";
1183
1184
  }
1185
+ if ((_a = zodStringChecks.ip) == null ? void 0 : _a.every((ip) => ip.version === "v4")) {
1186
+ return "ipv4";
1187
+ }
1188
+ if ((_b = zodStringChecks.ip) == null ? void 0 : _b.every((ip) => ip.version === "v6")) {
1189
+ return "ipv6";
1190
+ }
1191
+ if ((_c = zodStringChecks.cidr) == null ? void 0 : _c.every((ip) => ip.version === "v4")) {
1192
+ return "ipv4";
1193
+ }
1194
+ if ((_d = zodStringChecks.cidr) == null ? void 0 : _d.every((ip) => ip.version === "v6")) {
1195
+ return "ipv6";
1196
+ }
1184
1197
  return void 0;
1185
1198
  };
1186
1199
  const mapContentEncoding = (zodStringChecks) => {
@@ -1674,7 +1687,7 @@ const createParameters = (type, zodObjectType, components, subpath, documentOpti
1674
1687
  if (!zodObjectType) {
1675
1688
  return [];
1676
1689
  }
1677
- const zodObject = getZodObject(zodObjectType).shape;
1690
+ const zodObject = getZodObject(zodObjectType, "input").shape;
1678
1691
  return Object.entries(zodObject).map(
1679
1692
  ([key, zodSchema]) => createParamOrRef(
1680
1693
  zodSchema,
@@ -1757,18 +1770,19 @@ const getZodObject = (schema, type) => {
1757
1770
  return schema;
1758
1771
  }
1759
1772
  if (isZodType(schema, "ZodLazy")) {
1760
- return getZodObject(schema.schema);
1773
+ return getZodObject(schema.schema, type);
1761
1774
  }
1762
1775
  if (isZodType(schema, "ZodEffects")) {
1763
- return getZodObject(schema.innerType());
1776
+ return getZodObject(schema.innerType(), type);
1764
1777
  }
1765
1778
  if (isZodType(schema, "ZodBranded")) {
1766
- return getZodObject(schema.unwrap());
1779
+ return getZodObject(schema.unwrap(), type);
1767
1780
  }
1768
1781
  if (isZodType(schema, "ZodPipeline")) {
1769
- {
1770
- return getZodObject(schema._def.in);
1782
+ if (type === "input") {
1783
+ return getZodObject(schema._def.in, type);
1771
1784
  }
1785
+ return getZodObject(schema._def.out, type);
1772
1786
  }
1773
1787
  throw new Error("failed to find ZodObject in schema");
1774
1788
  };
@@ -2407,5 +2421,6 @@ export {
2407
2421
  createPaths,
2408
2422
  createSchema,
2409
2423
  createSchemaComponents,
2410
- getDefaultComponents
2424
+ getDefaultComponents,
2425
+ getZodObject
2411
2426
  };
@@ -1,8 +1,9 @@
1
- import { ZodType } from 'zod';
1
+ import { ZodType, AnyZodObject } from 'zod';
2
2
  import { ParameterObject, ReferenceObject } from '../openapi3-ts/dist/model/openapi31.js';
3
3
  import { ComponentsObject } from './components.js';
4
- import { ZodOpenApiParameters, CreateDocumentOptions } from './document.js';
4
+ import { ZodOpenApiParameters, CreateDocumentOptions, ZodObjectInputType } from './document.js';
5
5
 
6
6
  declare const createParamOrRef: (zodSchema: ZodType, components: ComponentsObject, subpath: string[], type?: keyof ZodOpenApiParameters, name?: string, documentOptions?: CreateDocumentOptions) => ParameterObject | ReferenceObject;
7
+ declare const getZodObject: (schema: ZodObjectInputType, type: "input" | "output") => AnyZodObject;
7
8
 
8
- export { createParamOrRef };
9
+ export { createParamOrRef, getZodObject };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod-openapi",
3
- "version": "4.1.2",
3
+ "version": "4.2.0",
4
4
  "description": "Convert Zod Schemas to OpenAPI v3.x documentation",
5
5
  "keywords": [
6
6
  "typescript",
@@ -74,13 +74,13 @@
74
74
  "devDependencies": {
75
75
  "@arethetypeswrong/cli": "0.17.1",
76
76
  "@crackle/cli": "0.15.5",
77
- "@redocly/cli": "1.25.15",
77
+ "@redocly/cli": "1.26.0",
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
81
  "skuba": "9.1.0",
82
82
  "yaml": "2.6.1",
83
- "zod": "3.23.8"
83
+ "zod": "3.24.1"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "zod": "^3.21.4"