@alt-stack/zod-openapi 1.1.3 → 1.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/.turbo/turbo-build.log +10 -10
- package/dist/index.cjs +161 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +158 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/interface-generator.spec.ts +595 -0
- package/src/interface-generator.ts +211 -0
- package/src/to-typescript.ts +25 -2
- package/src/to-zod.spec.ts +10 -6
package/dist/index.js
CHANGED
|
@@ -669,11 +669,150 @@ function generateRouteSchemaNames(route) {
|
|
|
669
669
|
return result;
|
|
670
670
|
}
|
|
671
671
|
|
|
672
|
-
// src/
|
|
672
|
+
// src/interface-generator.ts
|
|
673
673
|
var validIdentifierRegex2 = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
674
674
|
function quotePropertyName2(name) {
|
|
675
675
|
return validIdentifierRegex2.test(name) ? name : `'${name}'`;
|
|
676
676
|
}
|
|
677
|
+
function schemaToTypeString(schema) {
|
|
678
|
+
if (!schema || typeof schema !== "object") return "unknown";
|
|
679
|
+
if (schema["$ref"] && typeof schema["$ref"] === "string") {
|
|
680
|
+
const match = schema["$ref"].match(
|
|
681
|
+
/#\/components\/schemas\/(.+)/
|
|
682
|
+
);
|
|
683
|
+
let result2 = "unknown";
|
|
684
|
+
if (match && match[1]) {
|
|
685
|
+
result2 = decodeURIComponent(match[1]);
|
|
686
|
+
}
|
|
687
|
+
if (schema["nullable"] === true) {
|
|
688
|
+
result2 = `(${result2} | null)`;
|
|
689
|
+
}
|
|
690
|
+
return result2;
|
|
691
|
+
}
|
|
692
|
+
let result = "unknown";
|
|
693
|
+
if ("oneOf" in schema && Array.isArray(schema["oneOf"])) {
|
|
694
|
+
const unionMembers = schema["oneOf"].map(
|
|
695
|
+
(s) => schemaToTypeString(s)
|
|
696
|
+
);
|
|
697
|
+
result = unionMembers.length > 1 ? `(${unionMembers.join(" | ")})` : unionMembers[0] ?? "unknown";
|
|
698
|
+
} else if ("allOf" in schema && Array.isArray(schema["allOf"])) {
|
|
699
|
+
const intersectionMembers = schema["allOf"].map(
|
|
700
|
+
(s) => schemaToTypeString(s)
|
|
701
|
+
);
|
|
702
|
+
result = intersectionMembers.length > 1 ? `(${intersectionMembers.join(" & ")})` : intersectionMembers[0] ?? "unknown";
|
|
703
|
+
} else if ("anyOf" in schema && Array.isArray(schema["anyOf"])) {
|
|
704
|
+
const unionMembers = schema["anyOf"].map(
|
|
705
|
+
(s) => schemaToTypeString(s)
|
|
706
|
+
);
|
|
707
|
+
result = unionMembers.length > 1 ? `(${unionMembers.join(" | ")})` : unionMembers[0] ?? "unknown";
|
|
708
|
+
} else {
|
|
709
|
+
switch (schema["type"]) {
|
|
710
|
+
case "string":
|
|
711
|
+
if (schema["enum"] && Array.isArray(schema["enum"])) {
|
|
712
|
+
result = schema["enum"].map((v) => JSON.stringify(v)).join(" | ");
|
|
713
|
+
} else {
|
|
714
|
+
result = "string";
|
|
715
|
+
}
|
|
716
|
+
break;
|
|
717
|
+
case "number":
|
|
718
|
+
case "integer":
|
|
719
|
+
if (schema["enum"] && Array.isArray(schema["enum"])) {
|
|
720
|
+
result = schema["enum"].map((v) => String(v)).join(" | ");
|
|
721
|
+
} else {
|
|
722
|
+
result = "number";
|
|
723
|
+
}
|
|
724
|
+
break;
|
|
725
|
+
case "boolean":
|
|
726
|
+
result = "boolean";
|
|
727
|
+
break;
|
|
728
|
+
case "null":
|
|
729
|
+
result = "null";
|
|
730
|
+
break;
|
|
731
|
+
case "array":
|
|
732
|
+
if (schema["items"]) {
|
|
733
|
+
const itemType = schemaToTypeString(schema["items"]);
|
|
734
|
+
result = `Array<${itemType}>`;
|
|
735
|
+
} else {
|
|
736
|
+
result = "unknown[]";
|
|
737
|
+
}
|
|
738
|
+
break;
|
|
739
|
+
case "object":
|
|
740
|
+
result = objectSchemaToTypeString(schema);
|
|
741
|
+
break;
|
|
742
|
+
default:
|
|
743
|
+
if (schema["properties"]) {
|
|
744
|
+
result = objectSchemaToTypeString(schema);
|
|
745
|
+
} else if (schema["enum"] && Array.isArray(schema["enum"])) {
|
|
746
|
+
result = schema["enum"].map((v) => JSON.stringify(v)).join(" | ");
|
|
747
|
+
} else {
|
|
748
|
+
result = "unknown";
|
|
749
|
+
}
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (schema["nullable"] === true) {
|
|
754
|
+
result = `(${result} | null)`;
|
|
755
|
+
}
|
|
756
|
+
return result;
|
|
757
|
+
}
|
|
758
|
+
function objectSchemaToTypeString(schema) {
|
|
759
|
+
const properties = schema["properties"];
|
|
760
|
+
const required = new Set(schema["required"] ?? []);
|
|
761
|
+
const additionalProperties = schema["additionalProperties"];
|
|
762
|
+
if (!properties && !additionalProperties) {
|
|
763
|
+
return "Record<string, unknown>";
|
|
764
|
+
}
|
|
765
|
+
const propertyStrings = [];
|
|
766
|
+
if (properties) {
|
|
767
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
768
|
+
const isRequired = required.has(propName);
|
|
769
|
+
const propType = schemaToTypeString(propSchema);
|
|
770
|
+
const quotedName = quotePropertyName2(propName);
|
|
771
|
+
propertyStrings.push(
|
|
772
|
+
`${quotedName}${isRequired ? "" : "?"}: ${propType}`
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
if (additionalProperties === true) {
|
|
777
|
+
propertyStrings.push("[key: string]: unknown");
|
|
778
|
+
} else if (typeof additionalProperties === "object" && additionalProperties !== null) {
|
|
779
|
+
const additionalType = schemaToTypeString(additionalProperties);
|
|
780
|
+
propertyStrings.push(`[key: string]: ${additionalType}`);
|
|
781
|
+
}
|
|
782
|
+
return `{ ${propertyStrings.join("; ")} }`;
|
|
783
|
+
}
|
|
784
|
+
function generateInterface(name, schema) {
|
|
785
|
+
const properties = schema["properties"];
|
|
786
|
+
const required = new Set(schema["required"] ?? []);
|
|
787
|
+
if (schema["type"] !== "object" && !properties) {
|
|
788
|
+
return `export type ${name} = ${schemaToTypeString(schema)};`;
|
|
789
|
+
}
|
|
790
|
+
const lines = [];
|
|
791
|
+
lines.push(`export interface ${name} {`);
|
|
792
|
+
if (properties) {
|
|
793
|
+
for (const [propName, propSchema] of Object.entries(properties)) {
|
|
794
|
+
const isRequired = required.has(propName);
|
|
795
|
+
const propType = schemaToTypeString(propSchema);
|
|
796
|
+
const quotedName = quotePropertyName2(propName);
|
|
797
|
+
lines.push(` ${quotedName}${isRequired ? "" : "?"}: ${propType};`);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
const additionalProperties = schema["additionalProperties"];
|
|
801
|
+
if (additionalProperties === true) {
|
|
802
|
+
lines.push(" [key: string]: unknown;");
|
|
803
|
+
} else if (typeof additionalProperties === "object" && additionalProperties !== null) {
|
|
804
|
+
const additionalType = schemaToTypeString(additionalProperties);
|
|
805
|
+
lines.push(` [key: string]: ${additionalType};`);
|
|
806
|
+
}
|
|
807
|
+
lines.push("}");
|
|
808
|
+
return lines.join("\n");
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// src/to-typescript.ts
|
|
812
|
+
var validIdentifierRegex3 = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
813
|
+
function quotePropertyName3(name) {
|
|
814
|
+
return validIdentifierRegex3.test(name) ? name : `'${name}'`;
|
|
815
|
+
}
|
|
677
816
|
function generateRouteSchemaName2(path, method, suffix) {
|
|
678
817
|
const pathParts = path.split("/").filter((p) => p).map((p) => {
|
|
679
818
|
if (p.startsWith("{") && p.endsWith("}")) {
|
|
@@ -715,7 +854,7 @@ function generateRouteSchemas(routes, convertSchema, registry) {
|
|
|
715
854
|
const properties = [];
|
|
716
855
|
for (const param of pathParams) {
|
|
717
856
|
const zodExpr = convertSchema(param.schema);
|
|
718
|
-
properties.push(`${
|
|
857
|
+
properties.push(`${quotePropertyName3(param.name)}: ${zodExpr}`);
|
|
719
858
|
}
|
|
720
859
|
declarations.push(
|
|
721
860
|
`export const ${names.paramsSchemaName} = z.object({ ${properties.join(", ")} });`
|
|
@@ -751,7 +890,7 @@ function generateRouteSchemas(routes, convertSchema, registry) {
|
|
|
751
890
|
if (!param.required) {
|
|
752
891
|
zodExpr += ".optional()";
|
|
753
892
|
}
|
|
754
|
-
properties.push(`${
|
|
893
|
+
properties.push(`${quotePropertyName3(param.name)}: ${zodExpr}`);
|
|
755
894
|
}
|
|
756
895
|
declarations.push(
|
|
757
896
|
`export const ${names.querySchemaName} = z.object({ ${properties.join(", ")} });`
|
|
@@ -787,7 +926,7 @@ function generateRouteSchemas(routes, convertSchema, registry) {
|
|
|
787
926
|
if (!param.required) {
|
|
788
927
|
zodExpr += ".optional()";
|
|
789
928
|
}
|
|
790
|
-
properties.push(`${
|
|
929
|
+
properties.push(`${quotePropertyName3(param.name)}: ${zodExpr}`);
|
|
791
930
|
}
|
|
792
931
|
declarations.push(
|
|
793
932
|
`export const ${names.headersSchemaName} = z.object({ ${properties.join(", ")} });`
|
|
@@ -982,21 +1121,31 @@ var openApiToZodTsCode = (openapi, customImportLines, options) => {
|
|
|
982
1121
|
lines.push("import { z } from 'zod';");
|
|
983
1122
|
lines.push(...customImportLines ?? []);
|
|
984
1123
|
lines.push("");
|
|
1124
|
+
lines.push("// Type assertion helper - verifies interface matches schema at compile time");
|
|
1125
|
+
lines.push("type _AssertEqual<T, U> = [T] extends [U] ? ([U] extends [T] ? true : never) : never;");
|
|
1126
|
+
lines.push("");
|
|
985
1127
|
const registry = createSchemaRegistry();
|
|
986
1128
|
const sortedSchemaNames = topologicalSortSchemas(schemas);
|
|
1129
|
+
const typeAssertions = [];
|
|
987
1130
|
for (const name of sortedSchemaNames) {
|
|
988
1131
|
const schema = schemas[name];
|
|
989
1132
|
if (schema) {
|
|
990
1133
|
const zodExpr = convertSchemaToZodString(schema);
|
|
991
1134
|
const schemaName = `${name}Schema`;
|
|
992
1135
|
const typeName = name;
|
|
993
|
-
lines.push(
|
|
994
|
-
lines.push(`export
|
|
1136
|
+
lines.push(generateInterface(typeName, schema));
|
|
1137
|
+
lines.push(`export const ${schemaName}: z.ZodType<${typeName}> = ${zodExpr};`);
|
|
995
1138
|
lines.push("");
|
|
1139
|
+
typeAssertions.push(`type _Assert${typeName} = _AssertEqual<${typeName}, z.infer<typeof ${schemaName}>>;`);
|
|
996
1140
|
const fingerprint = getSchemaFingerprint(schema);
|
|
997
1141
|
preRegisterSchema(registry, schemaName, fingerprint);
|
|
998
1142
|
}
|
|
999
1143
|
}
|
|
1144
|
+
if (typeAssertions.length > 0) {
|
|
1145
|
+
lines.push("// Compile-time type assertions - ensure interfaces match schemas");
|
|
1146
|
+
lines.push(typeAssertions.join("\n"));
|
|
1147
|
+
lines.push("");
|
|
1148
|
+
}
|
|
1000
1149
|
if (options?.includeRoutes) {
|
|
1001
1150
|
const routes = parseOpenApiPaths(openapi);
|
|
1002
1151
|
if (routes.length > 0) {
|
|
@@ -1034,11 +1183,13 @@ export {
|
|
|
1034
1183
|
SUPPORTED_STRING_FORMATS,
|
|
1035
1184
|
clearZodSchemaToOpenApiSchemaRegistry,
|
|
1036
1185
|
convertSchemaToZodString,
|
|
1186
|
+
generateInterface,
|
|
1037
1187
|
generateRouteSchemaNames,
|
|
1038
1188
|
getSchemaExportedVariableNameForStringFormat,
|
|
1039
1189
|
openApiToZodTsCode,
|
|
1040
1190
|
parseOpenApiPaths,
|
|
1041
1191
|
registerZodSchemaToOpenApiSchema,
|
|
1042
|
-
schemaRegistry
|
|
1192
|
+
schemaRegistry,
|
|
1193
|
+
schemaToTypeString
|
|
1043
1194
|
};
|
|
1044
1195
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dependencies.ts","../src/schema-dedup.ts","../src/types/boolean.ts","../src/types/number.ts","../src/registry.ts","../src/types/string.ts","../src/types/array.ts","../src/types/object.ts","../src/types/union.ts","../src/types/intersection.ts","../src/to-zod.ts","../src/routes.ts","../src/to-typescript.ts"],"sourcesContent":["import type { AnySchema } from \"./types/types\";\n\n/**\n * Extracts all schema references ($ref) from an OpenAPI schema by recursively\n * traversing its structure.\n *\n * This function is used during the OpenAPI-to-Zod conversion process to identify\n * which schemas a given schema depends on. It traverses all OpenAPI schema\n * structures including objects, arrays, unions (oneOf), intersections (allOf),\n * conditionals (if/then/else), and discriminator mappings to find all $ref\n * references that point to other schemas in the components/schemas section.\n *\n * The extracted dependency names are used by `topologicalSortSchemas` to build\n * a dependency graph and determine the correct order for generating Zod schemas,\n * ensuring that referenced schemas are defined before they are used in the\n * generated TypeScript code.\n *\n * @param schema - The OpenAPI schema to extract dependencies from\n * @returns An array of schema names that this schema references (via $ref)\n */\nexport function extractSchemaDependencies(schema: AnySchema): string[] {\n const dependencies: Set<string> = new Set();\n const visited = new WeakSet();\n\n function traverse(obj: any): void {\n if (!obj || typeof obj !== \"object\") return;\n\n if (visited.has(obj)) return;\n visited.add(obj);\n\n if (obj[\"$ref\"] && typeof obj[\"$ref\"] === \"string\") {\n const match = (obj[\"$ref\"] as string).match(\n /#\\/components\\/schemas\\/(.+)/,\n );\n if (match && match[1]) {\n dependencies.add(decodeURIComponent(match[1]));\n }\n return;\n }\n\n if (Array.isArray(obj)) {\n obj.forEach(traverse);\n return;\n }\n\n if (obj.properties && typeof obj.properties === \"object\") {\n for (const propValue of Object.values(obj.properties)) {\n traverse(propValue);\n }\n }\n\n const schemaKeys = [\n \"items\",\n \"oneOf\",\n \"allOf\",\n \"anyOf\",\n \"not\",\n \"if\",\n \"then\",\n \"else\",\n \"prefixItems\",\n \"contains\",\n \"propertyNames\",\n \"dependentSchemas\",\n ];\n\n for (const key of schemaKeys) {\n if (obj[key]) {\n traverse(obj[key]);\n }\n }\n\n if (\n obj.additionalProperties &&\n typeof obj.additionalProperties === \"object\"\n ) {\n traverse(obj.additionalProperties);\n }\n\n if (obj.discriminator?.mapping) {\n Object.values(obj.discriminator.mapping).forEach(traverse);\n }\n }\n\n traverse(schema);\n return Array.from(dependencies);\n}\n\n/**\n * Sorts OpenAPI schemas topologically based on their dependencies to ensure\n * correct generation order.\n *\n * When converting OpenAPI schemas to Zod schemas and generating TypeScript code,\n * schemas must be defined before they are referenced. For example, if `UserSchema`\n * references `ProfileSchema` (via $ref), then `ProfileSchema` must be generated\n * before `UserSchema` to avoid \"undefined variable\" errors in the generated code.\n *\n * This function uses Kahn's algorithm for topological sorting to order schemas\n * such that all dependencies come before their dependents. It:\n * 1. Extracts dependencies for each schema using `extractSchemaDependencies`\n * 2. Builds a dependency graph and computes in-degrees\n * 3. Sorts schemas starting with those that have no dependencies (in-degree 0)\n * 4. Handles circular dependencies gracefully by appending any remaining schemas\n * that couldn't be sorted (though this indicates a problematic schema structure)\n *\n * This function is called by `openApiToZodTsCode` to determine the order in which\n * schemas should be converted and emitted in the generated TypeScript file.\n *\n * @param schemas - A record mapping schema names to their OpenAPI schema definitions\n * @returns An array of schema names sorted in topological order (dependencies before dependents)\n */\nexport function topologicalSortSchemas(\n schemas: Record<string, AnySchema>,\n): string[] {\n const schemaNames = Object.keys(schemas);\n const dependencies: Map<string, string[]> = new Map();\n const inDegree: Map<string, number> = new Map();\n const sorted: string[] = [];\n const queue: string[] = [];\n const dependents: Map<string, string[]> = new Map();\n\n for (const name of schemaNames) {\n dependencies.set(name, []);\n dependents.set(name, []);\n inDegree.set(name, 0);\n }\n\n for (const name of schemaNames) {\n const schemaValue = schemas[name];\n if (schemaValue) {\n const deps = extractSchemaDependencies(schemaValue);\n const validDeps = deps.filter((dep) => schemaNames.includes(dep));\n dependencies.set(name, validDeps);\n\n for (const dep of validDeps) {\n const currentDependents = dependents.get(dep) || [];\n currentDependents.push(name);\n dependents.set(dep, currentDependents);\n }\n }\n }\n\n for (const [name, deps] of dependencies.entries()) {\n inDegree.set(name, deps.length);\n }\n\n for (const [name, degree] of inDegree.entries()) {\n if (degree === 0) {\n queue.push(name);\n }\n }\n\n while (queue.length > 0) {\n const current = queue.shift()!;\n sorted.push(current);\n\n const currentDependents = dependents.get(current) || [];\n for (const dependent of currentDependents) {\n const newDegree = (inDegree.get(dependent) || 0) - 1;\n inDegree.set(dependent, newDegree);\n if (newDegree === 0) {\n queue.push(dependent);\n }\n }\n }\n\n if (sorted.length !== schemaNames.length) {\n for (const name of schemaNames) {\n if (!sorted.includes(name)) {\n sorted.push(name);\n }\n }\n }\n\n return sorted;\n}\n","import type { AnySchema } from \"./types/types\";\n\n/**\n * Schema deduplication utilities for optimizing generated TypeScript types.\n *\n * This module provides fingerprinting and registry functionality to detect\n * structurally identical schemas and generate them only once, reducing\n * memory usage in consuming TypeScript projects.\n */\n\n/**\n * Recursively sorts an object's keys to create a stable representation.\n * This ensures that {a: 1, b: 2} and {b: 2, a: 1} produce the same fingerprint.\n */\nfunction sortObjectDeep(obj: unknown): unknown {\n if (obj === null || typeof obj !== \"object\") return obj;\n if (Array.isArray(obj)) return obj.map(sortObjectDeep);\n\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(obj as Record<string, unknown>).sort();\n for (const key of keys) {\n sorted[key] = sortObjectDeep((obj as Record<string, unknown>)[key]);\n }\n return sorted;\n}\n\n/**\n * Generates a canonical fingerprint for an OpenAPI schema.\n * Identical schemas will produce identical fingerprints.\n */\nexport function getSchemaFingerprint(schema: AnySchema): string {\n return JSON.stringify(sortObjectDeep(schema));\n}\n\n/**\n * Registry for tracking unique schemas and their canonical names.\n */\nexport interface SchemaRegistry {\n /** Map from fingerprint to the first schema name that used it */\n fingerprintToName: Map<string, string>;\n /** Map from schema name to its fingerprint (for reverse lookup) */\n nameToFingerprint: Map<string, string>;\n}\n\n/**\n * Creates a new empty schema registry.\n */\nexport function createSchemaRegistry(): SchemaRegistry {\n return {\n fingerprintToName: new Map(),\n nameToFingerprint: new Map(),\n };\n}\n\n/**\n * Result of registering a schema.\n */\nexport interface RegisterSchemaResult {\n /** Whether this is a new unique schema */\n isNew: boolean;\n /** The canonical name for this schema (may be different from input name if duplicate) */\n canonicalName: string;\n}\n\n/**\n * Registers a schema in the registry. If an identical schema already exists,\n * returns the existing canonical name instead.\n */\nexport function registerSchema(\n registry: SchemaRegistry,\n name: string,\n schema: AnySchema,\n): RegisterSchemaResult {\n const fingerprint = getSchemaFingerprint(schema);\n\n const existing = registry.fingerprintToName.get(fingerprint);\n if (existing) {\n return { isNew: false, canonicalName: existing };\n }\n\n registry.fingerprintToName.set(fingerprint, name);\n registry.nameToFingerprint.set(name, fingerprint);\n return { isNew: true, canonicalName: name };\n}\n\n/**\n * Pre-registers a schema with a specific fingerprint.\n * Used for common schemas that should take priority.\n */\nexport function preRegisterSchema(\n registry: SchemaRegistry,\n name: string,\n fingerprint: string,\n): void {\n registry.fingerprintToName.set(fingerprint, name);\n registry.nameToFingerprint.set(name, fingerprint);\n}\n\n/**\n * Extracts the error code from an OpenAPI error schema.\n * Looks for patterns like: { error: { code: enum(['UNAUTHORIZED']) } }\n */\nexport function extractErrorCode(schema: AnySchema): string | null {\n const properties = schema?.[\"properties\"] as Record<string, AnySchema> | undefined;\n const errorObj = properties?.[\"error\"] as AnySchema | undefined;\n const errorProps = errorObj?.[\"properties\"] as Record<string, AnySchema> | undefined;\n const codeSchema = errorProps?.[\"code\"] as AnySchema | undefined;\n const codeEnum = codeSchema?.[\"enum\"] as string[] | undefined;\n\n if (Array.isArray(codeEnum) && codeEnum.length === 1) {\n return codeEnum[0]!;\n }\n return null;\n}\n\n/**\n * Converts an error code like UNAUTHORIZED or NOT_FOUND to PascalCase.\n * UNAUTHORIZED -> Unauthorized\n * NOT_FOUND -> NotFound\n */\nexport function errorCodeToPascalCase(code: string): string {\n return code\n .split(\"_\")\n .map((part) => part.charAt(0) + part.slice(1).toLowerCase())\n .join(\"\");\n}\n\n/**\n * Generates a common error schema name from an error code.\n * UNAUTHORIZED -> UnauthorizedErrorSchema\n */\nexport function generateCommonErrorSchemaName(errorCode: string): string {\n return `${errorCodeToPascalCase(errorCode)}ErrorSchema`;\n}\n\n/**\n * Represents a common schema that appears multiple times.\n */\nexport interface CommonSchema {\n /** The canonical name for this schema */\n name: string;\n /** The schema definition */\n schema: AnySchema;\n /** The fingerprint for deduplication */\n fingerprint: string;\n /** Number of times this schema appears */\n count: number;\n}\n\n/**\n * Scans schemas and identifies those that appear multiple times.\n * Returns common schemas sorted by count (most common first).\n */\nexport function findCommonSchemas(\n schemas: Array<{ name: string; schema: AnySchema }>,\n minCount: number = 2,\n): CommonSchema[] {\n const fingerprints = new Map<\n string,\n { schema: AnySchema; names: string[]; errorCode: string | null }\n >();\n\n // Count occurrences of each unique schema\n for (const { name, schema } of schemas) {\n const fingerprint = getSchemaFingerprint(schema);\n const existing = fingerprints.get(fingerprint);\n\n if (existing) {\n existing.names.push(name);\n } else {\n fingerprints.set(fingerprint, {\n schema,\n names: [name],\n errorCode: extractErrorCode(schema),\n });\n }\n }\n\n // Filter to schemas appearing minCount+ times\n const commonSchemas: CommonSchema[] = [];\n for (const [fingerprint, data] of fingerprints) {\n if (data.names.length >= minCount) {\n // Generate a semantic name if it's an error schema, otherwise use first occurrence\n const name = data.errorCode\n ? generateCommonErrorSchemaName(data.errorCode)\n : data.names[0]!;\n\n commonSchemas.push({\n name,\n schema: data.schema,\n fingerprint,\n count: data.names.length,\n });\n }\n }\n\n // Sort by count descending (most common first)\n return commonSchemas.sort((a, b) => b.count - a.count);\n}\n","/**\n * Convert an OpenAPI v3 boolean schema to a Zod schema string\n */\nexport function convertOpenAPIBooleanToZod(_: { type: \"boolean\" }): string {\n return \"z.boolean()\";\n}\n","/**\n * Convert an OpenAPI v3 number/integer schema to a Zod schema string\n */\nexport function convertOpenAPINumberToZod(schema: {\n type: \"number\" | \"integer\";\n minimum?: number;\n maximum?: number;\n}): string {\n let result = \"z.number()\";\n if (schema.type === \"integer\") {\n result += \".int()\";\n }\n if (typeof schema.minimum === \"number\") {\n result += `.min(${schema.minimum})`;\n }\n if (typeof schema.maximum === \"number\") {\n result += `.max(${schema.maximum})`;\n }\n return result;\n}\n","import { z } from \"zod\";\n\n// ============================================================================\n// Constants\n// ============================================================================\n\nconst SUPPORTED_STRING_FORMATS_MAP = {\n \"color-hex\": 1,\n date: 1,\n \"date-time\": 1,\n email: 1,\n \"iso-date\": 1,\n \"iso-date-time\": 1,\n objectid: 1,\n uri: 1,\n url: 1,\n uuid: 1,\n} as const;\n\nexport const SUPPORTED_STRING_FORMATS = Object.keys(\n SUPPORTED_STRING_FORMATS_MAP,\n) as unknown as keyof typeof SUPPORTED_STRING_FORMATS_MAP;\n\ntype SupportedStringFormat = typeof SUPPORTED_STRING_FORMATS;\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport type ZodOpenApiRegistrationString<\n F extends SupportedStringFormat = SupportedStringFormat,\n> = {\n /** The name of the schema variable, IMPORTANT: must be named the same as the variable name */\n schemaExportedVariableName: string;\n type: \"string\";\n description?: string;\n format: F;\n};\n\nexport type ZodOpenApiRegistrationStrings<\n Fs extends\n readonly SupportedStringFormat[] = readonly SupportedStringFormat[],\n> = {\n /** The name of the schema variable, IMPORTANT: must be named the same as the variable name */\n schemaExportedVariableName: string;\n type: \"string\";\n description?: string;\n formats: Fs;\n};\n\nexport type ZodOpenApiRegistrationPrimitive = {\n /** The name of the schema variable, IMPORTANT: must be named the same as the variable name */\n schemaExportedVariableName: string;\n description?: string;\n type: \"number\" | \"integer\" | \"boolean\";\n};\n\nexport type ZodOpenApiRegistration =\n | ZodOpenApiRegistrationString\n | ZodOpenApiRegistrationStrings\n | ZodOpenApiRegistrationPrimitive;\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\nfunction isStringRegistration(\n reg: ZodOpenApiRegistration,\n): reg is ZodOpenApiRegistrationString {\n return reg.type === \"string\" && \"format\" in reg;\n}\n\nfunction isStringsRegistration(\n reg: ZodOpenApiRegistration,\n): reg is ZodOpenApiRegistrationStrings {\n return reg.type === \"string\" && \"formats\" in reg;\n}\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\ntype TypeFormatPair = { type: string; format: string | undefined };\n\nfunction getTypeFormatPairs(reg: ZodOpenApiRegistration): TypeFormatPair[] {\n if (isStringRegistration(reg)) {\n return [{ type: \"string\", format: reg.format }];\n }\n\n if (isStringsRegistration(reg)) {\n return reg.formats.map((f) => ({ type: \"string\", format: f }));\n }\n\n return [];\n}\n\n// ============================================================================\n// Registry Class\n// ============================================================================\n\n/**\n * Global registry for mapping Zod schemas to OpenAPI schema representations\n */\nclass ZodSchemaRegistry {\n private readonly map = new Map<z.ZodTypeAny, ZodOpenApiRegistration>();\n\n /**\n * Register a Zod schema with its OpenAPI representation\n */\n register<F extends SupportedStringFormat>(\n schema: z.ZodTypeAny,\n registration: ZodOpenApiRegistrationString<F>,\n ): void;\n register<Fs extends readonly SupportedStringFormat[]>(\n schema: z.ZodTypeAny,\n registration: ZodOpenApiRegistrationStrings<Fs>,\n ): void;\n register(\n schema: z.ZodTypeAny,\n registration: ZodOpenApiRegistrationPrimitive,\n ): void;\n register(schema: z.ZodTypeAny, registration: ZodOpenApiRegistration): void {\n const newPairs = getTypeFormatPairs(registration);\n\n if (newPairs.length > 0) {\n for (const [existingSchema, existingRegistration] of this.map.entries()) {\n if (existingSchema === schema) continue;\n\n const existingPairs = getTypeFormatPairs(existingRegistration);\n for (const { type, format } of newPairs) {\n if (\n existingPairs.some((p) => p.type === type && p.format === format)\n ) {\n throw new Error(\n `duplicate Zod OpenAPI registration for (type, format)=('${type}', '${format as string}')`,\n );\n }\n }\n }\n }\n\n this.map.set(schema, registration);\n }\n\n /**\n * Get the OpenAPI schema for a given Zod schema\n */\n getOpenApiSchema(schema: z.ZodTypeAny): ZodOpenApiRegistration | undefined {\n return this.map.get(schema);\n }\n\n /**\n * Check if a Zod schema is registered\n */\n isRegistered(schema: z.ZodTypeAny): boolean {\n return this.map.has(schema);\n }\n\n /**\n * Clear all registered schemas\n */\n clear(): void {\n this.map.clear();\n }\n\n /**\n * Reverse-lookup helper: given a string format, return the registered schema's exported variable name\n */\n getSchemaExportedVariableNameForStringFormat(\n format: SupportedStringFormat,\n ): string | undefined {\n for (const registration of this.map.values()) {\n if (registration.type !== \"string\") continue;\n\n if (\n isStringRegistration(registration) &&\n registration.format === format\n ) {\n return registration.schemaExportedVariableName;\n }\n\n if (\n isStringsRegistration(registration) &&\n registration.formats.includes(format)\n ) {\n return registration.schemaExportedVariableName;\n }\n }\n return undefined;\n }\n}\n\n// ============================================================================\n// Global Registry Instance\n// ============================================================================\n\nexport const schemaRegistry = new ZodSchemaRegistry();\n\n// ============================================================================\n// Public API\n// ============================================================================\n\n/**\n * Helper function to register a Zod schema with its OpenAPI representation\n */\nexport function registerZodSchemaToOpenApiSchema(\n schema: z.ZodTypeAny,\n openApiSchema: ZodOpenApiRegistration,\n): void {\n schemaRegistry.register(schema, openApiSchema as any);\n}\n\n/**\n * Convenience helper to get an exported schema variable name for a given string format\n */\nexport function getSchemaExportedVariableNameForStringFormat(\n format: SupportedStringFormat,\n): string | undefined {\n return schemaRegistry.getSchemaExportedVariableNameForStringFormat(format);\n}\n\n/**\n * Clear all registered schemas in the global registry\n */\nexport function clearZodSchemaToOpenApiSchemaRegistry(): void {\n schemaRegistry.clear();\n}\n","import {\n getSchemaExportedVariableNameForStringFormat,\n SUPPORTED_STRING_FORMATS,\n} from \"../registry\";\n\n/**\n * Convert an OpenAPI v3 string schema to a Zod schema string\n */\nexport function convertOpenAPIStringToZod(schema: {\n type: \"string\";\n format?: typeof SUPPORTED_STRING_FORMATS;\n minLength?: number;\n maxLength?: number;\n pattern?: string;\n enum?: string[];\n}): string {\n // Handle enum values\n if (schema.enum) {\n return `z.enum([${schema.enum.map((value) => `'${value}'`).join(\", \")}])`;\n }\n\n // Check for custom registered format schemas\n if (schema.format && SUPPORTED_STRING_FORMATS.includes(schema.format)) {\n const customSchemaName = getSchemaExportedVariableNameForStringFormat(\n schema.format,\n );\n\n // Use custom schema if registered (ignores other constraints)\n if (customSchemaName) {\n return customSchemaName;\n }\n }\n\n // Build string schema with format modifiers\n let zodSchema = \"z.string()\";\n\n if (schema.format) {\n zodSchema += getFormatModifier(schema.format);\n }\n\n // Apply length constraints\n if (typeof schema.minLength === \"number\") {\n zodSchema += `.min(${schema.minLength})`;\n }\n\n if (typeof schema.maxLength === \"number\") {\n zodSchema += `.max(${schema.maxLength})`;\n }\n\n // Apply pattern constraint\n if (typeof schema.pattern === \"string\") {\n zodSchema += `.regex(/${schema.pattern}/)`;\n }\n\n return zodSchema;\n}\n\n/**\n * Get the Zod modifier for built-in string formats\n */\nfunction getFormatModifier(format: string): string {\n switch (format) {\n case \"email\":\n return \".email()\";\n case \"url\":\n case \"uri\":\n return \".url()\";\n case \"uuid\":\n return \".uuid()\";\n case \"color-hex\":\n return \".regex(/^[a-fA-F0-9]{6}$/)\";\n default:\n return \"\";\n }\n}\n","import type { AnySchema } from \"./types\";\n\nexport function convertOpenAPIArrayToZod(\n schema: {\n type: \"array\";\n items?: any;\n minItems?: number;\n maxItems?: number;\n },\n convertSchema: (schema: AnySchema) => string,\n): string {\n const item = schema.items;\n\n let itemZodString = \"z.unknown()\";\n if (item && typeof item === \"object\") {\n itemZodString = convertSchema(item);\n }\n\n let result = `z.array(${itemZodString})`;\n\n if (typeof schema.minItems === \"number\") {\n result += `.min(${schema.minItems})`;\n }\n if (typeof schema.maxItems === \"number\") {\n result += `.max(${schema.maxItems})`;\n }\n\n return result;\n}\n","import { AnySchema, OpenAPIObjectSchema } from \"./types\";\n\nconst validIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\nfunction quotePropertyName(name: string): string {\n return validIdentifierRegex.test(name) ? name : `'${name}'`;\n}\n\nexport function convertOpenAPIObjectToZod(\n schema: OpenAPIObjectSchema,\n convertSchema: (schema: AnySchema) => string,\n): string {\n const properties = schema.properties || {};\n const propertyNames = Object.keys(properties);\n\n if (propertyNames.length === 0) {\n if (schema.additionalProperties === false) {\n return \"z.object({}).strict()\";\n }\n return \"z.record(z.string(), z.unknown())\";\n }\n\n const requiredSet = new Set(schema.required || []);\n\n const entries: string[] = [];\n for (const [propName, propSchema] of Object.entries(properties)) {\n let zodProp = \"z.unknown()\";\n\n if (propSchema && typeof propSchema === \"object\") {\n zodProp = convertSchema(propSchema);\n }\n\n if (!requiredSet.has(propName)) {\n zodProp += \".optional()\";\n }\n\n entries.push(`${quotePropertyName(propName)}: ${zodProp}`);\n }\n\n let result = `z.object({ ${entries.join(\", \")} })`;\n\n if (schema.additionalProperties === false) {\n result += \".strict()\";\n }\n\n return result;\n}\n","import type { AnySchema } from \"./types\";\n\nexport function convertOpenAPIUnionToZod(\n schema: { oneOf: AnySchema[] },\n convertSchema: (schema: AnySchema) => string,\n): string {\n const items = schema.oneOf.map((item) => convertSchema(item));\n return `z.union([${items.join(\", \")}])`;\n}\n\n","import type { AnySchema } from \"./types\";\n\nexport function convertOpenAPIIntersectionToZod(\n schema: { allOf: AnySchema[] },\n convertSchema: (schema: AnySchema) => string,\n): string {\n const items = schema.allOf.map((item) => convertSchema(item));\n\n if (schema.allOf.length === 0) return \"z.unknown()\";\n if (schema.allOf.length === 1) return convertSchema(schema.allOf[0]!);\n\n return `z.intersection(${items.join(\", \")})`;\n}\n\n","import { convertOpenAPIBooleanToZod } from \"./types/boolean\";\nimport { convertOpenAPINumberToZod } from \"./types/number\";\nimport { convertOpenAPIStringToZod } from \"./types/string\";\nimport { convertOpenAPIArrayToZod } from \"./types/array\";\nimport { convertOpenAPIObjectToZod } from \"./types/object\";\nimport { convertOpenAPIUnionToZod } from \"./types/union\";\nimport { convertOpenAPIIntersectionToZod } from \"./types/intersection\";\nimport type { AnySchema } from \"./types/types\";\n\nexport function convertSchemaToZodString(schema: AnySchema): string {\n if (!schema || typeof schema !== \"object\") return \"z.unknown()\";\n\n if (schema[\"$ref\"] && typeof schema[\"$ref\"] === \"string\") {\n const match = (schema[\"$ref\"] as string).match(\n /#\\/components\\/schemas\\/(.+)/,\n );\n let result = \"z.unknown()\";\n if (match && match[1]) {\n result = `${match[1]}Schema`;\n }\n if (schema[\"nullable\"] === true) {\n result = `z.union([${result}, z.null()])`;\n }\n return result;\n }\n let result: string = \"z.unknown()\";\n\n if (\"oneOf\" in schema && Array.isArray(schema[\"oneOf\"])) {\n result = convertOpenAPIUnionToZod(\n schema as { oneOf: AnySchema[] },\n convertSchemaToZodString,\n );\n } else if (\"allOf\" in schema && Array.isArray(schema[\"allOf\"])) {\n result = convertOpenAPIIntersectionToZod(\n schema as { allOf: AnySchema[] },\n convertSchemaToZodString,\n );\n } else {\n switch (schema[\"type\"]) {\n case \"string\":\n result = convertOpenAPIStringToZod({\n enum: schema[\"enum\"],\n format: schema[\"format\"],\n maxLength: schema[\"maxLength\"],\n minLength: schema[\"minLength\"],\n pattern: schema[\"pattern\"],\n type: \"string\",\n });\n break;\n case \"number\":\n result = convertOpenAPINumberToZod({\n maximum: schema[\"maximum\"],\n minimum: schema[\"minimum\"],\n type: \"number\",\n });\n break;\n case \"integer\":\n result = convertOpenAPINumberToZod({\n maximum: schema[\"maximum\"],\n minimum: schema[\"minimum\"],\n type: \"integer\",\n });\n break;\n case \"boolean\":\n result = convertOpenAPIBooleanToZod({ type: \"boolean\" });\n break;\n case \"array\":\n result = convertOpenAPIArrayToZod(\n {\n items: schema[\"items\"],\n maxItems: schema[\"maxItems\"],\n minItems: schema[\"minItems\"],\n type: \"array\",\n },\n convertSchemaToZodString,\n );\n break;\n case \"object\":\n result = convertOpenAPIObjectToZod(\n {\n additionalProperties: schema[\"additionalProperties\"],\n properties: schema[\"properties\"],\n required: schema[\"required\"],\n type: \"object\",\n },\n convertSchemaToZodString,\n );\n break;\n default:\n if (schema[\"properties\"]) {\n result = convertOpenAPIObjectToZod(\n {\n additionalProperties: schema[\"additionalProperties\"],\n properties: schema[\"properties\"],\n required: schema[\"required\"],\n type: \"object\",\n },\n convertSchemaToZodString,\n );\n } else {\n result = \"z.unknown()\";\n }\n break;\n }\n }\n\n if (schema[\"nullable\"] === true) {\n result = `z.union([${result}, z.null()])`;\n }\n\n return result;\n}\n","import type { AnySchema } from \"./types/types\";\n\nexport type HttpMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\" | \"HEAD\" | \"OPTIONS\";\n\nexport interface RouteParameter {\n name: string;\n in: \"path\" | \"query\" | \"header\" | \"cookie\";\n required: boolean;\n schema: AnySchema;\n}\n\nexport interface RouteInfo {\n path: string;\n method: HttpMethod;\n parameters: RouteParameter[];\n requestBody?: AnySchema;\n responses: Record<string, AnySchema>;\n}\n\nexport interface RouteSchemaNames {\n paramsSchemaName?: string;\n querySchemaName?: string;\n headersSchemaName?: string;\n bodySchemaName?: string;\n responseSchemaName?: string;\n}\n\nfunction toUpperCaseMethod(method: string): HttpMethod {\n const upper = method.toUpperCase();\n if (\n upper === \"GET\" ||\n upper === \"POST\" ||\n upper === \"PUT\" ||\n upper === \"PATCH\" ||\n upper === \"DELETE\" ||\n upper === \"HEAD\" ||\n upper === \"OPTIONS\"\n ) {\n return upper as HttpMethod;\n }\n return \"GET\";\n}\n\nfunction toPascalCase(str: string): string {\n return str\n .replace(/[^a-zA-Z0-9]/g, \" \")\n .split(\" \")\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())\n .join(\"\");\n}\n\nfunction generateRouteSchemaName(\n path: string,\n method: HttpMethod,\n suffix: string,\n): string {\n const pathParts = path\n .split(\"/\")\n .filter((p) => p)\n .map((p) => {\n if (p.startsWith(\"{\") && p.endsWith(\"}\")) {\n return p.slice(1, -1);\n }\n return p;\n })\n .map(toPascalCase);\n const methodPrefix = method.charAt(0) + method.slice(1).toLowerCase();\n const parts = [methodPrefix, ...pathParts, suffix];\n return parts.join(\"\");\n}\n\nexport function parseOpenApiPaths(\n openapi: Record<string, unknown>,\n): RouteInfo[] {\n const paths = (openapi as AnySchema)[\"paths\"] as\n | Record<string, AnySchema>\n | undefined;\n if (!paths) {\n return [];\n }\n\n const routes: RouteInfo[] = [];\n\n for (const [path, pathItem] of Object.entries(paths)) {\n if (!pathItem || typeof pathItem !== \"object\") continue;\n\n const methods = [\n \"get\",\n \"post\",\n \"put\",\n \"patch\",\n \"delete\",\n \"head\",\n \"options\",\n ] as const;\n\n for (const method of methods) {\n const operation = pathItem[method] as AnySchema | undefined;\n if (!operation) continue;\n\n const parameters: RouteParameter[] = [];\n const responses: Record<string, AnySchema> = {};\n\n if (Array.isArray(pathItem[\"parameters\"])) {\n for (const param of pathItem[\"parameters\"]) {\n if (param && typeof param === \"object\") {\n parameters.push({\n name: String(param[\"name\"] || \"\"),\n in: param[\"in\"] || \"query\",\n required: Boolean(param[\"required\"]),\n schema: param[\"schema\"] || {},\n });\n }\n }\n }\n\n if (Array.isArray(operation[\"parameters\"])) {\n for (const param of operation[\"parameters\"]) {\n if (param && typeof param === \"object\") {\n parameters.push({\n name: String(param[\"name\"] || \"\"),\n in: param[\"in\"] || \"query\",\n required: Boolean(param[\"required\"]),\n schema: param[\"schema\"] || {},\n });\n }\n }\n }\n\n let requestBody: AnySchema | undefined;\n if (operation[\"requestBody\"]) {\n const rb = operation[\"requestBody\"];\n if (rb && typeof rb === \"object\") {\n const content = rb[\"content\"];\n if (content && typeof content === \"object\") {\n const jsonContent = content[\"application/json\"];\n if (jsonContent && typeof jsonContent === \"object\") {\n requestBody = jsonContent[\"schema\"] || {};\n }\n }\n }\n }\n\n if (operation[\"responses\"] && typeof operation[\"responses\"] === \"object\") {\n for (const [statusCode, response] of Object.entries(\n operation[\"responses\"],\n )) {\n if (response && typeof response === \"object\") {\n const responseSchema = response as AnySchema;\n const content = responseSchema[\"content\"];\n if (content && typeof content === \"object\") {\n const jsonContent = content[\"application/json\"];\n if (jsonContent && typeof jsonContent === \"object\") {\n const schema = jsonContent[\"schema\"];\n if (schema) {\n responses[statusCode] = schema;\n }\n }\n }\n }\n }\n }\n\n routes.push({\n path,\n method: toUpperCaseMethod(method),\n parameters,\n requestBody,\n responses,\n });\n }\n }\n\n return routes;\n}\n\nexport function generateRouteSchemaNames(\n route: RouteInfo,\n): RouteSchemaNames {\n const pathParams = route.parameters.filter((p) => p.in === \"path\");\n const queryParams = route.parameters.filter((p) => p.in === \"query\");\n const headerParams = route.parameters.filter((p) => p.in === \"header\");\n const successStatuses = Object.keys(route.responses).filter((s) =>\n s.startsWith(\"2\"),\n );\n\n const result: RouteSchemaNames = {\n responseSchemaName: successStatuses.length > 0\n ? generateRouteSchemaName(\n route.path,\n route.method,\n \"Response\",\n )\n : undefined,\n };\n\n if (pathParams.length > 0) {\n result.paramsSchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n \"Params\",\n );\n }\n\n if (queryParams.length > 0) {\n result.querySchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n \"Query\",\n );\n }\n\n if (headerParams.length > 0) {\n result.headersSchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n \"Headers\",\n );\n }\n\n if (route.requestBody) {\n result.bodySchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n \"Body\",\n );\n }\n\n return result;\n}\n\n","import { topologicalSortSchemas } from \"./dependencies\";\nimport {\n createSchemaRegistry,\n findCommonSchemas,\n getSchemaFingerprint,\n preRegisterSchema,\n registerSchema,\n type SchemaRegistry,\n} from \"./schema-dedup\";\nimport { convertSchemaToZodString } from \"./to-zod\";\nimport type { AnySchema } from \"./types/types\";\nimport {\n parseOpenApiPaths,\n generateRouteSchemaNames,\n type RouteInfo,\n} from \"./routes\";\n\nconst validIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\nfunction quotePropertyName(name: string): string {\n return validIdentifierRegex.test(name) ? name : `'${name}'`;\n}\n\nfunction generateRouteSchemaName(\n path: string,\n method: string,\n suffix: string,\n): string {\n const pathParts = path\n .split(\"/\")\n .filter((p) => p)\n .map((p) => {\n if (p.startsWith(\"{\") && p.endsWith(\"}\")) {\n return p.slice(1, -1);\n }\n return p;\n })\n .map((word) => {\n // Convert hyphenated words to PascalCase (e.g., \"timer-drafts\" -> \"TimerDrafts\")\n return word\n .split(/[-_]/)\n .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1).toLowerCase())\n .join(\"\");\n });\n const methodPrefix = method.charAt(0) + method.slice(1).toLowerCase();\n const parts = [methodPrefix, ...pathParts, suffix];\n return parts.join(\"\");\n}\n\n/**\n * Result of route schema generation including declarations and name mappings.\n */\ninterface RouteSchemaResult {\n /** Schema declarations to be emitted */\n declarations: string[];\n /** Maps route-specific schema name to its canonical name (for deduplication) */\n schemaNameToCanonical: Map<string, string>;\n}\n\nfunction generateRouteSchemas(\n routes: RouteInfo[],\n convertSchema: (schema: AnySchema) => string,\n registry: SchemaRegistry,\n): RouteSchemaResult {\n const declarations: string[] = [];\n const schemaNameToCanonical = new Map<string, string>();\n const generatedNames = new Set<string>();\n\n for (const route of routes) {\n const names = generateRouteSchemaNames(route);\n const pathParams = route.parameters.filter((p) => p.in === \"path\");\n const queryParams = route.parameters.filter((p) => p.in === \"query\");\n const headerParams = route.parameters.filter((p) => p.in === \"header\");\n\n // Generate params schema with deduplication\n if (names.paramsSchemaName && pathParams.length > 0) {\n const paramsSchema: AnySchema = {\n type: \"object\",\n properties: Object.fromEntries(\n pathParams.map((p) => [p.name, p.schema]),\n ),\n required: pathParams.filter((p) => p.required).map((p) => p.name),\n };\n\n const { isNew, canonicalName } = registerSchema(\n registry,\n names.paramsSchemaName,\n paramsSchema,\n );\n schemaNameToCanonical.set(names.paramsSchemaName, canonicalName);\n\n if (isNew && !generatedNames.has(names.paramsSchemaName)) {\n generatedNames.add(names.paramsSchemaName);\n const properties: string[] = [];\n for (const param of pathParams) {\n const zodExpr = convertSchema(param.schema);\n properties.push(`${quotePropertyName(param.name)}: ${zodExpr}`);\n }\n declarations.push(\n `export const ${names.paramsSchemaName} = z.object({ ${properties.join(\", \")} });`,\n );\n } else if (!isNew && names.paramsSchemaName !== canonicalName) {\n if (!generatedNames.has(names.paramsSchemaName)) {\n generatedNames.add(names.paramsSchemaName);\n declarations.push(\n `export const ${names.paramsSchemaName} = ${canonicalName};`,\n );\n }\n }\n }\n\n // Generate query schema with deduplication\n if (names.querySchemaName && queryParams.length > 0) {\n const querySchema: AnySchema = {\n type: \"object\",\n properties: Object.fromEntries(\n queryParams.map((p) => [p.name, p.schema]),\n ),\n required: queryParams.filter((p) => p.required).map((p) => p.name),\n };\n\n const { isNew, canonicalName } = registerSchema(\n registry,\n names.querySchemaName,\n querySchema,\n );\n schemaNameToCanonical.set(names.querySchemaName, canonicalName);\n\n if (isNew && !generatedNames.has(names.querySchemaName)) {\n generatedNames.add(names.querySchemaName);\n const properties: string[] = [];\n for (const param of queryParams) {\n let zodExpr = convertSchema(param.schema);\n if (!param.required) {\n zodExpr += \".optional()\";\n }\n properties.push(`${quotePropertyName(param.name)}: ${zodExpr}`);\n }\n declarations.push(\n `export const ${names.querySchemaName} = z.object({ ${properties.join(\", \")} });`,\n );\n } else if (!isNew && names.querySchemaName !== canonicalName) {\n if (!generatedNames.has(names.querySchemaName)) {\n generatedNames.add(names.querySchemaName);\n declarations.push(\n `export const ${names.querySchemaName} = ${canonicalName};`,\n );\n }\n }\n }\n\n // Generate headers schema with deduplication\n if (names.headersSchemaName && headerParams.length > 0) {\n const headersSchema: AnySchema = {\n type: \"object\",\n properties: Object.fromEntries(\n headerParams.map((p) => [p.name, p.schema]),\n ),\n required: headerParams.filter((p) => p.required).map((p) => p.name),\n };\n\n const { isNew, canonicalName } = registerSchema(\n registry,\n names.headersSchemaName,\n headersSchema,\n );\n schemaNameToCanonical.set(names.headersSchemaName, canonicalName);\n\n if (isNew && !generatedNames.has(names.headersSchemaName)) {\n generatedNames.add(names.headersSchemaName);\n const properties: string[] = [];\n for (const param of headerParams) {\n let zodExpr = convertSchema(param.schema);\n if (!param.required) {\n zodExpr += \".optional()\";\n }\n properties.push(`${quotePropertyName(param.name)}: ${zodExpr}`);\n }\n declarations.push(\n `export const ${names.headersSchemaName} = z.object({ ${properties.join(\", \")} });`,\n );\n } else if (!isNew && names.headersSchemaName !== canonicalName) {\n if (!generatedNames.has(names.headersSchemaName)) {\n generatedNames.add(names.headersSchemaName);\n declarations.push(\n `export const ${names.headersSchemaName} = ${canonicalName};`,\n );\n }\n }\n }\n\n // Generate body schema with deduplication\n if (names.bodySchemaName && route.requestBody) {\n const { isNew, canonicalName } = registerSchema(\n registry,\n names.bodySchemaName,\n route.requestBody,\n );\n schemaNameToCanonical.set(names.bodySchemaName, canonicalName);\n\n if (isNew && !generatedNames.has(names.bodySchemaName)) {\n generatedNames.add(names.bodySchemaName);\n const zodExpr = convertSchema(route.requestBody);\n declarations.push(`export const ${names.bodySchemaName} = ${zodExpr};`);\n } else if (!isNew && names.bodySchemaName !== canonicalName) {\n if (!generatedNames.has(names.bodySchemaName)) {\n generatedNames.add(names.bodySchemaName);\n declarations.push(\n `export const ${names.bodySchemaName} = ${canonicalName};`,\n );\n }\n }\n }\n\n // Generate schemas for ALL status codes with deduplication\n for (const [statusCode, responseSchema] of Object.entries(\n route.responses,\n )) {\n if (!responseSchema) continue;\n\n const isSuccess = statusCode.startsWith(\"2\");\n const suffix = isSuccess\n ? `${statusCode}Response`\n : `${statusCode}ErrorResponse`;\n const responseSchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n suffix,\n );\n\n const { isNew, canonicalName } = registerSchema(\n registry,\n responseSchemaName,\n responseSchema,\n );\n schemaNameToCanonical.set(responseSchemaName, canonicalName);\n\n if (isNew && !generatedNames.has(responseSchemaName)) {\n generatedNames.add(responseSchemaName);\n const zodExpr = convertSchema(responseSchema);\n declarations.push(`export const ${responseSchemaName} = ${zodExpr};`);\n } else if (!isNew && responseSchemaName !== canonicalName) {\n if (!generatedNames.has(responseSchemaName)) {\n generatedNames.add(responseSchemaName);\n declarations.push(\n `export const ${responseSchemaName} = ${canonicalName};`,\n );\n }\n }\n }\n }\n\n return { declarations, schemaNameToCanonical };\n}\n\nfunction generateRequestResponseObjects(\n routes: RouteInfo[],\n schemaNameToCanonical: Map<string, string>,\n): string[] {\n const lines: string[] = [];\n const requestPaths: Record<string, Record<string, string[]>> = {};\n const responsePaths: Record<\n string,\n Record<string, Record<string, string>>\n > = {};\n\n /**\n * Resolves a schema name to its canonical name if it exists,\n * otherwise returns the original name.\n */\n const resolveSchemaName = (name: string): string => {\n return schemaNameToCanonical.get(name) ?? name;\n };\n\n for (const route of routes) {\n const names = generateRouteSchemaNames(route);\n const pathParams = route.parameters.filter((p) => p.in === \"path\");\n const queryParams = route.parameters.filter((p) => p.in === \"query\");\n const headerParams = route.parameters.filter((p) => p.in === \"header\");\n\n if (!requestPaths[route.path]) {\n requestPaths[route.path] = {};\n }\n const requestMethodObj = requestPaths[route.path]!;\n if (!requestMethodObj[route.method]) {\n requestMethodObj[route.method] = [];\n }\n\n const requestParts: string[] = [];\n if (names.paramsSchemaName && pathParams.length > 0) {\n requestParts.push(\n `params: ${resolveSchemaName(names.paramsSchemaName)}`,\n );\n }\n if (names.querySchemaName && queryParams.length > 0) {\n requestParts.push(`query: ${resolveSchemaName(names.querySchemaName)}`);\n }\n if (names.headersSchemaName && headerParams.length > 0) {\n requestParts.push(\n `headers: ${resolveSchemaName(names.headersSchemaName)}`,\n );\n }\n if (names.bodySchemaName && route.requestBody) {\n requestParts.push(`body: ${resolveSchemaName(names.bodySchemaName)}`);\n }\n\n if (requestParts.length > 0) {\n requestMethodObj[route.method] = requestParts;\n }\n\n // Store all status codes in nested structure\n if (!responsePaths[route.path]) {\n responsePaths[route.path] = {};\n }\n const responseMethodObj = responsePaths[route.path]!;\n if (!responseMethodObj[route.method]) {\n responseMethodObj[route.method] = {};\n }\n\n for (const [statusCode, responseSchema] of Object.entries(\n route.responses,\n )) {\n if (!responseSchema) continue;\n\n const isSuccess = statusCode.startsWith(\"2\");\n const suffix = isSuccess\n ? `${statusCode}Response`\n : `${statusCode}ErrorResponse`;\n const responseSchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n suffix,\n );\n // Use canonical name for the Response object\n responseMethodObj[route.method]![statusCode] =\n resolveSchemaName(responseSchemaName);\n }\n }\n\n lines.push(\"export const Request = {\");\n for (const [path, methods] of Object.entries(requestPaths)) {\n const methodEntries = Object.entries(methods).filter(\n ([, parts]) => parts.length > 0,\n );\n if (methodEntries.length > 0) {\n lines.push(` '${path}': {`);\n for (const [method, parts] of methodEntries) {\n lines.push(` ${method}: {`);\n for (const part of parts) {\n lines.push(` ${part},`);\n }\n lines.push(` },`);\n }\n lines.push(` },`);\n }\n }\n lines.push(\"} as const;\");\n lines.push(\"\");\n\n lines.push(\"export const Response = {\");\n for (const [path, methods] of Object.entries(responsePaths)) {\n const methodEntries = Object.entries(methods);\n if (methodEntries.length > 0) {\n lines.push(` '${path}': {`);\n for (const [method, statusCodes] of methodEntries) {\n lines.push(` ${method}: {`);\n for (const [statusCode, schemaName] of Object.entries(statusCodes)) {\n lines.push(` '${statusCode}': ${schemaName},`);\n }\n lines.push(` },`);\n }\n lines.push(` },`);\n }\n }\n lines.push(\"} as const;\");\n\n return lines;\n}\n\n/**\n * Collects all response schemas from routes for common schema detection.\n */\nfunction collectRouteSchemas(\n routes: RouteInfo[],\n): Array<{ name: string; schema: AnySchema }> {\n const collected: Array<{ name: string; schema: AnySchema }> = [];\n\n for (const route of routes) {\n for (const [statusCode, responseSchema] of Object.entries(\n route.responses,\n )) {\n if (!responseSchema) continue;\n\n const isSuccess = statusCode.startsWith(\"2\");\n const suffix = isSuccess\n ? `${statusCode}Response`\n : `${statusCode}ErrorResponse`;\n const responseSchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n suffix,\n );\n\n collected.push({ name: responseSchemaName, schema: responseSchema });\n }\n }\n\n return collected;\n}\n\nexport const openApiToZodTsCode = (\n openapi: Record<string, unknown>,\n customImportLines?: string[],\n options?: { includeRoutes?: boolean },\n): string => {\n const components = (openapi as AnySchema)[\"components\"] as\n | AnySchema\n | undefined;\n const schemas: Record<string, AnySchema> =\n (components?.[\"schemas\"] as Record<string, AnySchema>) ?? {};\n\n const lines: string[] = [];\n lines.push(\"/**\");\n lines.push(\" * This file was automatically generated from OpenAPI schema\");\n lines.push(\" * Do not manually edit this file\");\n lines.push(\" */\");\n lines.push(\"\");\n lines.push(\"import { z } from 'zod';\");\n lines.push(...(customImportLines ?? []));\n lines.push(\"\");\n\n // Create registry for schema deduplication\n const registry = createSchemaRegistry();\n\n const sortedSchemaNames = topologicalSortSchemas(schemas);\n\n for (const name of sortedSchemaNames) {\n const schema = schemas[name];\n if (schema) {\n const zodExpr = convertSchemaToZodString(schema);\n const schemaName = `${name}Schema`;\n const typeName = name;\n lines.push(`export const ${schemaName} = ${zodExpr};`);\n lines.push(`export type ${typeName} = z.infer<typeof ${schemaName}>;`);\n lines.push(\"\");\n\n // Register component schemas so they can be referenced by route schemas\n const fingerprint = getSchemaFingerprint(schema);\n preRegisterSchema(registry, schemaName, fingerprint);\n }\n }\n\n if (options?.includeRoutes) {\n const routes = parseOpenApiPaths(openapi);\n if (routes.length > 0) {\n // Find common schemas that appear multiple times (for error responses, etc.)\n const routeSchemaList = collectRouteSchemas(routes);\n const commonSchemas = findCommonSchemas(routeSchemaList, 2);\n\n // Generate common schemas first (e.g., UnauthorizedErrorSchema, NotFoundErrorSchema)\n if (commonSchemas.length > 0) {\n lines.push(\"// Common Error Schemas (deduplicated)\");\n for (const common of commonSchemas) {\n const zodExpr = convertSchemaToZodString(common.schema);\n lines.push(`export const ${common.name} = ${zodExpr};`);\n // Pre-register so route schemas reference this instead of duplicating\n preRegisterSchema(registry, common.name, common.fingerprint);\n }\n lines.push(\"\");\n }\n\n // Generate route schemas with deduplication\n const { declarations, schemaNameToCanonical } = generateRouteSchemas(\n routes,\n convertSchemaToZodString,\n registry,\n );\n\n if (declarations.length > 0) {\n lines.push(\"// Route Schemas\");\n lines.push(...declarations);\n lines.push(\"\");\n\n // Generate Request/Response objects using canonical names\n const requestResponseObjs = generateRequestResponseObjects(\n routes,\n schemaNameToCanonical,\n );\n lines.push(...requestResponseObjs);\n }\n }\n }\n\n return lines.join(\"\\n\");\n};\n"],"mappings":";AA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AAgB,OAAO,IAAI,MAAM,OAAO,GAAG;AAEtD,4BAAkB,UAAU,OAAO,MAAM,OAAO,WAAW;AAAA,QAC7D;AACA,cAAM,KAAK,EAAE;AAAA,MACf;AAGA,YAAM,EAAE,cAAc,sBAAsB,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEA,UAAI,aAAa,SAAS,GAAG;AAC3B,cAAM,KAAK,kBAAkB;AAC7B,cAAM,KAAK,GAAG,YAAY;AAC1B,cAAM,KAAK,EAAE;AAGb,cAAM,sBAAsB;AAAA,UAC1B;AAAA,UACA;AAAA,QACF;AACA,cAAM,KAAK,GAAG,mBAAmB;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;","names":["result","validIdentifierRegex","quotePropertyName","generateRouteSchemaName"]}
|
|
1
|
+
{"version":3,"sources":["../src/dependencies.ts","../src/schema-dedup.ts","../src/types/boolean.ts","../src/types/number.ts","../src/registry.ts","../src/types/string.ts","../src/types/array.ts","../src/types/object.ts","../src/types/union.ts","../src/types/intersection.ts","../src/to-zod.ts","../src/routes.ts","../src/interface-generator.ts","../src/to-typescript.ts"],"sourcesContent":["import type { AnySchema } from \"./types/types\";\n\n/**\n * Extracts all schema references ($ref) from an OpenAPI schema by recursively\n * traversing its structure.\n *\n * This function is used during the OpenAPI-to-Zod conversion process to identify\n * which schemas a given schema depends on. It traverses all OpenAPI schema\n * structures including objects, arrays, unions (oneOf), intersections (allOf),\n * conditionals (if/then/else), and discriminator mappings to find all $ref\n * references that point to other schemas in the components/schemas section.\n *\n * The extracted dependency names are used by `topologicalSortSchemas` to build\n * a dependency graph and determine the correct order for generating Zod schemas,\n * ensuring that referenced schemas are defined before they are used in the\n * generated TypeScript code.\n *\n * @param schema - The OpenAPI schema to extract dependencies from\n * @returns An array of schema names that this schema references (via $ref)\n */\nexport function extractSchemaDependencies(schema: AnySchema): string[] {\n const dependencies: Set<string> = new Set();\n const visited = new WeakSet();\n\n function traverse(obj: any): void {\n if (!obj || typeof obj !== \"object\") return;\n\n if (visited.has(obj)) return;\n visited.add(obj);\n\n if (obj[\"$ref\"] && typeof obj[\"$ref\"] === \"string\") {\n const match = (obj[\"$ref\"] as string).match(\n /#\\/components\\/schemas\\/(.+)/,\n );\n if (match && match[1]) {\n dependencies.add(decodeURIComponent(match[1]));\n }\n return;\n }\n\n if (Array.isArray(obj)) {\n obj.forEach(traverse);\n return;\n }\n\n if (obj.properties && typeof obj.properties === \"object\") {\n for (const propValue of Object.values(obj.properties)) {\n traverse(propValue);\n }\n }\n\n const schemaKeys = [\n \"items\",\n \"oneOf\",\n \"allOf\",\n \"anyOf\",\n \"not\",\n \"if\",\n \"then\",\n \"else\",\n \"prefixItems\",\n \"contains\",\n \"propertyNames\",\n \"dependentSchemas\",\n ];\n\n for (const key of schemaKeys) {\n if (obj[key]) {\n traverse(obj[key]);\n }\n }\n\n if (\n obj.additionalProperties &&\n typeof obj.additionalProperties === \"object\"\n ) {\n traverse(obj.additionalProperties);\n }\n\n if (obj.discriminator?.mapping) {\n Object.values(obj.discriminator.mapping).forEach(traverse);\n }\n }\n\n traverse(schema);\n return Array.from(dependencies);\n}\n\n/**\n * Sorts OpenAPI schemas topologically based on their dependencies to ensure\n * correct generation order.\n *\n * When converting OpenAPI schemas to Zod schemas and generating TypeScript code,\n * schemas must be defined before they are referenced. For example, if `UserSchema`\n * references `ProfileSchema` (via $ref), then `ProfileSchema` must be generated\n * before `UserSchema` to avoid \"undefined variable\" errors in the generated code.\n *\n * This function uses Kahn's algorithm for topological sorting to order schemas\n * such that all dependencies come before their dependents. It:\n * 1. Extracts dependencies for each schema using `extractSchemaDependencies`\n * 2. Builds a dependency graph and computes in-degrees\n * 3. Sorts schemas starting with those that have no dependencies (in-degree 0)\n * 4. Handles circular dependencies gracefully by appending any remaining schemas\n * that couldn't be sorted (though this indicates a problematic schema structure)\n *\n * This function is called by `openApiToZodTsCode` to determine the order in which\n * schemas should be converted and emitted in the generated TypeScript file.\n *\n * @param schemas - A record mapping schema names to their OpenAPI schema definitions\n * @returns An array of schema names sorted in topological order (dependencies before dependents)\n */\nexport function topologicalSortSchemas(\n schemas: Record<string, AnySchema>,\n): string[] {\n const schemaNames = Object.keys(schemas);\n const dependencies: Map<string, string[]> = new Map();\n const inDegree: Map<string, number> = new Map();\n const sorted: string[] = [];\n const queue: string[] = [];\n const dependents: Map<string, string[]> = new Map();\n\n for (const name of schemaNames) {\n dependencies.set(name, []);\n dependents.set(name, []);\n inDegree.set(name, 0);\n }\n\n for (const name of schemaNames) {\n const schemaValue = schemas[name];\n if (schemaValue) {\n const deps = extractSchemaDependencies(schemaValue);\n const validDeps = deps.filter((dep) => schemaNames.includes(dep));\n dependencies.set(name, validDeps);\n\n for (const dep of validDeps) {\n const currentDependents = dependents.get(dep) || [];\n currentDependents.push(name);\n dependents.set(dep, currentDependents);\n }\n }\n }\n\n for (const [name, deps] of dependencies.entries()) {\n inDegree.set(name, deps.length);\n }\n\n for (const [name, degree] of inDegree.entries()) {\n if (degree === 0) {\n queue.push(name);\n }\n }\n\n while (queue.length > 0) {\n const current = queue.shift()!;\n sorted.push(current);\n\n const currentDependents = dependents.get(current) || [];\n for (const dependent of currentDependents) {\n const newDegree = (inDegree.get(dependent) || 0) - 1;\n inDegree.set(dependent, newDegree);\n if (newDegree === 0) {\n queue.push(dependent);\n }\n }\n }\n\n if (sorted.length !== schemaNames.length) {\n for (const name of schemaNames) {\n if (!sorted.includes(name)) {\n sorted.push(name);\n }\n }\n }\n\n return sorted;\n}\n","import type { AnySchema } from \"./types/types\";\n\n/**\n * Schema deduplication utilities for optimizing generated TypeScript types.\n *\n * This module provides fingerprinting and registry functionality to detect\n * structurally identical schemas and generate them only once, reducing\n * memory usage in consuming TypeScript projects.\n */\n\n/**\n * Recursively sorts an object's keys to create a stable representation.\n * This ensures that {a: 1, b: 2} and {b: 2, a: 1} produce the same fingerprint.\n */\nfunction sortObjectDeep(obj: unknown): unknown {\n if (obj === null || typeof obj !== \"object\") return obj;\n if (Array.isArray(obj)) return obj.map(sortObjectDeep);\n\n const sorted: Record<string, unknown> = {};\n const keys = Object.keys(obj as Record<string, unknown>).sort();\n for (const key of keys) {\n sorted[key] = sortObjectDeep((obj as Record<string, unknown>)[key]);\n }\n return sorted;\n}\n\n/**\n * Generates a canonical fingerprint for an OpenAPI schema.\n * Identical schemas will produce identical fingerprints.\n */\nexport function getSchemaFingerprint(schema: AnySchema): string {\n return JSON.stringify(sortObjectDeep(schema));\n}\n\n/**\n * Registry for tracking unique schemas and their canonical names.\n */\nexport interface SchemaRegistry {\n /** Map from fingerprint to the first schema name that used it */\n fingerprintToName: Map<string, string>;\n /** Map from schema name to its fingerprint (for reverse lookup) */\n nameToFingerprint: Map<string, string>;\n}\n\n/**\n * Creates a new empty schema registry.\n */\nexport function createSchemaRegistry(): SchemaRegistry {\n return {\n fingerprintToName: new Map(),\n nameToFingerprint: new Map(),\n };\n}\n\n/**\n * Result of registering a schema.\n */\nexport interface RegisterSchemaResult {\n /** Whether this is a new unique schema */\n isNew: boolean;\n /** The canonical name for this schema (may be different from input name if duplicate) */\n canonicalName: string;\n}\n\n/**\n * Registers a schema in the registry. If an identical schema already exists,\n * returns the existing canonical name instead.\n */\nexport function registerSchema(\n registry: SchemaRegistry,\n name: string,\n schema: AnySchema,\n): RegisterSchemaResult {\n const fingerprint = getSchemaFingerprint(schema);\n\n const existing = registry.fingerprintToName.get(fingerprint);\n if (existing) {\n return { isNew: false, canonicalName: existing };\n }\n\n registry.fingerprintToName.set(fingerprint, name);\n registry.nameToFingerprint.set(name, fingerprint);\n return { isNew: true, canonicalName: name };\n}\n\n/**\n * Pre-registers a schema with a specific fingerprint.\n * Used for common schemas that should take priority.\n */\nexport function preRegisterSchema(\n registry: SchemaRegistry,\n name: string,\n fingerprint: string,\n): void {\n registry.fingerprintToName.set(fingerprint, name);\n registry.nameToFingerprint.set(name, fingerprint);\n}\n\n/**\n * Extracts the error code from an OpenAPI error schema.\n * Looks for patterns like: { error: { code: enum(['UNAUTHORIZED']) } }\n */\nexport function extractErrorCode(schema: AnySchema): string | null {\n const properties = schema?.[\"properties\"] as Record<string, AnySchema> | undefined;\n const errorObj = properties?.[\"error\"] as AnySchema | undefined;\n const errorProps = errorObj?.[\"properties\"] as Record<string, AnySchema> | undefined;\n const codeSchema = errorProps?.[\"code\"] as AnySchema | undefined;\n const codeEnum = codeSchema?.[\"enum\"] as string[] | undefined;\n\n if (Array.isArray(codeEnum) && codeEnum.length === 1) {\n return codeEnum[0]!;\n }\n return null;\n}\n\n/**\n * Converts an error code like UNAUTHORIZED or NOT_FOUND to PascalCase.\n * UNAUTHORIZED -> Unauthorized\n * NOT_FOUND -> NotFound\n */\nexport function errorCodeToPascalCase(code: string): string {\n return code\n .split(\"_\")\n .map((part) => part.charAt(0) + part.slice(1).toLowerCase())\n .join(\"\");\n}\n\n/**\n * Generates a common error schema name from an error code.\n * UNAUTHORIZED -> UnauthorizedErrorSchema\n */\nexport function generateCommonErrorSchemaName(errorCode: string): string {\n return `${errorCodeToPascalCase(errorCode)}ErrorSchema`;\n}\n\n/**\n * Represents a common schema that appears multiple times.\n */\nexport interface CommonSchema {\n /** The canonical name for this schema */\n name: string;\n /** The schema definition */\n schema: AnySchema;\n /** The fingerprint for deduplication */\n fingerprint: string;\n /** Number of times this schema appears */\n count: number;\n}\n\n/**\n * Scans schemas and identifies those that appear multiple times.\n * Returns common schemas sorted by count (most common first).\n */\nexport function findCommonSchemas(\n schemas: Array<{ name: string; schema: AnySchema }>,\n minCount: number = 2,\n): CommonSchema[] {\n const fingerprints = new Map<\n string,\n { schema: AnySchema; names: string[]; errorCode: string | null }\n >();\n\n // Count occurrences of each unique schema\n for (const { name, schema } of schemas) {\n const fingerprint = getSchemaFingerprint(schema);\n const existing = fingerprints.get(fingerprint);\n\n if (existing) {\n existing.names.push(name);\n } else {\n fingerprints.set(fingerprint, {\n schema,\n names: [name],\n errorCode: extractErrorCode(schema),\n });\n }\n }\n\n // Filter to schemas appearing minCount+ times\n const commonSchemas: CommonSchema[] = [];\n for (const [fingerprint, data] of fingerprints) {\n if (data.names.length >= minCount) {\n // Generate a semantic name if it's an error schema, otherwise use first occurrence\n const name = data.errorCode\n ? generateCommonErrorSchemaName(data.errorCode)\n : data.names[0]!;\n\n commonSchemas.push({\n name,\n schema: data.schema,\n fingerprint,\n count: data.names.length,\n });\n }\n }\n\n // Sort by count descending (most common first)\n return commonSchemas.sort((a, b) => b.count - a.count);\n}\n","/**\n * Convert an OpenAPI v3 boolean schema to a Zod schema string\n */\nexport function convertOpenAPIBooleanToZod(_: { type: \"boolean\" }): string {\n return \"z.boolean()\";\n}\n","/**\n * Convert an OpenAPI v3 number/integer schema to a Zod schema string\n */\nexport function convertOpenAPINumberToZod(schema: {\n type: \"number\" | \"integer\";\n minimum?: number;\n maximum?: number;\n}): string {\n let result = \"z.number()\";\n if (schema.type === \"integer\") {\n result += \".int()\";\n }\n if (typeof schema.minimum === \"number\") {\n result += `.min(${schema.minimum})`;\n }\n if (typeof schema.maximum === \"number\") {\n result += `.max(${schema.maximum})`;\n }\n return result;\n}\n","import { z } from \"zod\";\n\n// ============================================================================\n// Constants\n// ============================================================================\n\nconst SUPPORTED_STRING_FORMATS_MAP = {\n \"color-hex\": 1,\n date: 1,\n \"date-time\": 1,\n email: 1,\n \"iso-date\": 1,\n \"iso-date-time\": 1,\n objectid: 1,\n uri: 1,\n url: 1,\n uuid: 1,\n} as const;\n\nexport const SUPPORTED_STRING_FORMATS = Object.keys(\n SUPPORTED_STRING_FORMATS_MAP,\n) as unknown as keyof typeof SUPPORTED_STRING_FORMATS_MAP;\n\ntype SupportedStringFormat = typeof SUPPORTED_STRING_FORMATS;\n\n// ============================================================================\n// Types\n// ============================================================================\n\nexport type ZodOpenApiRegistrationString<\n F extends SupportedStringFormat = SupportedStringFormat,\n> = {\n /** The name of the schema variable, IMPORTANT: must be named the same as the variable name */\n schemaExportedVariableName: string;\n type: \"string\";\n description?: string;\n format: F;\n};\n\nexport type ZodOpenApiRegistrationStrings<\n Fs extends\n readonly SupportedStringFormat[] = readonly SupportedStringFormat[],\n> = {\n /** The name of the schema variable, IMPORTANT: must be named the same as the variable name */\n schemaExportedVariableName: string;\n type: \"string\";\n description?: string;\n formats: Fs;\n};\n\nexport type ZodOpenApiRegistrationPrimitive = {\n /** The name of the schema variable, IMPORTANT: must be named the same as the variable name */\n schemaExportedVariableName: string;\n description?: string;\n type: \"number\" | \"integer\" | \"boolean\";\n};\n\nexport type ZodOpenApiRegistration =\n | ZodOpenApiRegistrationString\n | ZodOpenApiRegistrationStrings\n | ZodOpenApiRegistrationPrimitive;\n\n// ============================================================================\n// Type Guards\n// ============================================================================\n\nfunction isStringRegistration(\n reg: ZodOpenApiRegistration,\n): reg is ZodOpenApiRegistrationString {\n return reg.type === \"string\" && \"format\" in reg;\n}\n\nfunction isStringsRegistration(\n reg: ZodOpenApiRegistration,\n): reg is ZodOpenApiRegistrationStrings {\n return reg.type === \"string\" && \"formats\" in reg;\n}\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\ntype TypeFormatPair = { type: string; format: string | undefined };\n\nfunction getTypeFormatPairs(reg: ZodOpenApiRegistration): TypeFormatPair[] {\n if (isStringRegistration(reg)) {\n return [{ type: \"string\", format: reg.format }];\n }\n\n if (isStringsRegistration(reg)) {\n return reg.formats.map((f) => ({ type: \"string\", format: f }));\n }\n\n return [];\n}\n\n// ============================================================================\n// Registry Class\n// ============================================================================\n\n/**\n * Global registry for mapping Zod schemas to OpenAPI schema representations\n */\nclass ZodSchemaRegistry {\n private readonly map = new Map<z.ZodTypeAny, ZodOpenApiRegistration>();\n\n /**\n * Register a Zod schema with its OpenAPI representation\n */\n register<F extends SupportedStringFormat>(\n schema: z.ZodTypeAny,\n registration: ZodOpenApiRegistrationString<F>,\n ): void;\n register<Fs extends readonly SupportedStringFormat[]>(\n schema: z.ZodTypeAny,\n registration: ZodOpenApiRegistrationStrings<Fs>,\n ): void;\n register(\n schema: z.ZodTypeAny,\n registration: ZodOpenApiRegistrationPrimitive,\n ): void;\n register(schema: z.ZodTypeAny, registration: ZodOpenApiRegistration): void {\n const newPairs = getTypeFormatPairs(registration);\n\n if (newPairs.length > 0) {\n for (const [existingSchema, existingRegistration] of this.map.entries()) {\n if (existingSchema === schema) continue;\n\n const existingPairs = getTypeFormatPairs(existingRegistration);\n for (const { type, format } of newPairs) {\n if (\n existingPairs.some((p) => p.type === type && p.format === format)\n ) {\n throw new Error(\n `duplicate Zod OpenAPI registration for (type, format)=('${type}', '${format as string}')`,\n );\n }\n }\n }\n }\n\n this.map.set(schema, registration);\n }\n\n /**\n * Get the OpenAPI schema for a given Zod schema\n */\n getOpenApiSchema(schema: z.ZodTypeAny): ZodOpenApiRegistration | undefined {\n return this.map.get(schema);\n }\n\n /**\n * Check if a Zod schema is registered\n */\n isRegistered(schema: z.ZodTypeAny): boolean {\n return this.map.has(schema);\n }\n\n /**\n * Clear all registered schemas\n */\n clear(): void {\n this.map.clear();\n }\n\n /**\n * Reverse-lookup helper: given a string format, return the registered schema's exported variable name\n */\n getSchemaExportedVariableNameForStringFormat(\n format: SupportedStringFormat,\n ): string | undefined {\n for (const registration of this.map.values()) {\n if (registration.type !== \"string\") continue;\n\n if (\n isStringRegistration(registration) &&\n registration.format === format\n ) {\n return registration.schemaExportedVariableName;\n }\n\n if (\n isStringsRegistration(registration) &&\n registration.formats.includes(format)\n ) {\n return registration.schemaExportedVariableName;\n }\n }\n return undefined;\n }\n}\n\n// ============================================================================\n// Global Registry Instance\n// ============================================================================\n\nexport const schemaRegistry = new ZodSchemaRegistry();\n\n// ============================================================================\n// Public API\n// ============================================================================\n\n/**\n * Helper function to register a Zod schema with its OpenAPI representation\n */\nexport function registerZodSchemaToOpenApiSchema(\n schema: z.ZodTypeAny,\n openApiSchema: ZodOpenApiRegistration,\n): void {\n schemaRegistry.register(schema, openApiSchema as any);\n}\n\n/**\n * Convenience helper to get an exported schema variable name for a given string format\n */\nexport function getSchemaExportedVariableNameForStringFormat(\n format: SupportedStringFormat,\n): string | undefined {\n return schemaRegistry.getSchemaExportedVariableNameForStringFormat(format);\n}\n\n/**\n * Clear all registered schemas in the global registry\n */\nexport function clearZodSchemaToOpenApiSchemaRegistry(): void {\n schemaRegistry.clear();\n}\n","import {\n getSchemaExportedVariableNameForStringFormat,\n SUPPORTED_STRING_FORMATS,\n} from \"../registry\";\n\n/**\n * Convert an OpenAPI v3 string schema to a Zod schema string\n */\nexport function convertOpenAPIStringToZod(schema: {\n type: \"string\";\n format?: typeof SUPPORTED_STRING_FORMATS;\n minLength?: number;\n maxLength?: number;\n pattern?: string;\n enum?: string[];\n}): string {\n // Handle enum values\n if (schema.enum) {\n return `z.enum([${schema.enum.map((value) => `'${value}'`).join(\", \")}])`;\n }\n\n // Check for custom registered format schemas\n if (schema.format && SUPPORTED_STRING_FORMATS.includes(schema.format)) {\n const customSchemaName = getSchemaExportedVariableNameForStringFormat(\n schema.format,\n );\n\n // Use custom schema if registered (ignores other constraints)\n if (customSchemaName) {\n return customSchemaName;\n }\n }\n\n // Build string schema with format modifiers\n let zodSchema = \"z.string()\";\n\n if (schema.format) {\n zodSchema += getFormatModifier(schema.format);\n }\n\n // Apply length constraints\n if (typeof schema.minLength === \"number\") {\n zodSchema += `.min(${schema.minLength})`;\n }\n\n if (typeof schema.maxLength === \"number\") {\n zodSchema += `.max(${schema.maxLength})`;\n }\n\n // Apply pattern constraint\n if (typeof schema.pattern === \"string\") {\n zodSchema += `.regex(/${schema.pattern}/)`;\n }\n\n return zodSchema;\n}\n\n/**\n * Get the Zod modifier for built-in string formats\n */\nfunction getFormatModifier(format: string): string {\n switch (format) {\n case \"email\":\n return \".email()\";\n case \"url\":\n case \"uri\":\n return \".url()\";\n case \"uuid\":\n return \".uuid()\";\n case \"color-hex\":\n return \".regex(/^[a-fA-F0-9]{6}$/)\";\n default:\n return \"\";\n }\n}\n","import type { AnySchema } from \"./types\";\n\nexport function convertOpenAPIArrayToZod(\n schema: {\n type: \"array\";\n items?: any;\n minItems?: number;\n maxItems?: number;\n },\n convertSchema: (schema: AnySchema) => string,\n): string {\n const item = schema.items;\n\n let itemZodString = \"z.unknown()\";\n if (item && typeof item === \"object\") {\n itemZodString = convertSchema(item);\n }\n\n let result = `z.array(${itemZodString})`;\n\n if (typeof schema.minItems === \"number\") {\n result += `.min(${schema.minItems})`;\n }\n if (typeof schema.maxItems === \"number\") {\n result += `.max(${schema.maxItems})`;\n }\n\n return result;\n}\n","import { AnySchema, OpenAPIObjectSchema } from \"./types\";\n\nconst validIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\nfunction quotePropertyName(name: string): string {\n return validIdentifierRegex.test(name) ? name : `'${name}'`;\n}\n\nexport function convertOpenAPIObjectToZod(\n schema: OpenAPIObjectSchema,\n convertSchema: (schema: AnySchema) => string,\n): string {\n const properties = schema.properties || {};\n const propertyNames = Object.keys(properties);\n\n if (propertyNames.length === 0) {\n if (schema.additionalProperties === false) {\n return \"z.object({}).strict()\";\n }\n return \"z.record(z.string(), z.unknown())\";\n }\n\n const requiredSet = new Set(schema.required || []);\n\n const entries: string[] = [];\n for (const [propName, propSchema] of Object.entries(properties)) {\n let zodProp = \"z.unknown()\";\n\n if (propSchema && typeof propSchema === \"object\") {\n zodProp = convertSchema(propSchema);\n }\n\n if (!requiredSet.has(propName)) {\n zodProp += \".optional()\";\n }\n\n entries.push(`${quotePropertyName(propName)}: ${zodProp}`);\n }\n\n let result = `z.object({ ${entries.join(\", \")} })`;\n\n if (schema.additionalProperties === false) {\n result += \".strict()\";\n }\n\n return result;\n}\n","import type { AnySchema } from \"./types\";\n\nexport function convertOpenAPIUnionToZod(\n schema: { oneOf: AnySchema[] },\n convertSchema: (schema: AnySchema) => string,\n): string {\n const items = schema.oneOf.map((item) => convertSchema(item));\n return `z.union([${items.join(\", \")}])`;\n}\n\n","import type { AnySchema } from \"./types\";\n\nexport function convertOpenAPIIntersectionToZod(\n schema: { allOf: AnySchema[] },\n convertSchema: (schema: AnySchema) => string,\n): string {\n const items = schema.allOf.map((item) => convertSchema(item));\n\n if (schema.allOf.length === 0) return \"z.unknown()\";\n if (schema.allOf.length === 1) return convertSchema(schema.allOf[0]!);\n\n return `z.intersection(${items.join(\", \")})`;\n}\n\n","import { convertOpenAPIBooleanToZod } from \"./types/boolean\";\nimport { convertOpenAPINumberToZod } from \"./types/number\";\nimport { convertOpenAPIStringToZod } from \"./types/string\";\nimport { convertOpenAPIArrayToZod } from \"./types/array\";\nimport { convertOpenAPIObjectToZod } from \"./types/object\";\nimport { convertOpenAPIUnionToZod } from \"./types/union\";\nimport { convertOpenAPIIntersectionToZod } from \"./types/intersection\";\nimport type { AnySchema } from \"./types/types\";\n\nexport function convertSchemaToZodString(schema: AnySchema): string {\n if (!schema || typeof schema !== \"object\") return \"z.unknown()\";\n\n if (schema[\"$ref\"] && typeof schema[\"$ref\"] === \"string\") {\n const match = (schema[\"$ref\"] as string).match(\n /#\\/components\\/schemas\\/(.+)/,\n );\n let result = \"z.unknown()\";\n if (match && match[1]) {\n result = `${match[1]}Schema`;\n }\n if (schema[\"nullable\"] === true) {\n result = `z.union([${result}, z.null()])`;\n }\n return result;\n }\n let result: string = \"z.unknown()\";\n\n if (\"oneOf\" in schema && Array.isArray(schema[\"oneOf\"])) {\n result = convertOpenAPIUnionToZod(\n schema as { oneOf: AnySchema[] },\n convertSchemaToZodString,\n );\n } else if (\"allOf\" in schema && Array.isArray(schema[\"allOf\"])) {\n result = convertOpenAPIIntersectionToZod(\n schema as { allOf: AnySchema[] },\n convertSchemaToZodString,\n );\n } else {\n switch (schema[\"type\"]) {\n case \"string\":\n result = convertOpenAPIStringToZod({\n enum: schema[\"enum\"],\n format: schema[\"format\"],\n maxLength: schema[\"maxLength\"],\n minLength: schema[\"minLength\"],\n pattern: schema[\"pattern\"],\n type: \"string\",\n });\n break;\n case \"number\":\n result = convertOpenAPINumberToZod({\n maximum: schema[\"maximum\"],\n minimum: schema[\"minimum\"],\n type: \"number\",\n });\n break;\n case \"integer\":\n result = convertOpenAPINumberToZod({\n maximum: schema[\"maximum\"],\n minimum: schema[\"minimum\"],\n type: \"integer\",\n });\n break;\n case \"boolean\":\n result = convertOpenAPIBooleanToZod({ type: \"boolean\" });\n break;\n case \"array\":\n result = convertOpenAPIArrayToZod(\n {\n items: schema[\"items\"],\n maxItems: schema[\"maxItems\"],\n minItems: schema[\"minItems\"],\n type: \"array\",\n },\n convertSchemaToZodString,\n );\n break;\n case \"object\":\n result = convertOpenAPIObjectToZod(\n {\n additionalProperties: schema[\"additionalProperties\"],\n properties: schema[\"properties\"],\n required: schema[\"required\"],\n type: \"object\",\n },\n convertSchemaToZodString,\n );\n break;\n default:\n if (schema[\"properties\"]) {\n result = convertOpenAPIObjectToZod(\n {\n additionalProperties: schema[\"additionalProperties\"],\n properties: schema[\"properties\"],\n required: schema[\"required\"],\n type: \"object\",\n },\n convertSchemaToZodString,\n );\n } else {\n result = \"z.unknown()\";\n }\n break;\n }\n }\n\n if (schema[\"nullable\"] === true) {\n result = `z.union([${result}, z.null()])`;\n }\n\n return result;\n}\n","import type { AnySchema } from \"./types/types\";\n\nexport type HttpMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\" | \"HEAD\" | \"OPTIONS\";\n\nexport interface RouteParameter {\n name: string;\n in: \"path\" | \"query\" | \"header\" | \"cookie\";\n required: boolean;\n schema: AnySchema;\n}\n\nexport interface RouteInfo {\n path: string;\n method: HttpMethod;\n parameters: RouteParameter[];\n requestBody?: AnySchema;\n responses: Record<string, AnySchema>;\n}\n\nexport interface RouteSchemaNames {\n paramsSchemaName?: string;\n querySchemaName?: string;\n headersSchemaName?: string;\n bodySchemaName?: string;\n responseSchemaName?: string;\n}\n\nfunction toUpperCaseMethod(method: string): HttpMethod {\n const upper = method.toUpperCase();\n if (\n upper === \"GET\" ||\n upper === \"POST\" ||\n upper === \"PUT\" ||\n upper === \"PATCH\" ||\n upper === \"DELETE\" ||\n upper === \"HEAD\" ||\n upper === \"OPTIONS\"\n ) {\n return upper as HttpMethod;\n }\n return \"GET\";\n}\n\nfunction toPascalCase(str: string): string {\n return str\n .replace(/[^a-zA-Z0-9]/g, \" \")\n .split(\" \")\n .map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())\n .join(\"\");\n}\n\nfunction generateRouteSchemaName(\n path: string,\n method: HttpMethod,\n suffix: string,\n): string {\n const pathParts = path\n .split(\"/\")\n .filter((p) => p)\n .map((p) => {\n if (p.startsWith(\"{\") && p.endsWith(\"}\")) {\n return p.slice(1, -1);\n }\n return p;\n })\n .map(toPascalCase);\n const methodPrefix = method.charAt(0) + method.slice(1).toLowerCase();\n const parts = [methodPrefix, ...pathParts, suffix];\n return parts.join(\"\");\n}\n\nexport function parseOpenApiPaths(\n openapi: Record<string, unknown>,\n): RouteInfo[] {\n const paths = (openapi as AnySchema)[\"paths\"] as\n | Record<string, AnySchema>\n | undefined;\n if (!paths) {\n return [];\n }\n\n const routes: RouteInfo[] = [];\n\n for (const [path, pathItem] of Object.entries(paths)) {\n if (!pathItem || typeof pathItem !== \"object\") continue;\n\n const methods = [\n \"get\",\n \"post\",\n \"put\",\n \"patch\",\n \"delete\",\n \"head\",\n \"options\",\n ] as const;\n\n for (const method of methods) {\n const operation = pathItem[method] as AnySchema | undefined;\n if (!operation) continue;\n\n const parameters: RouteParameter[] = [];\n const responses: Record<string, AnySchema> = {};\n\n if (Array.isArray(pathItem[\"parameters\"])) {\n for (const param of pathItem[\"parameters\"]) {\n if (param && typeof param === \"object\") {\n parameters.push({\n name: String(param[\"name\"] || \"\"),\n in: param[\"in\"] || \"query\",\n required: Boolean(param[\"required\"]),\n schema: param[\"schema\"] || {},\n });\n }\n }\n }\n\n if (Array.isArray(operation[\"parameters\"])) {\n for (const param of operation[\"parameters\"]) {\n if (param && typeof param === \"object\") {\n parameters.push({\n name: String(param[\"name\"] || \"\"),\n in: param[\"in\"] || \"query\",\n required: Boolean(param[\"required\"]),\n schema: param[\"schema\"] || {},\n });\n }\n }\n }\n\n let requestBody: AnySchema | undefined;\n if (operation[\"requestBody\"]) {\n const rb = operation[\"requestBody\"];\n if (rb && typeof rb === \"object\") {\n const content = rb[\"content\"];\n if (content && typeof content === \"object\") {\n const jsonContent = content[\"application/json\"];\n if (jsonContent && typeof jsonContent === \"object\") {\n requestBody = jsonContent[\"schema\"] || {};\n }\n }\n }\n }\n\n if (operation[\"responses\"] && typeof operation[\"responses\"] === \"object\") {\n for (const [statusCode, response] of Object.entries(\n operation[\"responses\"],\n )) {\n if (response && typeof response === \"object\") {\n const responseSchema = response as AnySchema;\n const content = responseSchema[\"content\"];\n if (content && typeof content === \"object\") {\n const jsonContent = content[\"application/json\"];\n if (jsonContent && typeof jsonContent === \"object\") {\n const schema = jsonContent[\"schema\"];\n if (schema) {\n responses[statusCode] = schema;\n }\n }\n }\n }\n }\n }\n\n routes.push({\n path,\n method: toUpperCaseMethod(method),\n parameters,\n requestBody,\n responses,\n });\n }\n }\n\n return routes;\n}\n\nexport function generateRouteSchemaNames(\n route: RouteInfo,\n): RouteSchemaNames {\n const pathParams = route.parameters.filter((p) => p.in === \"path\");\n const queryParams = route.parameters.filter((p) => p.in === \"query\");\n const headerParams = route.parameters.filter((p) => p.in === \"header\");\n const successStatuses = Object.keys(route.responses).filter((s) =>\n s.startsWith(\"2\"),\n );\n\n const result: RouteSchemaNames = {\n responseSchemaName: successStatuses.length > 0\n ? generateRouteSchemaName(\n route.path,\n route.method,\n \"Response\",\n )\n : undefined,\n };\n\n if (pathParams.length > 0) {\n result.paramsSchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n \"Params\",\n );\n }\n\n if (queryParams.length > 0) {\n result.querySchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n \"Query\",\n );\n }\n\n if (headerParams.length > 0) {\n result.headersSchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n \"Headers\",\n );\n }\n\n if (route.requestBody) {\n result.bodySchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n \"Body\",\n );\n }\n\n return result;\n}\n\n","/**\n * Generates TypeScript interface/type strings from OpenAPI schemas.\n *\n * This produces concrete types that appear directly in .d.ts files,\n * rather than requiring z.infer<> resolution at the type level.\n */\n\nimport type { AnySchema } from \"./types/types\";\n\nconst validIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\nfunction quotePropertyName(name: string): string {\n return validIdentifierRegex.test(name) ? name : `'${name}'`;\n}\n\n/**\n * Converts an OpenAPI schema to a TypeScript type string.\n *\n * @example\n * schemaToTypeString({ type: 'string' }) // => 'string'\n * schemaToTypeString({ type: 'object', properties: { id: { type: 'string' } } }) // => '{ id?: string }'\n */\nexport function schemaToTypeString(schema: AnySchema): string {\n if (!schema || typeof schema !== \"object\") return \"unknown\";\n\n // Handle $ref\n if (schema[\"$ref\"] && typeof schema[\"$ref\"] === \"string\") {\n const match = (schema[\"$ref\"] as string).match(\n /#\\/components\\/schemas\\/(.+)/,\n );\n let result = \"unknown\";\n if (match && match[1]) {\n // Decode URI-encoded schema names (e.g., %20 -> space)\n result = decodeURIComponent(match[1]);\n }\n if (schema[\"nullable\"] === true) {\n result = `(${result} | null)`;\n }\n return result;\n }\n\n let result: string = \"unknown\";\n\n // Handle oneOf (union)\n if (\"oneOf\" in schema && Array.isArray(schema[\"oneOf\"])) {\n const unionMembers = (schema[\"oneOf\"] as AnySchema[]).map((s) =>\n schemaToTypeString(s),\n );\n result = unionMembers.length > 1 ? `(${unionMembers.join(\" | \")})` : unionMembers[0] ?? \"unknown\";\n }\n // Handle allOf (intersection)\n else if (\"allOf\" in schema && Array.isArray(schema[\"allOf\"])) {\n const intersectionMembers = (schema[\"allOf\"] as AnySchema[]).map((s) =>\n schemaToTypeString(s),\n );\n result = intersectionMembers.length > 1\n ? `(${intersectionMembers.join(\" & \")})`\n : intersectionMembers[0] ?? \"unknown\";\n }\n // Handle anyOf (union, similar to oneOf)\n else if (\"anyOf\" in schema && Array.isArray(schema[\"anyOf\"])) {\n const unionMembers = (schema[\"anyOf\"] as AnySchema[]).map((s) =>\n schemaToTypeString(s),\n );\n result = unionMembers.length > 1 ? `(${unionMembers.join(\" | \")})` : unionMembers[0] ?? \"unknown\";\n }\n // Handle type-based schemas\n else {\n switch (schema[\"type\"]) {\n case \"string\":\n if (schema[\"enum\"] && Array.isArray(schema[\"enum\"])) {\n // String enum\n result = (schema[\"enum\"] as string[])\n .map((v) => JSON.stringify(v))\n .join(\" | \");\n } else {\n result = \"string\";\n }\n break;\n case \"number\":\n case \"integer\":\n if (schema[\"enum\"] && Array.isArray(schema[\"enum\"])) {\n // Numeric enum\n result = (schema[\"enum\"] as number[]).map((v) => String(v)).join(\" | \");\n } else {\n result = \"number\";\n }\n break;\n case \"boolean\":\n result = \"boolean\";\n break;\n case \"null\":\n result = \"null\";\n break;\n case \"array\":\n if (schema[\"items\"]) {\n const itemType = schemaToTypeString(schema[\"items\"] as AnySchema);\n result = `Array<${itemType}>`;\n } else {\n result = \"unknown[]\";\n }\n break;\n case \"object\":\n result = objectSchemaToTypeString(schema);\n break;\n default:\n // Try to detect object from properties\n if (schema[\"properties\"]) {\n result = objectSchemaToTypeString(schema);\n } else if (schema[\"enum\"] && Array.isArray(schema[\"enum\"])) {\n // Untyped enum\n result = (schema[\"enum\"] as unknown[])\n .map((v) => JSON.stringify(v))\n .join(\" | \");\n } else {\n result = \"unknown\";\n }\n break;\n }\n }\n\n // Handle nullable\n if (schema[\"nullable\"] === true) {\n result = `(${result} | null)`;\n }\n\n return result;\n}\n\n/**\n * Converts an OpenAPI object schema to a TypeScript object type string.\n */\nfunction objectSchemaToTypeString(schema: AnySchema): string {\n const properties = schema[\"properties\"] as Record<string, AnySchema> | undefined;\n const required = new Set((schema[\"required\"] as string[]) ?? []);\n const additionalProperties = schema[\"additionalProperties\"];\n\n if (!properties && !additionalProperties) {\n return \"Record<string, unknown>\";\n }\n\n const propertyStrings: string[] = [];\n\n if (properties) {\n for (const [propName, propSchema] of Object.entries(properties)) {\n const isRequired = required.has(propName);\n const propType = schemaToTypeString(propSchema);\n const quotedName = quotePropertyName(propName);\n propertyStrings.push(\n `${quotedName}${isRequired ? \"\" : \"?\"}: ${propType}`,\n );\n }\n }\n\n // Handle additionalProperties\n if (additionalProperties === true) {\n propertyStrings.push(\"[key: string]: unknown\");\n } else if (\n typeof additionalProperties === \"object\" &&\n additionalProperties !== null\n ) {\n const additionalType = schemaToTypeString(additionalProperties as AnySchema);\n propertyStrings.push(`[key: string]: ${additionalType}`);\n }\n\n return `{ ${propertyStrings.join(\"; \")} }`;\n}\n\n/**\n * Generates a full TypeScript interface declaration.\n *\n * @example\n * generateInterface('User', { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] })\n * // => 'export interface User { id: string; }'\n */\nexport function generateInterface(name: string, schema: AnySchema): string {\n const properties = schema[\"properties\"] as Record<string, AnySchema> | undefined;\n const required = new Set((schema[\"required\"] as string[]) ?? []);\n\n // For non-object types, use type alias instead of interface\n if (schema[\"type\"] !== \"object\" && !properties) {\n return `export type ${name} = ${schemaToTypeString(schema)};`;\n }\n\n const lines: string[] = [];\n lines.push(`export interface ${name} {`);\n\n if (properties) {\n for (const [propName, propSchema] of Object.entries(properties)) {\n const isRequired = required.has(propName);\n const propType = schemaToTypeString(propSchema);\n const quotedName = quotePropertyName(propName);\n lines.push(` ${quotedName}${isRequired ? \"\" : \"?\"}: ${propType};`);\n }\n }\n\n // Handle additionalProperties\n const additionalProperties = schema[\"additionalProperties\"];\n if (additionalProperties === true) {\n lines.push(\" [key: string]: unknown;\");\n } else if (\n typeof additionalProperties === \"object\" &&\n additionalProperties !== null\n ) {\n const additionalType = schemaToTypeString(additionalProperties as AnySchema);\n lines.push(` [key: string]: ${additionalType};`);\n }\n\n lines.push(\"}\");\n return lines.join(\"\\n\");\n}\n","import { topologicalSortSchemas } from \"./dependencies\";\nimport {\n createSchemaRegistry,\n findCommonSchemas,\n getSchemaFingerprint,\n preRegisterSchema,\n registerSchema,\n type SchemaRegistry,\n} from \"./schema-dedup\";\nimport { convertSchemaToZodString } from \"./to-zod\";\nimport type { AnySchema } from \"./types/types\";\nimport {\n parseOpenApiPaths,\n generateRouteSchemaNames,\n type RouteInfo,\n} from \"./routes\";\nimport { generateInterface, schemaToTypeString } from \"./interface-generator\";\n\nconst validIdentifierRegex = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;\n\nfunction quotePropertyName(name: string): string {\n return validIdentifierRegex.test(name) ? name : `'${name}'`;\n}\n\nfunction generateRouteSchemaName(\n path: string,\n method: string,\n suffix: string,\n): string {\n const pathParts = path\n .split(\"/\")\n .filter((p) => p)\n .map((p) => {\n if (p.startsWith(\"{\") && p.endsWith(\"}\")) {\n return p.slice(1, -1);\n }\n return p;\n })\n .map((word) => {\n // Convert hyphenated words to PascalCase (e.g., \"timer-drafts\" -> \"TimerDrafts\")\n return word\n .split(/[-_]/)\n .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1).toLowerCase())\n .join(\"\");\n });\n const methodPrefix = method.charAt(0) + method.slice(1).toLowerCase();\n const parts = [methodPrefix, ...pathParts, suffix];\n return parts.join(\"\");\n}\n\n/**\n * Result of route schema generation including declarations and name mappings.\n */\ninterface RouteSchemaResult {\n /** Schema declarations to be emitted */\n declarations: string[];\n /** Maps route-specific schema name to its canonical name (for deduplication) */\n schemaNameToCanonical: Map<string, string>;\n}\n\nfunction generateRouteSchemas(\n routes: RouteInfo[],\n convertSchema: (schema: AnySchema) => string,\n registry: SchemaRegistry,\n): RouteSchemaResult {\n const declarations: string[] = [];\n const schemaNameToCanonical = new Map<string, string>();\n const generatedNames = new Set<string>();\n\n for (const route of routes) {\n const names = generateRouteSchemaNames(route);\n const pathParams = route.parameters.filter((p) => p.in === \"path\");\n const queryParams = route.parameters.filter((p) => p.in === \"query\");\n const headerParams = route.parameters.filter((p) => p.in === \"header\");\n\n // Generate params schema with deduplication\n if (names.paramsSchemaName && pathParams.length > 0) {\n const paramsSchema: AnySchema = {\n type: \"object\",\n properties: Object.fromEntries(\n pathParams.map((p) => [p.name, p.schema]),\n ),\n required: pathParams.filter((p) => p.required).map((p) => p.name),\n };\n\n const { isNew, canonicalName } = registerSchema(\n registry,\n names.paramsSchemaName,\n paramsSchema,\n );\n schemaNameToCanonical.set(names.paramsSchemaName, canonicalName);\n\n if (isNew && !generatedNames.has(names.paramsSchemaName)) {\n generatedNames.add(names.paramsSchemaName);\n const properties: string[] = [];\n for (const param of pathParams) {\n const zodExpr = convertSchema(param.schema);\n properties.push(`${quotePropertyName(param.name)}: ${zodExpr}`);\n }\n declarations.push(\n `export const ${names.paramsSchemaName} = z.object({ ${properties.join(\", \")} });`,\n );\n } else if (!isNew && names.paramsSchemaName !== canonicalName) {\n if (!generatedNames.has(names.paramsSchemaName)) {\n generatedNames.add(names.paramsSchemaName);\n declarations.push(\n `export const ${names.paramsSchemaName} = ${canonicalName};`,\n );\n }\n }\n }\n\n // Generate query schema with deduplication\n if (names.querySchemaName && queryParams.length > 0) {\n const querySchema: AnySchema = {\n type: \"object\",\n properties: Object.fromEntries(\n queryParams.map((p) => [p.name, p.schema]),\n ),\n required: queryParams.filter((p) => p.required).map((p) => p.name),\n };\n\n const { isNew, canonicalName } = registerSchema(\n registry,\n names.querySchemaName,\n querySchema,\n );\n schemaNameToCanonical.set(names.querySchemaName, canonicalName);\n\n if (isNew && !generatedNames.has(names.querySchemaName)) {\n generatedNames.add(names.querySchemaName);\n const properties: string[] = [];\n for (const param of queryParams) {\n let zodExpr = convertSchema(param.schema);\n if (!param.required) {\n zodExpr += \".optional()\";\n }\n properties.push(`${quotePropertyName(param.name)}: ${zodExpr}`);\n }\n declarations.push(\n `export const ${names.querySchemaName} = z.object({ ${properties.join(\", \")} });`,\n );\n } else if (!isNew && names.querySchemaName !== canonicalName) {\n if (!generatedNames.has(names.querySchemaName)) {\n generatedNames.add(names.querySchemaName);\n declarations.push(\n `export const ${names.querySchemaName} = ${canonicalName};`,\n );\n }\n }\n }\n\n // Generate headers schema with deduplication\n if (names.headersSchemaName && headerParams.length > 0) {\n const headersSchema: AnySchema = {\n type: \"object\",\n properties: Object.fromEntries(\n headerParams.map((p) => [p.name, p.schema]),\n ),\n required: headerParams.filter((p) => p.required).map((p) => p.name),\n };\n\n const { isNew, canonicalName } = registerSchema(\n registry,\n names.headersSchemaName,\n headersSchema,\n );\n schemaNameToCanonical.set(names.headersSchemaName, canonicalName);\n\n if (isNew && !generatedNames.has(names.headersSchemaName)) {\n generatedNames.add(names.headersSchemaName);\n const properties: string[] = [];\n for (const param of headerParams) {\n let zodExpr = convertSchema(param.schema);\n if (!param.required) {\n zodExpr += \".optional()\";\n }\n properties.push(`${quotePropertyName(param.name)}: ${zodExpr}`);\n }\n declarations.push(\n `export const ${names.headersSchemaName} = z.object({ ${properties.join(\", \")} });`,\n );\n } else if (!isNew && names.headersSchemaName !== canonicalName) {\n if (!generatedNames.has(names.headersSchemaName)) {\n generatedNames.add(names.headersSchemaName);\n declarations.push(\n `export const ${names.headersSchemaName} = ${canonicalName};`,\n );\n }\n }\n }\n\n // Generate body schema with deduplication\n if (names.bodySchemaName && route.requestBody) {\n const { isNew, canonicalName } = registerSchema(\n registry,\n names.bodySchemaName,\n route.requestBody,\n );\n schemaNameToCanonical.set(names.bodySchemaName, canonicalName);\n\n if (isNew && !generatedNames.has(names.bodySchemaName)) {\n generatedNames.add(names.bodySchemaName);\n const zodExpr = convertSchema(route.requestBody);\n declarations.push(`export const ${names.bodySchemaName} = ${zodExpr};`);\n } else if (!isNew && names.bodySchemaName !== canonicalName) {\n if (!generatedNames.has(names.bodySchemaName)) {\n generatedNames.add(names.bodySchemaName);\n declarations.push(\n `export const ${names.bodySchemaName} = ${canonicalName};`,\n );\n }\n }\n }\n\n // Generate schemas for ALL status codes with deduplication\n for (const [statusCode, responseSchema] of Object.entries(\n route.responses,\n )) {\n if (!responseSchema) continue;\n\n const isSuccess = statusCode.startsWith(\"2\");\n const suffix = isSuccess\n ? `${statusCode}Response`\n : `${statusCode}ErrorResponse`;\n const responseSchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n suffix,\n );\n\n const { isNew, canonicalName } = registerSchema(\n registry,\n responseSchemaName,\n responseSchema,\n );\n schemaNameToCanonical.set(responseSchemaName, canonicalName);\n\n if (isNew && !generatedNames.has(responseSchemaName)) {\n generatedNames.add(responseSchemaName);\n const zodExpr = convertSchema(responseSchema);\n declarations.push(`export const ${responseSchemaName} = ${zodExpr};`);\n } else if (!isNew && responseSchemaName !== canonicalName) {\n if (!generatedNames.has(responseSchemaName)) {\n generatedNames.add(responseSchemaName);\n declarations.push(\n `export const ${responseSchemaName} = ${canonicalName};`,\n );\n }\n }\n }\n }\n\n return { declarations, schemaNameToCanonical };\n}\n\nfunction generateRequestResponseObjects(\n routes: RouteInfo[],\n schemaNameToCanonical: Map<string, string>,\n): string[] {\n const lines: string[] = [];\n const requestPaths: Record<string, Record<string, string[]>> = {};\n const responsePaths: Record<\n string,\n Record<string, Record<string, string>>\n > = {};\n\n /**\n * Resolves a schema name to its canonical name if it exists,\n * otherwise returns the original name.\n */\n const resolveSchemaName = (name: string): string => {\n return schemaNameToCanonical.get(name) ?? name;\n };\n\n for (const route of routes) {\n const names = generateRouteSchemaNames(route);\n const pathParams = route.parameters.filter((p) => p.in === \"path\");\n const queryParams = route.parameters.filter((p) => p.in === \"query\");\n const headerParams = route.parameters.filter((p) => p.in === \"header\");\n\n if (!requestPaths[route.path]) {\n requestPaths[route.path] = {};\n }\n const requestMethodObj = requestPaths[route.path]!;\n if (!requestMethodObj[route.method]) {\n requestMethodObj[route.method] = [];\n }\n\n const requestParts: string[] = [];\n if (names.paramsSchemaName && pathParams.length > 0) {\n requestParts.push(\n `params: ${resolveSchemaName(names.paramsSchemaName)}`,\n );\n }\n if (names.querySchemaName && queryParams.length > 0) {\n requestParts.push(`query: ${resolveSchemaName(names.querySchemaName)}`);\n }\n if (names.headersSchemaName && headerParams.length > 0) {\n requestParts.push(\n `headers: ${resolveSchemaName(names.headersSchemaName)}`,\n );\n }\n if (names.bodySchemaName && route.requestBody) {\n requestParts.push(`body: ${resolveSchemaName(names.bodySchemaName)}`);\n }\n\n if (requestParts.length > 0) {\n requestMethodObj[route.method] = requestParts;\n }\n\n // Store all status codes in nested structure\n if (!responsePaths[route.path]) {\n responsePaths[route.path] = {};\n }\n const responseMethodObj = responsePaths[route.path]!;\n if (!responseMethodObj[route.method]) {\n responseMethodObj[route.method] = {};\n }\n\n for (const [statusCode, responseSchema] of Object.entries(\n route.responses,\n )) {\n if (!responseSchema) continue;\n\n const isSuccess = statusCode.startsWith(\"2\");\n const suffix = isSuccess\n ? `${statusCode}Response`\n : `${statusCode}ErrorResponse`;\n const responseSchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n suffix,\n );\n // Use canonical name for the Response object\n responseMethodObj[route.method]![statusCode] =\n resolveSchemaName(responseSchemaName);\n }\n }\n\n lines.push(\"export const Request = {\");\n for (const [path, methods] of Object.entries(requestPaths)) {\n const methodEntries = Object.entries(methods).filter(\n ([, parts]) => parts.length > 0,\n );\n if (methodEntries.length > 0) {\n lines.push(` '${path}': {`);\n for (const [method, parts] of methodEntries) {\n lines.push(` ${method}: {`);\n for (const part of parts) {\n lines.push(` ${part},`);\n }\n lines.push(` },`);\n }\n lines.push(` },`);\n }\n }\n lines.push(\"} as const;\");\n lines.push(\"\");\n\n lines.push(\"export const Response = {\");\n for (const [path, methods] of Object.entries(responsePaths)) {\n const methodEntries = Object.entries(methods);\n if (methodEntries.length > 0) {\n lines.push(` '${path}': {`);\n for (const [method, statusCodes] of methodEntries) {\n lines.push(` ${method}: {`);\n for (const [statusCode, schemaName] of Object.entries(statusCodes)) {\n lines.push(` '${statusCode}': ${schemaName},`);\n }\n lines.push(` },`);\n }\n lines.push(` },`);\n }\n }\n lines.push(\"} as const;\");\n\n return lines;\n}\n\n/**\n * Collects all response schemas from routes for common schema detection.\n */\nfunction collectRouteSchemas(\n routes: RouteInfo[],\n): Array<{ name: string; schema: AnySchema }> {\n const collected: Array<{ name: string; schema: AnySchema }> = [];\n\n for (const route of routes) {\n for (const [statusCode, responseSchema] of Object.entries(\n route.responses,\n )) {\n if (!responseSchema) continue;\n\n const isSuccess = statusCode.startsWith(\"2\");\n const suffix = isSuccess\n ? `${statusCode}Response`\n : `${statusCode}ErrorResponse`;\n const responseSchemaName = generateRouteSchemaName(\n route.path,\n route.method,\n suffix,\n );\n\n collected.push({ name: responseSchemaName, schema: responseSchema });\n }\n }\n\n return collected;\n}\n\nexport const openApiToZodTsCode = (\n openapi: Record<string, unknown>,\n customImportLines?: string[],\n options?: { includeRoutes?: boolean },\n): string => {\n const components = (openapi as AnySchema)[\"components\"] as\n | AnySchema\n | undefined;\n const schemas: Record<string, AnySchema> =\n (components?.[\"schemas\"] as Record<string, AnySchema>) ?? {};\n\n const lines: string[] = [];\n lines.push(\"/**\");\n lines.push(\" * This file was automatically generated from OpenAPI schema\");\n lines.push(\" * Do not manually edit this file\");\n lines.push(\" */\");\n lines.push(\"\");\n lines.push(\"import { z } from 'zod';\");\n lines.push(...(customImportLines ?? []));\n lines.push(\"\");\n\n // Type assertion helper for compile-time verification\n lines.push(\"// Type assertion helper - verifies interface matches schema at compile time\");\n lines.push(\"type _AssertEqual<T, U> = [T] extends [U] ? ([U] extends [T] ? true : never) : never;\");\n lines.push(\"\");\n\n // Create registry for schema deduplication\n const registry = createSchemaRegistry();\n\n const sortedSchemaNames = topologicalSortSchemas(schemas);\n\n // Collect all type assertions to emit after all schemas\n const typeAssertions: string[] = [];\n\n for (const name of sortedSchemaNames) {\n const schema = schemas[name];\n if (schema) {\n const zodExpr = convertSchemaToZodString(schema);\n const schemaName = `${name}Schema`;\n const typeName = name;\n\n // Generate interface (concrete type in .d.ts)\n lines.push(generateInterface(typeName, schema));\n\n // Generate schema with ZodType<T> annotation (simple type in .d.ts)\n lines.push(`export const ${schemaName}: z.ZodType<${typeName}> = ${zodExpr};`);\n lines.push(\"\");\n\n // Add type assertion to verify interface matches schema\n typeAssertions.push(`type _Assert${typeName} = _AssertEqual<${typeName}, z.infer<typeof ${schemaName}>>;`);\n\n // Register component schemas so they can be referenced by route schemas\n const fingerprint = getSchemaFingerprint(schema);\n preRegisterSchema(registry, schemaName, fingerprint);\n }\n }\n\n // Emit all type assertions\n if (typeAssertions.length > 0) {\n lines.push(\"// Compile-time type assertions - ensure interfaces match schemas\");\n lines.push(typeAssertions.join(\"\\n\"));\n lines.push(\"\");\n }\n\n if (options?.includeRoutes) {\n const routes = parseOpenApiPaths(openapi);\n if (routes.length > 0) {\n // Find common schemas that appear multiple times (for error responses, etc.)\n const routeSchemaList = collectRouteSchemas(routes);\n const commonSchemas = findCommonSchemas(routeSchemaList, 2);\n\n // Generate common schemas first (e.g., UnauthorizedErrorSchema, NotFoundErrorSchema)\n if (commonSchemas.length > 0) {\n lines.push(\"// Common Error Schemas (deduplicated)\");\n for (const common of commonSchemas) {\n const zodExpr = convertSchemaToZodString(common.schema);\n lines.push(`export const ${common.name} = ${zodExpr};`);\n // Pre-register so route schemas reference this instead of duplicating\n preRegisterSchema(registry, common.name, common.fingerprint);\n }\n lines.push(\"\");\n }\n\n // Generate route schemas with deduplication\n const { declarations, schemaNameToCanonical } = generateRouteSchemas(\n routes,\n convertSchemaToZodString,\n registry,\n );\n\n if (declarations.length > 0) {\n lines.push(\"// Route Schemas\");\n lines.push(...declarations);\n lines.push(\"\");\n\n // Generate Request/Response objects using canonical names\n const requestResponseObjs = generateRequestResponseObjects(\n routes,\n schemaNameToCanonical,\n );\n lines.push(...requestResponseObjs);\n }\n }\n }\n\n return lines.join(\"\\n\");\n};\n"],"mappings":";AAoBO,SAAS,0BAA0B,QAA6B;AACrE,QAAM,eAA4B,oBAAI,IAAI;AAC1C,QAAM,UAAU,oBAAI,QAAQ;AAE5B,WAAS,SAAS,KAAgB;AAChC,QAAI,CAAC,OAAO,OAAO,QAAQ,SAAU;AAErC,QAAI,QAAQ,IAAI,GAAG,EAAG;AACtB,YAAQ,IAAI,GAAG;AAEf,QAAI,IAAI,MAAM,KAAK,OAAO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Y,WAAW;AAAA,IACrD;AAAA,EACF;AAGA,MAAI,eAAe,SAAS,GAAG;AAC7B,UAAM,KAAK,mEAAmE;AAC9E,UAAM,KAAK,eAAe,KAAK,IAAI,CAAC;AACpC,UAAM,KAAK,EAAE;AAAA,EACf;AAEA,MAAI,SAAS,eAAe;AAC1B,UAAM,SAAS,kBAAkB,OAAO;AACxC,QAAI,OAAO,SAAS,GAAG;AAErB,YAAM,kBAAkB,oBAAoB,MAAM;AAClD,YAAM,gBAAgB,kBAAkB,iBAAiB,CAAC;AAG1D,UAAI,cAAc,SAAS,GAAG;AAC5B,cAAM,KAAK,wCAAwC;AACnD,mBAAW,UAAU,eAAe;AAClC,gBAAM,UAAU,yBAAyB,OAAO,MAAM;AACtD,gBAAM,KAAK,gBAAgB,OAAO,IAAI,MAAM,OAAO,GAAG;AAEtD,4BAAkB,UAAU,OAAO,MAAM,OAAO,WAAW;AAAA,QAC7D;AACA,cAAM,KAAK,EAAE;AAAA,MACf;AAGA,YAAM,EAAE,cAAc,sBAAsB,IAAI;AAAA,QAC9C;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEA,UAAI,aAAa,SAAS,GAAG;AAC3B,cAAM,KAAK,kBAAkB;AAC7B,cAAM,KAAK,GAAG,YAAY;AAC1B,cAAM,KAAK,EAAE;AAGb,cAAM,sBAAsB;AAAA,UAC1B;AAAA,UACA;AAAA,QACF;AACA,cAAM,KAAK,GAAG,mBAAmB;AAAA,MACnC;AAAA,IACF;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;","names":["result","validIdentifierRegex","quotePropertyName","result","validIdentifierRegex","quotePropertyName","generateRouteSchemaName"]}
|