zod-openapi 0.0.0-semantically-released → 0.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.
Files changed (152) hide show
  1. package/README.md +341 -75
  2. package/lib-commonjs/create/components.js +108 -0
  3. package/lib-commonjs/create/components.js.map +1 -0
  4. package/lib-commonjs/create/content.js +32 -0
  5. package/lib-commonjs/create/content.js.map +1 -0
  6. package/lib-commonjs/create/document.js +28 -0
  7. package/lib-commonjs/create/document.js.map +1 -0
  8. package/lib-commonjs/create/parameters.js +84 -0
  9. package/lib-commonjs/create/parameters.js.map +1 -0
  10. package/lib-commonjs/create/paths.js +68 -0
  11. package/lib-commonjs/create/paths.js.map +1 -0
  12. package/lib-commonjs/create/responses.js +93 -0
  13. package/lib-commonjs/create/responses.js.map +1 -0
  14. package/lib-commonjs/create/schema/array.js +17 -0
  15. package/lib-commonjs/create/schema/array.js.map +1 -0
  16. package/lib-commonjs/create/schema/boolean.js +8 -0
  17. package/lib-commonjs/create/schema/boolean.js.map +1 -0
  18. package/lib-commonjs/create/schema/date.js +8 -0
  19. package/lib-commonjs/create/schema/date.js.map +1 -0
  20. package/lib-commonjs/create/schema/default.js +14 -0
  21. package/lib-commonjs/create/schema/default.js.map +1 -0
  22. package/lib-commonjs/create/schema/discriminatedUnion.js +43 -0
  23. package/lib-commonjs/create/schema/discriminatedUnion.js.map +1 -0
  24. package/lib-commonjs/create/schema/effects.js +7 -0
  25. package/lib-commonjs/create/schema/effects.js.map +1 -0
  26. package/lib-commonjs/create/schema/enum.js +10 -0
  27. package/lib-commonjs/create/schema/enum.js.map +1 -0
  28. package/lib-commonjs/create/schema/index.js +127 -0
  29. package/lib-commonjs/create/schema/index.js.map +1 -0
  30. package/lib-commonjs/create/schema/intersection.js +12 -0
  31. package/lib-commonjs/create/schema/intersection.js.map +1 -0
  32. package/lib-commonjs/create/schema/literal.js +9 -0
  33. package/lib-commonjs/create/schema/literal.js.map +1 -0
  34. package/lib-commonjs/create/schema/metadata.js +38 -0
  35. package/lib-commonjs/create/schema/metadata.js.map +1 -0
  36. package/lib-commonjs/create/schema/nativeEnum.js +35 -0
  37. package/lib-commonjs/create/schema/nativeEnum.js.map +1 -0
  38. package/lib-commonjs/create/schema/null.js +8 -0
  39. package/lib-commonjs/create/schema/null.js.map +1 -0
  40. package/lib-commonjs/create/schema/nullable.js +52 -0
  41. package/lib-commonjs/create/schema/nullable.js.map +1 -0
  42. package/lib-commonjs/create/schema/number.js +28 -0
  43. package/lib-commonjs/create/schema/number.js.map +1 -0
  44. package/lib-commonjs/create/schema/object.js +51 -0
  45. package/lib-commonjs/create/schema/object.js.map +1 -0
  46. package/lib-commonjs/create/schema/optional.js +9 -0
  47. package/lib-commonjs/create/schema/optional.js.map +1 -0
  48. package/lib-commonjs/create/schema/record.js +10 -0
  49. package/lib-commonjs/create/schema/record.js.map +1 -0
  50. package/lib-commonjs/create/schema/string.js +46 -0
  51. package/lib-commonjs/create/schema/string.js.map +1 -0
  52. package/lib-commonjs/create/schema/tuple.js +29 -0
  53. package/lib-commonjs/create/schema/tuple.js.map +1 -0
  54. package/lib-commonjs/create/schema/union.js +13 -0
  55. package/lib-commonjs/create/schema/union.js.map +1 -0
  56. package/lib-commonjs/create/specificationExtension.js +6 -0
  57. package/lib-commonjs/create/specificationExtension.js.map +1 -0
  58. package/lib-commonjs/extendZod.js +49 -0
  59. package/lib-commonjs/extendZod.js.map +1 -0
  60. package/lib-commonjs/index.js +16 -9
  61. package/lib-commonjs/index.js.map +1 -1
  62. package/lib-es2015/create/components.js +102 -0
  63. package/lib-es2015/create/components.js.map +1 -0
  64. package/lib-es2015/create/content.js +28 -0
  65. package/lib-es2015/create/content.js.map +1 -0
  66. package/lib-es2015/create/document.js +22 -0
  67. package/lib-es2015/create/document.js.map +1 -0
  68. package/lib-es2015/create/parameters.js +78 -0
  69. package/lib-es2015/create/parameters.js.map +1 -0
  70. package/lib-es2015/create/paths.js +64 -0
  71. package/lib-es2015/create/paths.js.map +1 -0
  72. package/lib-es2015/create/responses.js +86 -0
  73. package/lib-es2015/create/responses.js.map +1 -0
  74. package/lib-es2015/create/schema/array.js +13 -0
  75. package/lib-es2015/create/schema/array.js.map +1 -0
  76. package/lib-es2015/create/schema/boolean.js +4 -0
  77. package/lib-es2015/create/schema/boolean.js.map +1 -0
  78. package/lib-es2015/create/schema/date.js +4 -0
  79. package/lib-es2015/create/schema/date.js.map +1 -0
  80. package/lib-es2015/create/schema/default.js +10 -0
  81. package/lib-es2015/create/schema/default.js.map +1 -0
  82. package/lib-es2015/create/schema/discriminatedUnion.js +38 -0
  83. package/lib-es2015/create/schema/discriminatedUnion.js.map +1 -0
  84. package/lib-es2015/create/schema/effects.js +3 -0
  85. package/lib-es2015/create/schema/effects.js.map +1 -0
  86. package/lib-es2015/create/schema/enum.js +6 -0
  87. package/lib-es2015/create/schema/enum.js.map +1 -0
  88. package/lib-es2015/create/schema/index.js +121 -0
  89. package/lib-es2015/create/schema/index.js.map +1 -0
  90. package/lib-es2015/create/schema/intersection.js +8 -0
  91. package/lib-es2015/create/schema/intersection.js.map +1 -0
  92. package/lib-es2015/create/schema/literal.js +5 -0
  93. package/lib-es2015/create/schema/literal.js.map +1 -0
  94. package/lib-es2015/create/schema/metadata.js +33 -0
  95. package/lib-es2015/create/schema/metadata.js.map +1 -0
  96. package/lib-es2015/create/schema/nativeEnum.js +29 -0
  97. package/lib-es2015/create/schema/nativeEnum.js.map +1 -0
  98. package/lib-es2015/create/schema/null.js +4 -0
  99. package/lib-es2015/create/schema/null.js.map +1 -0
  100. package/lib-es2015/create/schema/nullable.js +47 -0
  101. package/lib-es2015/create/schema/nullable.js.map +1 -0
  102. package/lib-es2015/create/schema/number.js +24 -0
  103. package/lib-es2015/create/schema/number.js.map +1 -0
  104. package/lib-es2015/create/schema/object.js +43 -0
  105. package/lib-es2015/create/schema/object.js.map +1 -0
  106. package/lib-es2015/create/schema/optional.js +5 -0
  107. package/lib-es2015/create/schema/optional.js.map +1 -0
  108. package/lib-es2015/create/schema/record.js +6 -0
  109. package/lib-es2015/create/schema/record.js.map +1 -0
  110. package/lib-es2015/create/schema/string.js +42 -0
  111. package/lib-es2015/create/schema/string.js.map +1 -0
  112. package/lib-es2015/create/schema/tuple.js +25 -0
  113. package/lib-es2015/create/schema/tuple.js.map +1 -0
  114. package/lib-es2015/create/schema/union.js +9 -0
  115. package/lib-es2015/create/schema/union.js.map +1 -0
  116. package/lib-es2015/create/specificationExtension.js +2 -0
  117. package/lib-es2015/create/specificationExtension.js.map +1 -0
  118. package/lib-es2015/extendZod.js +45 -0
  119. package/lib-es2015/extendZod.js.map +1 -0
  120. package/lib-es2015/index.js +2 -7
  121. package/lib-es2015/index.js.map +1 -1
  122. package/lib-types/create/components.d.ts +33 -0
  123. package/lib-types/create/content.d.ts +4 -0
  124. package/lib-types/create/document.d.ts +62 -0
  125. package/lib-types/create/parameters.d.ts +7 -0
  126. package/lib-types/create/paths.d.ts +4 -0
  127. package/lib-types/create/responses.d.ts +8 -0
  128. package/lib-types/create/schema/array.d.ts +4 -0
  129. package/lib-types/create/schema/boolean.d.ts +3 -0
  130. package/lib-types/create/schema/date.d.ts +3 -0
  131. package/lib-types/create/schema/default.d.ts +4 -0
  132. package/lib-types/create/schema/discriminatedUnion.d.ts +10 -0
  133. package/lib-types/create/schema/effects.d.ts +4 -0
  134. package/lib-types/create/schema/enum.d.ts +3 -0
  135. package/lib-types/create/schema/index.d.ts +6 -0
  136. package/lib-types/create/schema/intersection.d.ts +4 -0
  137. package/lib-types/create/schema/literal.d.ts +3 -0
  138. package/lib-types/create/schema/metadata.d.ts +5 -0
  139. package/lib-types/create/schema/nativeEnum.d.ts +10 -0
  140. package/lib-types/create/schema/null.d.ts +3 -0
  141. package/lib-types/create/schema/nullable.d.ts +5 -0
  142. package/lib-types/create/schema/number.d.ts +3 -0
  143. package/lib-types/create/schema/object.d.ts +8 -0
  144. package/lib-types/create/schema/optional.d.ts +4 -0
  145. package/lib-types/create/schema/record.d.ts +4 -0
  146. package/lib-types/create/schema/string.d.ts +3 -0
  147. package/lib-types/create/schema/tuple.d.ts +4 -0
  148. package/lib-types/create/schema/union.d.ts +4 -0
  149. package/lib-types/create/specificationExtension.d.ts +1 -0
  150. package/lib-types/extendZod.d.ts +36 -0
  151. package/lib-types/index.d.ts +2 -5
  152. package/package.json +14 -7
