@cerios/openapi-to-zod 0.5.3 → 1.0.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/dist/index.mjs CHANGED
@@ -67,6 +67,7 @@ var ConfigurationError = class extends GeneratorError {
67
67
  // src/openapi-generator.ts
68
68
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
69
69
  import { dirname, normalize } from "path";
70
+ import { minimatch as minimatch2 } from "minimatch";
70
71
  import { parse } from "yaml";
71
72
 
72
73
  // src/utils/name-utils.ts
@@ -100,34 +101,11 @@ function resolveRef(ref) {
100
101
 
101
102
  // src/generators/enum-generator.ts
102
103
  function generateEnum(name, values, options) {
103
- const enumName = name.endsWith("EnumOptions") ? name.replace("EnumOptions", "Enum") : `${name}Enum`;
104
104
  const schemaName = `${toCamelCase(name, options)}Schema`;
105
- if (options.enumType === "typescript") {
106
- const usedKeys = /* @__PURE__ */ new Set();
107
- const enumEntries = values.map((value) => {
108
- let key = toPascalCase(value);
109
- if (usedKeys.has(key)) {
110
- let counter = 2;
111
- while (usedKeys.has(`${key}${counter}`)) {
112
- counter++;
113
- }
114
- key = `${key}${counter}`;
115
- }
116
- usedKeys.add(key);
117
- const stringValue = typeof value === "string" ? `"${value}"` : value;
118
- return ` ${key} = ${stringValue},`;
119
- }).join("\n");
120
- const enumCode = `export enum ${enumName} {
121
- ${enumEntries}
122
- }`;
123
- const schemaCode2 = `export const ${schemaName} = z.nativeEnum(${enumName});`;
124
- const typeCode2 = `export type ${name} = z.infer<typeof ${schemaName}>;`;
125
- return { enumCode, schemaCode: schemaCode2, typeCode: typeCode2 };
126
- }
127
105
  const enumValues = values.map((v) => `"${v}"`).join(", ");
128
106
  const schemaCode = `export const ${schemaName} = z.enum([${enumValues}]);`;
129
107
  const typeCode = `export type ${name} = z.infer<typeof ${schemaName}>;`;
130
- return { enumCode: null, schemaCode, typeCode };
108
+ return { schemaCode, typeCode };
131
109
  }
132
110
 
133
111
  // src/utils/string-utils.ts
@@ -226,6 +204,9 @@ var LRUCache = class {
226
204
  this.cache = /* @__PURE__ */ new Map();
227
205
  this.maxSize = maxSize;
228
206
  }
207
+ get capacity() {
208
+ return this.maxSize;
209
+ }
229
210
  get(key) {
230
211
  if (!this.cache.has(key)) return void 0;
231
212
  const value = this.cache.get(key);
@@ -775,6 +756,11 @@ ${properties.join(",\n")}
775
756
 
776
757
  // src/validators/string-validator.ts
777
758
  var PATTERN_CACHE = new LRUCache(1e3);
759
+ function configurePatternCache(size) {
760
+ if (size > 0 && size !== PATTERN_CACHE.capacity) {
761
+ PATTERN_CACHE = new LRUCache(size);
762
+ }
763
+ }
778
764
  var FORMAT_MAP = {
779
765
  uuid: "z.uuid()",
780
766
  email: "z.email()",
@@ -1391,14 +1377,11 @@ var OpenApiGenerator = class {
1391
1377
  constructor(options) {
1392
1378
  this.schemas = /* @__PURE__ */ new Map();
1393
1379
  this.types = /* @__PURE__ */ new Map();
1394
- this.enums = /* @__PURE__ */ new Map();
1395
- this.nativeEnums = /* @__PURE__ */ new Map();
1396
1380
  this.schemaDependencies = /* @__PURE__ */ new Map();
1397
1381
  this.schemaUsageMap = /* @__PURE__ */ new Map();
1398
- this.schemaTypeModeMap = /* @__PURE__ */ new Map();
1399
- this.needsZodImport = false;
1382
+ this.needsZodImport = true;
1400
1383
  this.filterStats = createFilterStatistics();
1401
- var _a, _b, _c;
1384
+ var _a, _b, _c, _d, _e;
1402
1385
  if (!options.input) {
1403
1386
  throw new ConfigurationError("Input path is required", { providedOptions: options });
1404
1387
  }
@@ -1407,17 +1390,21 @@ var OpenApiGenerator = class {
1407
1390
  input: options.input,
1408
1391
  output: options.output,
1409
1392
  includeDescriptions: (_a = options.includeDescriptions) != null ? _a : true,
1410
- enumType: options.enumType || "zod",
1411
1393
  useDescribe: (_b = options.useDescribe) != null ? _b : false,
1412
1394
  schemaType: options.schemaType || "all",
1413
1395
  prefix: options.prefix,
1414
1396
  suffix: options.suffix,
1415
1397
  showStats: (_c = options.showStats) != null ? _c : true,
1416
- nativeEnumType: options.nativeEnumType || "union",
1417
1398
  request: options.request,
1418
1399
  response: options.response,
1419
- operationFilters: options.operationFilters
1400
+ operationFilters: options.operationFilters,
1401
+ ignoreHeaders: options.ignoreHeaders,
1402
+ cacheSize: (_d = options.cacheSize) != null ? _d : 1e3,
1403
+ batchSize: (_e = options.batchSize) != null ? _e : 10
1420
1404
  };
1405
+ if (this.options.cacheSize) {
1406
+ configurePatternCache(this.options.cacheSize);
1407
+ }
1421
1408
  try {
1422
1409
  const fs = __require("fs");
1423
1410
  if (!fs.existsSync(this.options.input)) {
@@ -1473,7 +1460,6 @@ var OpenApiGenerator = class {
1473
1460
  this.requestOptions = this.resolveOptionsForContext("request");
1474
1461
  this.responseOptions = this.resolveOptionsForContext("response");
1475
1462
  this.analyzeSchemaUsage();
1476
- this.determineSchemaTypeModes();
1477
1463
  this.propertyGenerator = new PropertyGenerator({
1478
1464
  spec: this.spec,
1479
1465
  schemaDependencies: this.schemaDependencies,
@@ -1481,8 +1467,6 @@ var OpenApiGenerator = class {
1481
1467
  mode: this.requestOptions.mode,
1482
1468
  includeDescriptions: this.requestOptions.includeDescriptions,
1483
1469
  useDescribe: this.requestOptions.useDescribe,
1484
- typeMode: this.requestOptions.typeMode,
1485
- nativeEnumType: this.requestOptions.nativeEnumType,
1486
1470
  namingOptions: {
1487
1471
  prefix: this.options.prefix,
1488
1472
  suffix: this.options.suffix
@@ -1498,25 +1482,6 @@ var OpenApiGenerator = class {
1498
1482
  if (!((_a = this.spec.components) == null ? void 0 : _a.schemas)) {
1499
1483
  throw new SpecValidationError("No schemas found in OpenAPI spec", { filePath: this.options.input });
1500
1484
  }
1501
- for (const [name, schema] of Object.entries(this.spec.components.schemas)) {
1502
- if (schema.enum) {
1503
- const context = this.schemaUsageMap.get(name);
1504
- const resolvedOptions = context === "response" ? this.responseOptions : this.requestOptions;
1505
- if (resolvedOptions.enumType === "typescript") {
1506
- this.generateNativeEnum(name, schema);
1507
- } else {
1508
- const { enumCode } = generateEnum(name, schema.enum, {
1509
- enumType: "zod",
1510
- prefix: this.options.prefix,
1511
- suffix: this.options.suffix
1512
- });
1513
- if (enumCode) {
1514
- this.enums.set(name, enumCode);
1515
- this.needsZodImport = true;
1516
- }
1517
- }
1518
- }
1519
- }
1520
1485
  for (const [name, schema] of Object.entries(this.spec.components.schemas)) {
1521
1486
  this.generateComponentSchema(name, schema);
1522
1487
  }
@@ -1533,22 +1498,11 @@ var OpenApiGenerator = class {
1533
1498
  output.push('import { z } from "zod";');
1534
1499
  output.push("");
1535
1500
  }
1536
- if (this.nativeEnums.size > 0) {
1537
- output.push("// Native Enums");
1538
- for (const enumCode of this.nativeEnums.values()) {
1539
- output.push(enumCode);
1540
- output.push("");
1541
- }
1542
- }
1543
1501
  output.push("// Schemas and Types");
1544
1502
  for (const name of orderedSchemaNames) {
1545
- const enumCode = this.enums.get(name);
1546
1503
  const schemaCode = this.schemas.get(name);
1547
1504
  const typeCode = this.types.get(name);
1548
- if (enumCode) {
1549
- output.push(enumCode);
1550
- output.push("");
1551
- } else if (schemaCode) {
1505
+ if (schemaCode) {
1552
1506
  output.push(schemaCode);
1553
1507
  if (!schemaCode.includes(`export type ${name}`)) {
1554
1508
  const schemaName = `${toCamelCase(name, { prefix: this.options.prefix, suffix: this.options.suffix })}Schema`;
@@ -1586,25 +1540,19 @@ var OpenApiGenerator = class {
1586
1540
  const normalizedOutput = normalize(this.options.output);
1587
1541
  this.ensureDirectoryExists(normalizedOutput);
1588
1542
  writeFileSync(normalizedOutput, output);
1543
+ console.log(` \u2713 Generated ${normalizedOutput}`);
1589
1544
  }
1590
1545
  /**
1591
1546
  * Resolve options for a specific context (request or response)
1592
1547
  * Nested options silently override root-level options
1593
- * Response schemas always use 'inferred' mode (Zod schemas)
1594
1548
  */
1595
1549
  resolveOptionsForContext(context) {
1596
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1550
+ var _a, _b, _c, _d, _e, _f;
1597
1551
  const contextOptions = context === "request" ? this.options.request : this.options.response;
1598
- const nativeEnumType = context === "request" ? (_c = (_b = (_a = this.options.request) == null ? void 0 : _a.nativeEnumType) != null ? _b : this.options.nativeEnumType) != null ? _c : "union" : (_d = this.options.nativeEnumType) != null ? _d : "union";
1599
1552
  return {
1600
- mode: (_f = (_e = contextOptions == null ? void 0 : contextOptions.mode) != null ? _e : this.options.mode) != null ? _f : "normal",
1601
- enumType: (_h = (_g = contextOptions == null ? void 0 : contextOptions.enumType) != null ? _g : this.options.enumType) != null ? _h : "zod",
1602
- useDescribe: (_j = (_i = contextOptions == null ? void 0 : contextOptions.useDescribe) != null ? _i : this.options.useDescribe) != null ? _j : false,
1603
- includeDescriptions: (_l = (_k = contextOptions == null ? void 0 : contextOptions.includeDescriptions) != null ? _k : this.options.includeDescriptions) != null ? _l : true,
1604
- // Response schemas always use 'inferred' mode (Zod schemas are required)
1605
- // Request schemas can optionally use 'native' mode
1606
- typeMode: context === "response" ? "inferred" : (_n = (_m = this.options.request) == null ? void 0 : _m.typeMode) != null ? _n : "inferred",
1607
- nativeEnumType
1553
+ mode: (_b = (_a = contextOptions == null ? void 0 : contextOptions.mode) != null ? _a : this.options.mode) != null ? _b : "normal",
1554
+ useDescribe: (_d = (_c = contextOptions == null ? void 0 : contextOptions.useDescribe) != null ? _c : this.options.useDescribe) != null ? _d : false,
1555
+ includeDescriptions: (_f = (_e = contextOptions == null ? void 0 : contextOptions.includeDescriptions) != null ? _e : this.options.includeDescriptions) != null ? _f : true
1608
1556
  };
1609
1557
  }
1610
1558
  /**
@@ -1795,28 +1743,6 @@ var OpenApiGenerator = class {
1795
1743
  detectCycle(name);
1796
1744
  }
1797
1745
  }
1798
- /**
1799
- * Determine the typeMode for each schema based on its usage context
1800
- * Response schemas always use 'inferred' mode
1801
- */
1802
- determineSchemaTypeModes() {
1803
- var _a;
1804
- for (const [name] of Object.entries(((_a = this.spec.components) == null ? void 0 : _a.schemas) || {})) {
1805
- const context = this.schemaUsageMap.get(name);
1806
- if (context === "request") {
1807
- this.schemaTypeModeMap.set(name, this.requestOptions.typeMode);
1808
- } else if (context === "response") {
1809
- this.schemaTypeModeMap.set(name, "inferred");
1810
- } else if (context === "both") {
1811
- this.schemaTypeModeMap.set(name, "inferred");
1812
- } else {
1813
- this.schemaTypeModeMap.set(name, "inferred");
1814
- }
1815
- if (this.schemaTypeModeMap.get(name) === "inferred") {
1816
- this.needsZodImport = true;
1817
- }
1818
- }
1819
- }
1820
1746
  /**
1821
1747
  * Validate the OpenAPI specification
1822
1748
  */
@@ -1892,80 +1818,54 @@ var OpenApiGenerator = class {
1892
1818
  if (!this.schemaDependencies.has(name)) {
1893
1819
  this.schemaDependencies.set(name, /* @__PURE__ */ new Set());
1894
1820
  }
1895
- const typeMode = this.schemaTypeModeMap.get(name) || "inferred";
1896
1821
  const context = this.schemaUsageMap.get(name);
1897
1822
  const resolvedOptions = context === "response" ? this.responseOptions : this.requestOptions;
1898
1823
  if (schema.enum) {
1899
- const jsdoc = generateJSDoc(schema, name, { includeDescriptions: resolvedOptions.includeDescriptions });
1900
- if (resolvedOptions.enumType === "typescript") {
1901
- const { schemaCode, typeCode } = generateEnum(name, schema.enum, {
1902
- enumType: "typescript",
1903
- prefix: this.options.prefix,
1904
- suffix: this.options.suffix
1905
- });
1906
- const enumSchemaCode = `${jsdoc}${schemaCode}
1907
- ${typeCode}`;
1908
- this.schemas.set(name, enumSchemaCode);
1909
- } else {
1910
- const { enumCode, schemaCode, typeCode } = generateEnum(name, schema.enum, {
1911
- enumType: "zod",
1912
- prefix: this.options.prefix,
1913
- suffix: this.options.suffix
1914
- });
1915
- if (enumCode) {
1916
- this.enums.set(name, enumCode);
1917
- }
1918
- const enumSchemaCode = `${jsdoc}${schemaCode}
1824
+ const jsdoc2 = generateJSDoc(schema, name, { includeDescriptions: resolvedOptions.includeDescriptions });
1825
+ const { schemaCode, typeCode } = generateEnum(name, schema.enum, {
1826
+ prefix: this.options.prefix,
1827
+ suffix: this.options.suffix
1828
+ });
1829
+ const enumSchemaCode = `${jsdoc2}${schemaCode}
1919
1830
  ${typeCode}`;
1920
- this.schemas.set(name, enumSchemaCode);
1921
- }
1831
+ this.schemas.set(name, enumSchemaCode);
1922
1832
  return;
1923
1833
  }
1924
- if (typeMode === "native") {
1925
- const jsdoc = generateJSDoc(schema, name, { includeDescriptions: resolvedOptions.includeDescriptions });
1926
- const jsdocWithConstraints = this.addConstraintsToJSDoc(jsdoc, schema, resolvedOptions.includeDescriptions);
1927
- const typeDefinition = this.generateNativeTypeDefinition(schema, name);
1928
- const typeCode = `${jsdocWithConstraints}export type ${name} = ${typeDefinition};`;
1929
- this.types.set(name, typeCode);
1930
- } else {
1931
- const schemaName = `${toCamelCase(name, { prefix: this.options.prefix, suffix: this.options.suffix })}Schema`;
1932
- const jsdoc = generateJSDoc(schema, name, { includeDescriptions: resolvedOptions.includeDescriptions });
1933
- if (schema.allOf && schema.allOf.length === 1 && schema.allOf[0].$ref) {
1934
- const refName = resolveRef(schema.allOf[0].$ref);
1935
- (_a = this.schemaDependencies.get(name)) == null ? void 0 : _a.add(refName);
1834
+ const schemaName = `${toCamelCase(name, { prefix: this.options.prefix, suffix: this.options.suffix })}Schema`;
1835
+ const jsdoc = generateJSDoc(schema, name, { includeDescriptions: resolvedOptions.includeDescriptions });
1836
+ if (schema.allOf && schema.allOf.length === 1 && schema.allOf[0].$ref) {
1837
+ const refName = resolveRef(schema.allOf[0].$ref);
1838
+ (_a = this.schemaDependencies.get(name)) == null ? void 0 : _a.add(refName);
1839
+ }
1840
+ this.propertyGenerator = new PropertyGenerator({
1841
+ spec: this.spec,
1842
+ schemaDependencies: this.schemaDependencies,
1843
+ schemaType: this.options.schemaType || "all",
1844
+ mode: resolvedOptions.mode,
1845
+ includeDescriptions: resolvedOptions.includeDescriptions,
1846
+ useDescribe: resolvedOptions.useDescribe,
1847
+ namingOptions: {
1848
+ prefix: this.options.prefix,
1849
+ suffix: this.options.suffix
1936
1850
  }
1937
- this.propertyGenerator = new PropertyGenerator({
1938
- spec: this.spec,
1939
- schemaDependencies: this.schemaDependencies,
1940
- schemaType: this.options.schemaType || "all",
1941
- mode: resolvedOptions.mode,
1942
- includeDescriptions: resolvedOptions.includeDescriptions,
1943
- useDescribe: resolvedOptions.useDescribe,
1944
- typeMode: resolvedOptions.typeMode,
1945
- nativeEnumType: resolvedOptions.nativeEnumType,
1946
- namingOptions: {
1947
- prefix: this.options.prefix,
1948
- suffix: this.options.suffix
1949
- }
1950
- });
1951
- const isAlias = !!(schema.$ref && !schema.properties && !schema.allOf && !schema.oneOf && !schema.anyOf);
1952
- const zodSchema = this.propertyGenerator.generatePropertySchema(schema, name, isAlias);
1953
- const zodSchemaCode = `${jsdoc}export const ${schemaName} = ${zodSchema};`;
1954
- if (zodSchema.includes("z.discriminatedUnion(")) {
1955
- const match = zodSchema.match(/z\.discriminatedUnion\([^,]+,\s*\[([^\]]+)\]/);
1956
- if (match) {
1957
- const refs = match[1].split(",").map((ref) => ref.trim());
1958
- for (const ref of refs) {
1959
- const depMatch = ref.match(/^([a-z][a-zA-Z0-9]*?)Schema$/);
1960
- if (depMatch) {
1961
- const depName = depMatch[1].charAt(0).toUpperCase() + depMatch[1].slice(1);
1962
- (_b = this.schemaDependencies.get(name)) == null ? void 0 : _b.add(depName);
1963
- }
1851
+ });
1852
+ const isAlias = !!(schema.$ref && !schema.properties && !schema.allOf && !schema.oneOf && !schema.anyOf);
1853
+ const zodSchema = this.propertyGenerator.generatePropertySchema(schema, name, isAlias);
1854
+ const zodSchemaCode = `${jsdoc}export const ${schemaName} = ${zodSchema};`;
1855
+ if (zodSchema.includes("z.discriminatedUnion(")) {
1856
+ const match = zodSchema.match(/z\.discriminatedUnion\([^,]+,\s*\[([^\]]+)\]/);
1857
+ if (match) {
1858
+ const refs = match[1].split(",").map((ref) => ref.trim());
1859
+ for (const ref of refs) {
1860
+ const depMatch = ref.match(/^([a-z][a-zA-Z0-9]*?)Schema$/);
1861
+ if (depMatch) {
1862
+ const depName = depMatch[1].charAt(0).toUpperCase() + depMatch[1].slice(1);
1863
+ (_b = this.schemaDependencies.get(name)) == null ? void 0 : _b.add(depName);
1964
1864
  }
1965
1865
  }
1966
1866
  }
1967
- this.schemas.set(name, zodSchemaCode);
1968
1867
  }
1868
+ this.schemas.set(name, zodSchemaCode);
1969
1869
  }
1970
1870
  /**
1971
1871
  * Generate query parameter schemas for each operation
@@ -2051,6 +1951,24 @@ ${propsCode}
2051
1951
  }
2052
1952
  }
2053
1953
  }
1954
+ /**
1955
+ * Check if a header should be ignored based on filter patterns
1956
+ * @internal
1957
+ */
1958
+ shouldIgnoreHeader(headerName) {
1959
+ const ignorePatterns = this.options.ignoreHeaders;
1960
+ if (!ignorePatterns || ignorePatterns.length === 0) {
1961
+ return false;
1962
+ }
1963
+ if (ignorePatterns.includes("*")) {
1964
+ return true;
1965
+ }
1966
+ const headerLower = headerName.toLowerCase();
1967
+ return ignorePatterns.some((pattern) => {
1968
+ const patternLower = pattern.toLowerCase();
1969
+ return minimatch2(headerLower, patternLower);
1970
+ });
1971
+ }
2054
1972
  /**
2055
1973
  * Generate header parameter schemas for each operation
2056
1974
  * Header parameters are always string type (HTTP header semantics)
@@ -2073,7 +1991,7 @@ ${propsCode}
2073
1991
  continue;
2074
1992
  }
2075
1993
  const headerParams = operation.parameters.filter(
2076
- (param) => param && typeof param === "object" && param.in === "header"
1994
+ (param) => param && typeof param === "object" && param.in === "header" && !this.shouldIgnoreHeader(param.name)
2077
1995
  );
2078
1996
  if (headerParams.length === 0) {
2079
1997
  continue;
@@ -2171,151 +2089,11 @@ ${propsCode}
2171
2089
  }
2172
2090
  return "z.unknown()";
2173
2091
  }
2174
- /**
2175
- * Generate native TypeScript enum
2176
- */
2177
- generateNativeEnum(name, schema) {
2178
- if (!schema.enum) return;
2179
- const context = this.schemaUsageMap.get(name);
2180
- const resolvedOptions = context === "response" ? this.responseOptions : this.requestOptions;
2181
- const jsdoc = generateJSDoc(schema, name, { includeDescriptions: resolvedOptions.includeDescriptions });
2182
- if (resolvedOptions.nativeEnumType === "enum") {
2183
- const enumName = `${name}Enum`;
2184
- const members = schema.enum.map((value) => {
2185
- const key = typeof value === "string" ? this.toEnumKey(value) : `N${value}`;
2186
- const val = typeof value === "string" ? `"${value}"` : value;
2187
- return ` ${key} = ${val}`;
2188
- }).join(",\n");
2189
- const enumCode = `${jsdoc}export enum ${enumName} {
2190
- ${members}
2191
- }`;
2192
- this.nativeEnums.set(name, enumCode);
2193
- const typeCode = `export type ${name} = ${enumName};`;
2194
- this.types.set(name, typeCode);
2195
- } else {
2196
- const unionType = schema.enum.map((v) => typeof v === "string" ? `"${v}"` : v).join(" | ");
2197
- const typeCode = `${jsdoc}export type ${name} = ${unionType};`;
2198
- this.types.set(name, typeCode);
2199
- }
2200
- }
2201
- /**
2202
- * Convert string to valid enum key
2203
- */
2204
- toEnumKey(value) {
2205
- const cleaned = value.replace(/[^a-zA-Z0-9]/g, "_");
2206
- const pascalCase = cleaned.split("_").map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()).join("");
2207
- return pascalCase || "Value";
2208
- }
2209
- /**
2210
- * Add constraint annotations to JSDoc for native types
2211
- */
2212
- addConstraintsToJSDoc(jsdoc, schema, includeDescriptions) {
2213
- if (!includeDescriptions) return jsdoc;
2214
- const constraints = [];
2215
- if (schema.minLength !== void 0) constraints.push(`@minLength ${schema.minLength}`);
2216
- if (schema.maxLength !== void 0) constraints.push(`@maxLength ${schema.maxLength}`);
2217
- if (schema.pattern) constraints.push(`@pattern ${schema.pattern}`);
2218
- if (schema.minimum !== void 0) constraints.push(`@minimum ${schema.minimum}`);
2219
- if (schema.maximum !== void 0) constraints.push(`@maximum ${schema.maximum}`);
2220
- if (schema.minItems !== void 0) constraints.push(`@minItems ${schema.minItems}`);
2221
- if (schema.maxItems !== void 0) constraints.push(`@maxItems ${schema.maxItems}`);
2222
- if (schema.minProperties !== void 0) constraints.push(`@minProperties ${schema.minProperties}`);
2223
- if (schema.maxProperties !== void 0) constraints.push(`@maxProperties ${schema.maxProperties}`);
2224
- if (schema.multipleOf !== void 0) constraints.push(`@multipleOf ${schema.multipleOf}`);
2225
- if (schema.format) constraints.push(`@format ${schema.format}`);
2226
- if (constraints.length === 0) return jsdoc;
2227
- if (jsdoc) {
2228
- const lines = jsdoc.trim().split("\n");
2229
- if (lines[0] === "/**" && lines[lines.length - 1] === " */") {
2230
- const newLines = [...lines.slice(0, -1), ...constraints.map((c) => ` * ${c}`), " */\n"];
2231
- return newLines.join("\n");
2232
- }
2233
- const content = jsdoc.replace("/** ", "").replace(" */\n", "");
2234
- return `/**
2235
- * ${content}
2236
- ${constraints.map((c) => ` * ${c}`).join("\n")}
2237
- */
2238
- `;
2239
- }
2240
- return `/**
2241
- ${constraints.map((c) => ` * ${c}`).join("\n")}
2242
- */
2243
- `;
2244
- }
2245
- /**
2246
- * Generate native TypeScript type definition from OpenAPI schema
2247
- */
2248
- generateNativeTypeDefinition(schema, _schemaName) {
2249
- if (schema.$ref) {
2250
- return resolveRef(schema.$ref);
2251
- }
2252
- if (schema.const !== void 0) {
2253
- return typeof schema.const === "string" ? `"${schema.const}"` : String(schema.const);
2254
- }
2255
- const isNullable2 = schema.nullable || Array.isArray(schema.type) && schema.type.includes("null");
2256
- const wrapNullable2 = (type) => isNullable2 ? `(${type}) | null` : type;
2257
- const primaryType = Array.isArray(schema.type) ? schema.type.find((t) => t !== "null") : schema.type;
2258
- switch (primaryType) {
2259
- case "string":
2260
- return wrapNullable2("string");
2261
- case "number":
2262
- case "integer":
2263
- return wrapNullable2("number");
2264
- case "boolean":
2265
- return wrapNullable2("boolean");
2266
- case "array":
2267
- if (schema.items) {
2268
- const itemType = this.generateNativeTypeDefinition(schema.items);
2269
- return wrapNullable2(`${itemType}[]`);
2270
- }
2271
- return wrapNullable2("unknown[]");
2272
- case "object":
2273
- return wrapNullable2(this.generateObjectType(schema));
2274
- default:
2275
- if (schema.allOf) {
2276
- const types = schema.allOf.map((s) => this.generateNativeTypeDefinition(s));
2277
- return wrapNullable2(types.join(" & "));
2278
- }
2279
- if (schema.oneOf || schema.anyOf) {
2280
- const schemas = schema.oneOf || schema.anyOf || [];
2281
- const types = schemas.map((s) => this.generateNativeTypeDefinition(s));
2282
- return wrapNullable2(types.join(" | "));
2283
- }
2284
- return wrapNullable2("unknown");
2285
- }
2286
- }
2287
- /**
2288
- * Generate TypeScript object type definition
2289
- */
2290
- generateObjectType(schema) {
2291
- if (!schema.properties || Object.keys(schema.properties).length === 0) {
2292
- return "Record<string, unknown>";
2293
- }
2294
- const context = this.schemaUsageMap.get(schema.$ref ? resolveRef(schema.$ref) : "");
2295
- const resolvedOptions = context === "response" ? this.responseOptions : this.requestOptions;
2296
- const required = new Set(schema.required || []);
2297
- const props = [];
2298
- for (const [propName, propSchema] of Object.entries(schema.properties)) {
2299
- const propType = this.generateNativeTypeDefinition(propSchema);
2300
- const optional = !required.has(propName) ? "?" : "";
2301
- let propJsdoc = generateJSDoc(propSchema, propName, { includeDescriptions: resolvedOptions.includeDescriptions });
2302
- if (resolvedOptions.includeDescriptions && !propJsdoc) {
2303
- propJsdoc = this.addConstraintsToJSDoc("", propSchema, resolvedOptions.includeDescriptions);
2304
- } else if (propJsdoc && resolvedOptions.includeDescriptions) {
2305
- propJsdoc = this.addConstraintsToJSDoc(propJsdoc, propSchema, resolvedOptions.includeDescriptions);
2306
- }
2307
- if (propJsdoc) {
2308
- const cleanJsdoc = propJsdoc.trimEnd();
2309
- props.push(` ${cleanJsdoc}
2310
- ${propName}${optional}: ${propType};`);
2311
- } else {
2312
- props.push(` ${propName}${optional}: ${propType};`);
2313
- }
2314
- }
2315
- return `{
2316
- ${props.join("\n")}
2317
- }`;
2318
- }
2092
+ // REMOVED: generateNativeEnum method - no longer needed as we only generate Zod schemas
2093
+ // REMOVED: toEnumKey method - was only used by generateNativeEnum
2094
+ // REMOVED: addConstraintsToJSDoc method - was only used for native TypeScript types
2095
+ // REMOVED: generateNativeTypeDefinition method - was only used for native TypeScript types
2096
+ // REMOVED: generateObjectType method - was only used for native TypeScript types
2319
2097
  /**
2320
2098
  * Topological sort for schema dependencies
2321
2099
  * Returns schemas in the order they should be declared
@@ -2327,9 +2105,6 @@ ${props.join("\n")}
2327
2105
  const aliases = [];
2328
2106
  const circularDeps = /* @__PURE__ */ new Set();
2329
2107
  const codeCache = /* @__PURE__ */ new Map();
2330
- for (const [name, code] of this.enums) {
2331
- codeCache.set(name, code);
2332
- }
2333
2108
  for (const [name, code] of this.schemas) {
2334
2109
  codeCache.set(name, code);
2335
2110
  }
@@ -2354,7 +2129,7 @@ ${props.join("\n")}
2354
2129
  const deps = this.schemaDependencies.get(name);
2355
2130
  if (deps && deps.size > 0) {
2356
2131
  for (const dep of deps) {
2357
- if (this.enums.has(dep) || this.schemas.has(dep) || this.types.has(dep)) {
2132
+ if (this.schemas.has(dep) || this.types.has(dep)) {
2358
2133
  visit(dep);
2359
2134
  }
2360
2135
  }
@@ -2365,7 +2140,7 @@ ${props.join("\n")}
2365
2140
  sorted.push(name);
2366
2141
  }
2367
2142
  };
2368
- const allNames = /* @__PURE__ */ new Set([...this.enums.keys(), ...this.schemas.keys(), ...this.types.keys()]);
2143
+ const allNames = /* @__PURE__ */ new Set([...this.schemas.keys(), ...this.types.keys()]);
2369
2144
  for (const name of allNames) {
2370
2145
  visit(name);
2371
2146
  }
@@ -2383,7 +2158,6 @@ ${props.join("\n")}
2383
2158
  generateStats() {
2384
2159
  const stats = {
2385
2160
  totalSchemas: this.schemas.size,
2386
- enums: this.enums.size,
2387
2161
  withCircularRefs: 0,
2388
2162
  withDiscriminators: 0,
2389
2163
  withConstraints: 0
@@ -2398,7 +2172,6 @@ ${props.join("\n")}
2398
2172
  const output = [
2399
2173
  "// Generation Statistics:",
2400
2174
  `// Total schemas: ${stats.totalSchemas}`,
2401
- `// Enums: ${stats.enums}`,
2402
2175
  `// Circular references: ${stats.withCircularRefs}`,
2403
2176
  `// Discriminated unions: ${stats.withDiscriminators}`,
2404
2177
  `// With constraints: ${stats.withConstraints}`
@@ -2428,10 +2201,6 @@ export {
2428
2201
  OpenApiGenerator,
2429
2202
  SchemaGenerationError,
2430
2203
  SpecValidationError,
2431
- createFilterStatistics,
2432
- defineConfig,
2433
- formatFilterStatistics,
2434
- shouldIncludeOperation,
2435
- validateFilters
2204
+ defineConfig
2436
2205
  };
2437
2206
  //# sourceMappingURL=index.mjs.map