@@ -0,0 +1,47 @@
1
+ import { createSchemaOrRef } from '.';
2
+ export const createNullableSchema = (zodNullable, components) => {
3
+ const schemaOrReference = createSchemaOrRef(zodNullable.unwrap(), components);
4
+ if ('$ref' in schemaOrReference) {
5
+ return {
6
+ oneOf: mapNullOf([schemaOrReference]),
7
+ };
8
+ }
9
+ if (schemaOrReference.oneOf) {
10
+ const { oneOf, ...schema } = schemaOrReference;
11
+ return {
12
+ oneOf: mapNullOf(oneOf),
13
+ ...schema,
14
+ };
15
+ }
16
+ if (schemaOrReference.allOf) {
17
+ return {
18
+ oneOf: [schemaOrReference, { type: 'null' }],
19
+ };
20
+ }
21
+ if (schemaOrReference.anyOf) {
22
+ const { anyOf, ...schema } = schemaOrReference;
23
+ return {
24
+ anyOf: mapNullOf(anyOf),
25
+ ...schema,
26
+ };
27
+ }
28
+ const { type, ...schema } = schemaOrReference;
29
+ return {
30
+ type: mapNullType(type),
31
+ ...schema,
32
+ };
33
+ };
34
+ export const mapNullType = (type) => {
35
+ if (!type) {
36
+ return 'null';
37
+ }
38
+ if (Array.isArray(type)) {
39
+ return [...type, 'null'];
40
+ }
41
+ return [type, 'null'];
42
+ };
43
+ const mapNullOf = (ofSchema) => [
44
+ ...ofSchema,
45
+ { type: 'null' },
46
+ ];
47
+ //# sourceMappingURL=nullable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nullable.js","sourceRoot":"","sources":["../../../src/create/schema/nullable.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEtC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,WAA6B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,CAAC;AAEF,MAAM,SAAS,GAAG,CAChB,QAAwD,EACR,EAAE,CAAC;IACnD,GAAG,QAAQ;IACX,EAAE,IAAI,EAAE,MAAM,EAAE;CACjB,CAAC"}
@@ -0,0 +1,24 @@
1
+ export const createNumberSchema = (zodNumber) => {
2
+ const zodNumberChecks = getZodNumberChecks(zodNumber);
3
+ return {
4
+ type: mapNumberType(zodNumberChecks),
5
+ ...mapRanges(zodNumberChecks),
6
+ };
7
+ };
8
+ const mapRanges = (zodNumberChecks) => {
9
+ const minimum = zodNumberChecks.min?.value;
10
+ const maximum = zodNumberChecks.max?.value;
11
+ return {
12
+ ...(minimum !== undefined && { minimum }),
13
+ ...(maximum !== undefined && { maximum }),
14
+ ...(zodNumberChecks.min?.inclusive && { exclusiveMinimum: minimum }),
15
+ ...(zodNumberChecks.max?.inclusive && { exclusiveMaximum: maximum }),
16
+ };
17
+ };
18
+ const getZodNumberChecks = (zodNumber) => zodNumber._def.checks.reduce((acc, check) => {
19
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
20
+ acc[check.kind] = check;
21
+ return acc;
22
+ }, {});
23
+ const mapNumberType = (zodNumberChecks) => (zodNumberChecks.int ? 'integer' : 'number');
24
+ //# sourceMappingURL=number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.js","sourceRoot":"","sources":["../../../src/create/schema/number.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAAoB,EACA,EAAE;IACtB,MAAM,eAAe,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAEtD,OAAO;QACL,IAAI,EAAE,aAAa,CAAC,eAAe,CAAC;QACpC,GAAG,SAAS,CAAC,eAAe,CAAC;KAC9B,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,SAAS,GAAG,CAChB,eAAkC,EAIlC,EAAE;IACF,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,EAAE,KAAK,CAAC;IAC3C,MAAM,OAAO,GAAG,eAAe,CAAC,GAAG,EAAE,KAAK,CAAC;IAC3C,OAAO;QACL,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,CAAC;QACzC,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,EAAE,OAAO,EAAE,CAAC;QACzC,GAAG,CAAC,eAAe,CAAC,GAAG,EAAE,SAAS,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC;QACpE,GAAG,CAAC,eAAe,CAAC,GAAG,EAAE,SAAS,IAAI,EAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC;KACrE,CAAC;AACJ,CAAC,CAAC;AAMF,MAAM,kBAAkB,GAAG,CAAC,SAAoB,EAAqB,EAAE,CACrE,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAoB,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;IAC7D,mEAAmE;IACnE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAY,CAAC;IAC/B,OAAO,GAAG,CAAC;AACb,CAAC,EAAE,EAAE,CAAC,CAAC;AAET,MAAM,aAAa,GAAG,CACpB,eAAkC,EACN,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { createComponentSchemaRef } from '../components';
2
+ import { createSchemaOrRef } from '.';
3
+ export const createObjectSchema = (zodObject, components) => {
4
+ if (zodObject._def.extendMetadata?.extendsRef) {
5
+ return createExtendedSchema(zodObject, zodObject._def.extendMetadata.extends, zodObject._def.extendMetadata.extendsRef, components);
6
+ }
7
+ return createObjectSchemaFromShape(zodObject.shape, zodObject._def.unknownKeys === 'strict', components);
8
+ };
9
+ export const createExtendedSchema = (zodObject, baseZodObject, schemaRef, components) => {
10
+ const diffShape = createShapeDiff(baseZodObject._def.shape(), zodObject._def.shape());
11
+ return {
12
+ allOf: [
13
+ { $ref: createComponentSchemaRef(schemaRef) },
14
+ createObjectSchemaFromShape(diffShape, false, components),
15
+ ],
16
+ };
17
+ };
18
+ const createShapeDiff = (baseObj, extendedObj) => Object.entries(extendedObj).reduce((acc, [key, val]) => {
19
+ if (val !== baseObj[key]) {
20
+ acc[key] = extendedObj[key];
21
+ }
22
+ return acc;
23
+ }, {});
24
+ export const createObjectSchemaFromShape = (shape, strict, components) => ({
25
+ type: 'object',
26
+ properties: mapProperties(shape, components),
27
+ required: mapRequired(shape),
28
+ ...(strict && { additionalProperties: strict }),
29
+ });
30
+ export const mapRequired = (shape) => {
31
+ const required = Object.entries(shape)
32
+ .filter(([_key, zodSchema]) => !zodSchema.isOptional())
33
+ .map(([key]) => key);
34
+ if (!required.length) {
35
+ return undefined;
36
+ }
37
+ return required;
38
+ };
39
+ export const mapProperties = (shape, components) => Object.entries(shape).reduce((acc, [key, zodSchema]) => {
40
+ acc[key] = createSchemaOrRef(zodSchema, components);
41
+ return acc;
42
+ }, {});
43
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../../../src/create/schema/object.ts"],"names":[],"mappings":"AAGA,OAAO,EAAoB,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAIhC,SAAmD,EACnD,UAA4B,EACR,EAAE;IACtB,IAAI,SAAS,CAAC,IAAI,CAAC,cAAc,EAAE,UAAU,EAAE;QAC7C,OAAO,oBAAoB,CACzB,SAAS,EACT,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,EACrC,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,EACxC,UAAU,CACX,CAAC;KACH;IAED,OAAO,2BAA2B,CAChC,SAAS,CAAC,KAAK,EACf,SAAS,CAAC,IAAI,CAAC,WAAW,KAAK,QAAQ,EACvC,UAAU,CACX,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AC7C,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC,SAAS,CAAC,UAAU,EAAE,CAAC;SACtD,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;IAEvB,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;QACpB,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,KAAkB,EAClB,UAA4B,EACM,EAAE,CACpC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAC1B,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,SAAS,CAAC,EAAiD,EAAE;IACvE,GAAG,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IACpD,OAAO,GAAG,CAAC;AACb,CAAC,EACD,EAAE,CACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { createSchemaOrRef } from '.';
2
+ export const createOptionalSchema = (zodOptional, components) =>
3
+ // Optional doesn't change OpenAPI schema
4
+ createSchemaOrRef(zodOptional.unwrap(), components);
5
+ //# sourceMappingURL=optional.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optional.js","sourceRoot":"","sources":["../../../src/create/schema/optional.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEtC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,WAA6B,EAC7B,UAA4B,EACgB,EAAE;AAC9C,yCAAyC;AACzC,iBAAiB,CAAC,WAAW,CAAC,MAAM,EAAgB,EAAE,UAAU,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { createSchemaOrRef } from '.';
2
+ export const createRecordSchema = (zodRecord, components) => ({
3
+ type: 'object',
4
+ additionalProperties: createSchemaOrRef(zodRecord.valueSchema, components),
5
+ });
6
+ //# sourceMappingURL=record.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record.js","sourceRoot":"","sources":["../../../src/create/schema/record.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEtC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,SAA8B,EAC9B,UAA4B,EACR,EAAE,CAAC,CAAC;IACxB,IAAI,EAAE,QAAQ;IACd,oBAAoB,EAAE,iBAAiB,CACrC,SAAS,CAAC,WAAyB,EACnC,UAAU,CACX;CACF,CAAC,CAAC"}
@@ -0,0 +1,42 @@
1
+ export const createStringSchema = (zodString) => {
2
+ const zodStringChecks = getZodStringChecks(zodString);
3
+ const format = mapStringFormat(zodStringChecks);
4
+ const pattern = mapRegex(zodStringChecks);
5
+ const minLength = zodStringChecks.length?.value ?? zodStringChecks.min?.value;
6
+ const maxLength = zodStringChecks.length?.value ?? zodStringChecks.max?.value;
7
+ return {
8
+ type: 'string',
9
+ ...(format && { format }),
10
+ ...(pattern && { pattern }),
11
+ ...(minLength !== undefined && { minLength }),
12
+ ...(maxLength !== undefined && { maxLength }),
13
+ };
14
+ };
15
+ const getZodStringChecks = (zodString) => zodString._def.checks.reduce((acc, check) => {
16
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
17
+ acc[check.kind] = check;
18
+ return acc;
19
+ }, {});
20
+ const mapRegex = (zodStringChecks) => {
21
+ const regexCheck = zodStringChecks.regex;
22
+ if (!regexCheck) {
23
+ return undefined;
24
+ }
25
+ return regexCheck?.regex.source;
26
+ };
27
+ const mapStringFormat = (zodStringChecks) => {
28
+ if (zodStringChecks.uuid) {
29
+ return 'uuid';
30
+ }
31
+ if (zodStringChecks.datetime) {
32
+ return 'date-time';
33
+ }
34
+ if (zodStringChecks.email) {
35
+ return 'email';
36
+ }
37
+ if (zodStringChecks.url) {
38
+ return 'uri';
39
+ }
40
+ return undefined;
41
+ };
42
+ //#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UAAU,EAAE;QACf,OAAO,SAAS,CAAC;KAClB;IAED,OAAO,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC;AAClC,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,CACtB,eAAkC,EACJ,EAAE;IAChC,IAAI,eAAe,CAAC,IAAI,EAAE;QACxB,OAAO,MAAM,CAAC;KACf;IAED,IAAI,eAAe,CAAC,QAAQ,EAAE;QAC5B,OAAO,WAAW,CAAC;KACpB;IAED,IAAI,eAAe,CAAC,KAAK,EAAE;QACzB,OAAO,OAAO,CAAC;KAChB;IAED,IAAI,eAAe,CAAC,GAAG,EAAE;QACvB,OAAO,KAAK,CAAC;KACd;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { createSchemaOrRef } from '.';
2
+ export const createTupleSchema = (zodTuple, components) => {
3
+ const items = zodTuple.items;
4
+ const rest = zodTuple._def.rest;
5
+ return {
6
+ type: 'array',
7
+ ...mapPrefixItems(items, components),
8
+ ...mapItemProperties(items, rest, components),
9
+ };
10
+ };
11
+ const mapPrefixItems = (items, components) => items.length
12
+ ? { prefixItems: items.map((item) => createSchemaOrRef(item, components)) }
13
+ : undefined;
14
+ const mapItemProperties = (items, rest, components) => {
15
+ if (!rest) {
16
+ return {
17
+ maxItems: items.length,
18
+ minItems: items.length,
19
+ };
20
+ }
21
+ return {
22
+ items: createSchemaOrRef(rest, components),
23
+ };
24
+ };
25
+ //# sourceMappingURL=tuple.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tuple.js","sourceRoot":"","sources":["../../../src/create/schema/tuple.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,QAA4B,EAC5B,UAA4B,EACR,EAAE;IACtB,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAqB,CAAC;IAC7C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAkB,CAAC;IAC9C,OAAO;QACL,IAAI,EAAE,OAAO;QACb,GAAG,cAAc,CAAC,KAAK,EAAE,UAAU,CAAC;QACpC,GAAG,iBAAiB,CAAC,KAAK,EAAE,IAAI,EAAE,UAAU,CAAC;KACxB,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CACrB,KAAmB,EACnB,UAA4B,EAGhB,EAAE,CACd,KAAK,CAAC,MAAM;IACV,CAAC,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,EAAE;IAC3E,CAAC,CAAC,SAAS,CAAC;AAEhB,MAAM,iBAAiB,GAAG,CACxB,KAAmB,EACnB,IAAgB,EAChB,UAA4B,EACiC,EAAE;IAC/D,IAAI,CAAC,IAAI,EAAE;QACT,OAAO;YACL,QAAQ,EAAE,KAAK,CAAC,MAAM;YACtB,QAAQ,EAAE,KAAK,CAAC,MAAM;SACvB,CAAC;KACH;IAED,OAAO;QACL,KAAK,EAAE,iBAAiB,CAAC,IAAI,EAAE,UAAU,CAAC;KAC3C,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { createSchemaOrRef } from '.';
2
+ export const createUnionSchema = (zodUnion, components) => {
3
+ const options = zodUnion.options;
4
+ const schemas = options.map((option) => createSchemaOrRef(option, components));
5
+ return {
6
+ anyOf: schemas,
7
+ };
8
+ };
9
+ //# sourceMappingURL=union.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"union.js","sourceRoot":"","sources":["../../../src/create/schema/union.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,CAAC;AAEtC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,QAAuB,EACvB,UAA4B,EACR,EAAE;IACtB,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAuB,CAAC;IACjD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CACrC,iBAAiB,CAAC,MAAM,EAAE,UAAU,CAAC,CACtC,CAAC;IACF,OAAO;QACL,KAAK,EAAE,OAAO;KACf,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export const isISpecificationExtension = (key) => key.startsWith('x-');
2
+ //# sourceMappingURL=specificationExtension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"specificationExtension.js","sourceRoot":"","sources":["../../src/create/specificationExtension.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,GAAW,EACkB,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1,45 @@
1
+ export function extendZodWithOpenApi(zod) {
2
+ if (typeof zod.ZodSchema.prototype.openapi !== 'undefined') {
3
+ return;
4
+ }
5
+ zod.ZodSchema.prototype.openapi = function (openapi) {
6
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
7
+ const result = new this.constructor({
8
+ ...this._def,
9
+ openapi,
10
+ });
11
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
12
+ return result;
13
+ };
14
+ // eslint-disable-next-line @typescript-eslint/unbound-method
15
+ const zodObjectExtend = zod.ZodObject.prototype.extend;
16
+ zod.ZodObject.prototype.extend = function (...args) {
17
+ const extendResult = zodObjectExtend.apply(this, args);
18
+ extendResult._def.extendMetadata = {
19
+ extends: this,
20
+ extendsRef: extendResult._def.openapi?.ref,
21
+ };
22
+ delete extendResult._def.openapi;
23
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
24
+ return extendResult;
25
+ };
26
+ // eslint-disable-next-line @typescript-eslint/unbound-method
27
+ const zodObjectOmit = zod.ZodObject.prototype.omit;
28
+ zod.ZodObject.prototype.omit = function (...args) {
29
+ const omitResult = zodObjectOmit.apply(this, args);
30
+ delete omitResult._def.extendMetadata;
31
+ delete omitResult._def.openapi;
32
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
33
+ return omitResult;
34
+ };
35
+ // eslint-disable-next-line @typescript-eslint/unbound-method
36
+ const zodObjectPick = zod.ZodObject.prototype.pick;
37
+ zod.ZodObject.prototype.pick = function (...args) {
38
+ const pickResult = zodObjectPick.apply(this, args);
39
+ delete pickResult._def.extendMetadata;
40
+ delete pickResult._def.openapi;
41
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
42
+ return pickResult;
43
+ };
44
+ }
45
+ //# sourceMappingURL=extendZod.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extendZod.js","sourceRoot":"","sources":["../src/extendZod.ts"],"names":[],"mappings":"AAyDA,MAAM,UAAU,oBAAoB,CAAC,GAAa;IAChD,IAAI,OAAO,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,KAAK,WAAW,EAAE;QAC1D,OAAO;KACR;IACD,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,GAAG,UAAU,OAAO;QACjD,kJAAkJ;QAClJ,MAAM,MAAM,GAAG,IAAK,IAAY,CAAC,WAAW,CAAC;YAC3C,GAAG,IAAI,CAAC,IAAI;YACZ,OAAO;SACR,CAAC,CAAC;QAEH,+DAA+D;QAC/D,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,6DAA6D;IAC7D,MAAM,eAAe,GAAG,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC;IAEvD,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,GAAG,UAC/B,GAAG,IAAiC;QAEpC,MAAM,YAAY,GAAG,eAAe,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACvD,YAAY,CAAC,IAAI,CAAC,cAAc,GAAG;YACjC,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG;SAC3C,CAAC;QACF,OAAO,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;QACjC,+DAA+D;QAC/D,OAAO,YAAmB,CAAC;IAC7B,CAAC,CAAC;IAEF,6DAA6D;IAC7D,MAAM,aAAa,GAAG,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC;IAEnD,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,GAAG,UAC7B,GAAG,IAA+C;QAElD,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACnD,OAAO,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC;QACtC,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;QAC/B,+DAA+D;QAC/D,OAAO,UAAiB,CAAC;IAC3B,CAAC,CAAC;IAEF,6DAA6D;IAC7D,MAAM,aAAa,GAAG,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC;IAEnD,GAAG,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,GAAG,UAC7B,GAAG,IAA+C;QAElD,MAAM,UAAU,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACnD,OAAO,UAAU,CAAC,IAAI,CAAC,cAAc,CAAC;QACtC,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC;QAC/B,+DAA+D;QAC/D,OAAO,UAAiB,CAAC;IAC3B,CAAC,CAAC;AACJ,CAAC"}
@@ -1,8 +1,3 @@
1
- /**
2
- * Writes the module name to stdout.
3
- * Thrilling stuff.
4
- */
5
- export const log = () =>
6
- /* eslint-disable-next-line no-console */
7
- console.log('zod-openapi');
1
+ export * from './create/document';
2
+ export * from './extendZod';
8
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,EAAE;AACtB,yCAAyC;AACzC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodType } from 'zod';
3
+ import { ZodOpenApiComponentsObject } from './document';
4
+ export interface Schema {
5
+ zodSchema?: ZodType;
6
+ schemaObject: oas31.SchemaObject | oas31.ReferenceObject;
7
+ }
8
+ interface SchemaComponentObject {
9
+ [ref: string]: Schema | undefined;
10
+ }
11
+ export interface Parameter {
12
+ zodSchema?: ZodType;
13
+ paramObject: oas31.ParameterObject | oas31.ReferenceObject;
14
+ }
15
+ interface ParametersComponentObject {
16
+ [ref: string]: Parameter | undefined;
17
+ }
18
+ export interface Header {
19
+ zodSchema?: ZodType;
20
+ headerObject: oas31.HeaderObject | oas31.ReferenceObject;
21
+ }
22
+ interface HeadersComponentObject {
23
+ [ref: string]: Header | undefined;
24
+ }
25
+ export interface ComponentsObject {
26
+ schemas: SchemaComponentObject;
27
+ parameters: ParametersComponentObject;
28
+ headers: HeadersComponentObject;
29
+ }
30
+ export declare const getDefaultComponents: (componentsObject?: Pick<ZodOpenApiComponentsObject, 'schemas' | 'parameters' | 'headers'>) => ComponentsObject;
31
+ export declare const createComponentSchemaRef: (schemaRef: string) => string;
32
+ export declare const createComponents: (componentsObject: Omit<ZodOpenApiComponentsObject, 'schemas' | 'parameters' | 'headers'> | undefined, components: ComponentsObject) => oas31.ComponentsObject | undefined;
33
+ export {};
@@ -0,0 +1,4 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ComponentsObject } from './components';
3
+ import { ZodOpenApiContentObject } from './document';
4
+ export declare const createContent: (contentObject: ZodOpenApiContentObject, components: ComponentsObject) => oas31.ContentObject;
@@ -0,0 +1,62 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { stringify } from 'yaml';
3
+ import { AnyZodObject, ZodType } from 'zod';
4
+ export interface ZodOpenApiMediaTypeObject extends Omit<oas31.MediaTypeObject, 'schema'> {
5
+ schema?: AnyZodObject | oas31.SchemaObject | oas31.ReferenceObject;
6
+ }
7
+ export interface ZodOpenApiContentObject {
8
+ 'application/json'?: ZodOpenApiMediaTypeObject;
9
+ [mediatype: string]: ZodOpenApiMediaTypeObject | undefined;
10
+ }
11
+ export interface ZodOpenApiRequestBodyObject extends Omit<oas31.RequestBodyObject, 'content'> {
12
+ content: ZodOpenApiContentObject;
13
+ }
14
+ export interface ZodOpenApiResponseObject extends Omit<oas31.ResponseObject, 'content'> {
15
+ content?: ZodOpenApiContentObject;
16
+ responseHeaders?: AnyZodObject;
17
+ }
18
+ export interface ZodOpenApiResponsesObject extends oas31.ISpecificationExtension {
19
+ default?: ZodOpenApiResponseObject | oas31.ReferenceObject;
20
+ [statuscode: `${1 | 2 | 3 | 4 | 5}${string}`]: ZodOpenApiResponseObject | oas31.ReferenceObject;
21
+ }
22
+ export type ZodOpenApiParameters = {
23
+ [type in oas31.ParameterLocation]?: AnyZodObject;
24
+ };
25
+ export interface ZodOpenApiOperationObject extends Omit<oas31.OperationObject, 'requestBody' | 'responses'> {
26
+ requestBody?: ZodOpenApiRequestBodyObject;
27
+ requestParams?: ZodOpenApiParameters;
28
+ responses: ZodOpenApiResponsesObject;
29
+ }
30
+ export interface ZodOpenApiPathItemObject extends Omit<oas31.PathItemObject, 'get' | 'put' | 'post' | 'delete' | 'options' | 'head' | 'patch' | 'trace'> {
31
+ get?: ZodOpenApiOperationObject;
32
+ put?: ZodOpenApiOperationObject;
33
+ post?: ZodOpenApiOperationObject;
34
+ delete?: ZodOpenApiOperationObject;
35
+ options?: ZodOpenApiOperationObject;
36
+ head?: ZodOpenApiOperationObject;
37
+ patch?: ZodOpenApiOperationObject;
38
+ trace?: ZodOpenApiOperationObject;
39
+ }
40
+ export interface ZodOpenApiPathsObject extends oas31.ISpecificationExtension {
41
+ [path: string]: ZodOpenApiPathItemObject;
42
+ }
43
+ export interface ZodOpenApiComponentsObject extends Omit<oas31.ComponentsObject, 'schemas'> {
44
+ schemas?: {
45
+ [schema: string]: ZodType | oas31.SchemaObject | oas31.ReferenceObject;
46
+ };
47
+ }
48
+ export interface ZodOpenApiObject extends Omit<oas31.OpenAPIObject, 'openapi' | 'paths' | 'webhooks' | 'components'> {
49
+ openapi: '3.1.0';
50
+ paths?: ZodOpenApiPathsObject;
51
+ webhooks?: ZodOpenApiPathsObject;
52
+ components?: ZodOpenApiComponentsObject;
53
+ }
54
+ export declare const createDocument: (zodOpenApiObject: ZodOpenApiObject) => oas31.OpenAPIObject;
55
+ export declare const createDocumentJson: (params: ZodOpenApiObject, jsonOptions?: {
56
+ replacer?: Parameters<typeof JSON.stringify>[1];
57
+ options?: Parameters<typeof JSON.stringify>[2];
58
+ }) => string;
59
+ export declare const createDocumentYaml: (params: ZodOpenApiObject, yamlOptions?: {
60
+ replacer?: Parameters<typeof stringify>[1];
61
+ options?: Parameters<typeof stringify>[2];
62
+ }) => string;
@@ -0,0 +1,7 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodType } from 'zod';
3
+ import { ComponentsObject } from './components';
4
+ import { ZodOpenApiParameters } from './document';
5
+ export declare const createComponentParamRef: (ref: string) => string;
6
+ export declare const createBaseParameter: (schema: ZodType, components: ComponentsObject) => oas31.BaseParameterObject;
7
+ export declare const createParametersObject: (parameters: (oas31.ParameterObject | oas31.ReferenceObject)[] | undefined, requestParams: ZodOpenApiParameters | undefined, components: ComponentsObject) => (oas31.ParameterObject | oas31.ReferenceObject)[] | undefined;
@@ -0,0 +1,4 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ComponentsObject } from './components';
3
+ import { ZodOpenApiPathsObject } from './document';
4
+ export declare const createPaths: (pathsObject: ZodOpenApiPathsObject | undefined, components: ComponentsObject) => oas31.PathsObject | undefined;
@@ -0,0 +1,8 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { AnyZodObject, ZodType } from 'zod';
3
+ import { ComponentsObject } from './components';
4
+ import { ZodOpenApiResponsesObject } from './document';
5
+ export declare const createResponseHeaders: (responseHeaders: AnyZodObject | undefined, components: ComponentsObject) => oas31.ResponseObject['headers'];
6
+ export declare const createBaseHeader: (schema: ZodType, components: ComponentsObject) => oas31.BaseParameterObject;
7
+ export declare const createComponentHeaderRef: (ref: string) => string;
8
+ export declare const createResponses: (responsesObject: ZodOpenApiResponsesObject, components: ComponentsObject) => oas31.ResponsesObject;
@@ -0,0 +1,4 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodArray } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createArraySchema: (zodArray: ZodArray<any, any>, components: ComponentsObject) => oas31.SchemaObject;
@@ -0,0 +1,3 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodBoolean } from 'zod';
3
+ export declare const createBooleanSchema: (_zodBoolean: ZodBoolean) => oas31.SchemaObject;
@@ -0,0 +1,3 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodDate } from 'zod';
3
+ export declare const createDateSchema: (_zodDate: ZodDate) => oas31.SchemaObject;
@@ -0,0 +1,4 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodDefault } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createDefaultSchema: (zodDefault: ZodDefault<any>, components: ComponentsObject) => oas31.SchemaObject | oas31.ReferenceObject;
@@ -0,0 +1,10 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { AnyZodObject, ZodDiscriminatedUnion } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createDiscriminatedUnionSchema: (zodDiscriminatedUnion: ZodDiscriminatedUnion<any, any>, components: ComponentsObject) => oas31.SchemaObject;
5
+ export declare const mapDiscriminator: (zodObjects: AnyZodObject[], discriminator: string) => {
6
+ propertyName: string;
7
+ mapping: {
8
+ [key: string]: string;
9
+ };
10
+ } | undefined;
@@ -0,0 +1,4 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodEffects } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createEffectsSchema: (zodEffects: ZodEffects<any, any, any>, components: ComponentsObject) => oas31.SchemaObject | oas31.ReferenceObject;
@@ -0,0 +1,3 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodEnum } from 'zod';
3
+ export declare const createEnumSchema: (zodEnum: ZodEnum<any>) => oas31.SchemaObject;
@@ -0,0 +1,6 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodType, ZodTypeDef } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createSchema: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, components: ComponentsObject) => oas31.SchemaObject | oas31.ReferenceObject;
5
+ export declare const createRegisteredSchema: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, schemaRef: string, components: ComponentsObject) => oas31.ReferenceObject;
6
+ export declare const createSchemaOrRef: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, components: ComponentsObject) => oas31.SchemaObject | oas31.ReferenceObject;
@@ -0,0 +1,4 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodIntersection } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createIntersectionSchema: (zodIntersection: ZodIntersection<any, any>, components: ComponentsObject) => oas31.SchemaObject | oas31.ReferenceObject;
@@ -0,0 +1,3 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodLiteral } from 'zod';
3
+ export declare const createLiteralSchema: (zodLiteral: ZodLiteral<any>) => oas31.SchemaObject;
@@ -0,0 +1,5 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodType, ZodTypeDef } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createSchemaWithMetadata: <Output = any, Def extends ZodTypeDef = ZodTypeDef, Input = Output>(zodSchema: ZodType<Output, Def, Input>, components: ComponentsObject) => oas31.SchemaObject | oas31.ReferenceObject;
5
+ export declare const enhanceWithMetadata: (schemaOrRef: oas31.SchemaObject | oas31.ReferenceObject, metadata: oas31.SchemaObject | oas31.ReferenceObject) => oas31.SchemaObject | oas31.ReferenceObject;
@@ -0,0 +1,10 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { EnumLike, ZodNativeEnum } from 'zod';
3
+ export declare const createNativeEnumSchema: <T extends EnumLike>(zodEnum: ZodNativeEnum<T>) => oas31.SchemaObject | oas31.ReferenceObject;
4
+ interface StringsAndNumbers {
5
+ strings: string[];
6
+ numbers: number[];
7
+ }
8
+ export declare const getValidEnumValues: (enumValues: EnumLike) => (string | number)[];
9
+ export declare const sortStringsAndNumbers: (values: (string | number)[]) => StringsAndNumbers;
10
+ export {};
@@ -0,0 +1,3 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodNull } from 'zod';
3
+ export declare const createNullSchema: (_zodNull: ZodNull) => oas31.SchemaObject;
@@ -0,0 +1,5 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodNullable } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createNullableSchema: (zodNullable: ZodNullable<any>, components: ComponentsObject) => oas31.SchemaObject;
5
+ export declare const mapNullType: (type: oas31.SchemaObject['type']) => oas31.SchemaObject['type'];
@@ -0,0 +1,3 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodNumber } from 'zod';
3
+ export declare const createNumberSchema: (zodNumber: ZodNumber) => oas31.SchemaObject;
@@ -0,0 +1,8 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { UnknownKeysParam, ZodObject, ZodRawShape } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createObjectSchema: <T extends ZodRawShape, UnknownKeys extends UnknownKeysParam = UnknownKeysParam>(zodObject: ZodObject<T, UnknownKeys, any, any, any>, components: ComponentsObject) => oas31.SchemaObject;
5
+ export declare const createExtendedSchema: (zodObject: ZodObject<any, any, any, any, any>, baseZodObject: ZodObject<any, any, any, any, any>, schemaRef: string, components: ComponentsObject) => oas31.SchemaObject;
6
+ export declare const createObjectSchemaFromShape: (shape: ZodRawShape, strict: boolean, components: ComponentsObject) => oas31.SchemaObject;
7
+ export declare const mapRequired: (shape: ZodRawShape) => oas31.SchemaObject['required'];
8
+ export declare const mapProperties: (shape: ZodRawShape, components: ComponentsObject) => oas31.SchemaObject['properties'];
@@ -0,0 +1,4 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodOptional } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createOptionalSchema: (zodOptional: ZodOptional<any>, components: ComponentsObject) => oas31.SchemaObject | oas31.ReferenceObject;
@@ -0,0 +1,4 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodRecord } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createRecordSchema: (zodRecord: ZodRecord<any, any>, components: ComponentsObject) => oas31.SchemaObject;
@@ -0,0 +1,3 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodString } from 'zod';
3
+ export declare const createStringSchema: (zodString: ZodString) => oas31.SchemaObject;
@@ -0,0 +1,4 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodTuple } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createTupleSchema: (zodTuple: ZodTuple<any, any>, components: ComponentsObject) => oas31.SchemaObject;
@@ -0,0 +1,4 @@
1
+ import { oas31 } from 'openapi3-ts';
2
+ import { ZodUnion } from 'zod';
3
+ import { ComponentsObject } from '../components';
4
+ export declare const createUnionSchema: (zodUnion: ZodUnion<any>, components: ComponentsObject) => oas31.SchemaObject;
@@ -0,0 +1 @@
1
+ export declare const isISpecificationExtension: (key: string) => key is `x-${string}`;