next-openapi-gen 1.2.0 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/dist/cli.js +202 -41
- package/dist/index.js +202 -41
- package/dist/next/index.js +202 -41
- package/dist/react-router/index.js +202 -41
- package/dist/vite/index.js +202 -41
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -950,6 +950,17 @@ function mergeJSDocData(target, source) {
|
|
|
950
950
|
function cleanComment(commentValue) {
|
|
951
951
|
return commentValue.replace(/\*\s*/g, "").trim();
|
|
952
952
|
}
|
|
953
|
+
function extractSchemaIdFromComments(comments) {
|
|
954
|
+
if (!comments)
|
|
955
|
+
return null;
|
|
956
|
+
for (const comment of comments) {
|
|
957
|
+
const cleaned = cleanComment(comment.value);
|
|
958
|
+
const id = extractTokenValue(cleaned, "@id");
|
|
959
|
+
if (id)
|
|
960
|
+
return id;
|
|
961
|
+
}
|
|
962
|
+
return null;
|
|
963
|
+
}
|
|
953
964
|
function extractLineValue(commentValue, tag) {
|
|
954
965
|
return commentValue.match(new RegExp(`${escapeRegExp(tag)}\\s*(.*)`, "m"))?.[1]?.trim() || "";
|
|
955
966
|
}
|
|
@@ -3134,7 +3145,8 @@ var DrizzleZodProcessor = class _DrizzleZodProcessor {
|
|
|
3134
3145
|
if (firstArg && !t4.isSpreadElement(firstArg) && !t4.isArgumentPlaceholder(firstArg)) {
|
|
3135
3146
|
const metadata = _DrizzleZodProcessor.extractStaticObject(firstArg);
|
|
3136
3147
|
if (metadata) {
|
|
3137
|
-
|
|
3148
|
+
const { id: _id, ...rest } = metadata;
|
|
3149
|
+
Object.assign(result, rest);
|
|
3138
3150
|
}
|
|
3139
3151
|
}
|
|
3140
3152
|
break;
|
|
@@ -11418,8 +11430,11 @@ var ZodRuntimeExporter = class {
|
|
|
11418
11430
|
case "deprecated":
|
|
11419
11431
|
return schema.meta({ deprecated: true });
|
|
11420
11432
|
case "meta": {
|
|
11421
|
-
const
|
|
11422
|
-
|
|
11433
|
+
const rawMetadata = node.arguments[0] ? this.buildMetadataObject(node.arguments[0]) : null;
|
|
11434
|
+
if (!rawMetadata)
|
|
11435
|
+
return schema;
|
|
11436
|
+
const { id: _id, ...metadata } = rawMetadata;
|
|
11437
|
+
return Object.keys(metadata).length > 0 ? schema.meta(metadata) : schema;
|
|
11423
11438
|
}
|
|
11424
11439
|
case "default":
|
|
11425
11440
|
case "prefault":
|
|
@@ -11655,7 +11670,9 @@ var ZodSchemaConverter = class {
|
|
|
11655
11670
|
apiDir;
|
|
11656
11671
|
zodSchemas = {};
|
|
11657
11672
|
processingSchemas = /* @__PURE__ */ new Set();
|
|
11658
|
-
|
|
11673
|
+
/** Memoization guard for processFileForZodSchema. Keys: `${filePath}|${schemaName}`.
|
|
11674
|
+
* Prevents infinite recursion when re-export files reference schemas via z.infer<typeof X>. */
|
|
11675
|
+
processedFileSchemaPairs = /* @__PURE__ */ new Set();
|
|
11659
11676
|
typeToSchemaMapping = {};
|
|
11660
11677
|
drizzleZodImports = /* @__PURE__ */ new Set();
|
|
11661
11678
|
factoryCache = /* @__PURE__ */ new Map();
|
|
@@ -11869,6 +11886,11 @@ var ZodSchemaConverter = class {
|
|
|
11869
11886
|
* Process a file to find Zod schema definitions
|
|
11870
11887
|
*/
|
|
11871
11888
|
processFileForZodSchema(filePath, schemaName) {
|
|
11889
|
+
const visitKey = `${filePath}|${schemaName}|${this.currentContentType}`;
|
|
11890
|
+
if (this.processedFileSchemaPairs.has(visitKey)) {
|
|
11891
|
+
return;
|
|
11892
|
+
}
|
|
11893
|
+
this.processedFileSchemaPairs.add(visitKey);
|
|
11872
11894
|
try {
|
|
11873
11895
|
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
11874
11896
|
if (!content.includes(schemaName)) {
|
|
@@ -12182,7 +12204,9 @@ var ZodSchemaConverter = class {
|
|
|
12182
12204
|
const param = path25.node.typeAnnotation.typeParameters.params[0];
|
|
12183
12205
|
if (t10.isTSTypeQuery(param) && t10.isIdentifier(param.exprName)) {
|
|
12184
12206
|
const referencedSchemaName = param.exprName.name;
|
|
12185
|
-
this.
|
|
12207
|
+
if (!this.getStoredSchema(referencedSchemaName)) {
|
|
12208
|
+
this.processFileForZodSchema(filePath, referencedSchemaName);
|
|
12209
|
+
}
|
|
12186
12210
|
}
|
|
12187
12211
|
}
|
|
12188
12212
|
}
|
|
@@ -12200,6 +12224,8 @@ var ZodSchemaConverter = class {
|
|
|
12200
12224
|
try {
|
|
12201
12225
|
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
12202
12226
|
const ast = parseTypeScriptFile(content);
|
|
12227
|
+
this.currentFilePath = filePath;
|
|
12228
|
+
this.currentAST = ast;
|
|
12203
12229
|
resolvedTraverse(ast, {
|
|
12204
12230
|
ExportNamedDeclaration: (path25) => {
|
|
12205
12231
|
if (t10.isVariableDeclaration(path25.node.declaration)) {
|
|
@@ -12214,6 +12240,17 @@ var ZodSchemaConverter = class {
|
|
|
12214
12240
|
}
|
|
12215
12241
|
this.processingSchemas.delete(schemaName);
|
|
12216
12242
|
}
|
|
12243
|
+
} else if (t10.isIdentifier(declaration.id) && declaration.init) {
|
|
12244
|
+
const schemaName = declaration.id.name;
|
|
12245
|
+
const overrideId = this.extractMetaIdFromNode(declaration.init);
|
|
12246
|
+
if (overrideId && !this.getStoredSchema(schemaName) && !this.processingSchemas.has(schemaName)) {
|
|
12247
|
+
this.processingSchemas.add(schemaName);
|
|
12248
|
+
const schema = this.processZodNode(declaration.init);
|
|
12249
|
+
this.processingSchemas.delete(schemaName);
|
|
12250
|
+
if (schema) {
|
|
12251
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
12252
|
+
}
|
|
12253
|
+
}
|
|
12217
12254
|
}
|
|
12218
12255
|
});
|
|
12219
12256
|
}
|
|
@@ -12767,6 +12804,24 @@ var ZodSchemaConverter = class {
|
|
|
12767
12804
|
}
|
|
12768
12805
|
return void 0;
|
|
12769
12806
|
}
|
|
12807
|
+
extractMetaIdFromNode(node) {
|
|
12808
|
+
if (!t10.isCallExpression(node))
|
|
12809
|
+
return null;
|
|
12810
|
+
if (t10.isMemberExpression(node.callee) && t10.isIdentifier(node.callee.property)) {
|
|
12811
|
+
if (node.callee.property.name === "meta" && node.arguments.length > 0) {
|
|
12812
|
+
const metadata = this.extractStaticJsonValue(node.arguments[0]);
|
|
12813
|
+
if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
12814
|
+
const id = metadata.id;
|
|
12815
|
+
if (typeof id === "string" && id.length > 0)
|
|
12816
|
+
return id;
|
|
12817
|
+
}
|
|
12818
|
+
}
|
|
12819
|
+
if (t10.isCallExpression(node.callee.object)) {
|
|
12820
|
+
return this.extractMetaIdFromNode(node.callee.object);
|
|
12821
|
+
}
|
|
12822
|
+
}
|
|
12823
|
+
return null;
|
|
12824
|
+
}
|
|
12770
12825
|
shouldUseRuntimeExport(node) {
|
|
12771
12826
|
if (!t10.isCallExpression(node)) {
|
|
12772
12827
|
return false;
|
|
@@ -13007,7 +13062,8 @@ var ZodSchemaConverter = class {
|
|
|
13007
13062
|
if (node.arguments.length > 0) {
|
|
13008
13063
|
const metadata = this.extractStaticJsonValue(node.arguments[0]);
|
|
13009
13064
|
if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
13010
|
-
|
|
13065
|
+
const { id: _id, ...rest } = metadata;
|
|
13066
|
+
Object.assign(schema, rest);
|
|
13011
13067
|
}
|
|
13012
13068
|
}
|
|
13013
13069
|
break;
|
|
@@ -13293,6 +13349,7 @@ var ZodSchemaConverter = class {
|
|
|
13293
13349
|
this.currentFilePath = filePath;
|
|
13294
13350
|
this.currentAST = ast;
|
|
13295
13351
|
this.currentImports = importedModules;
|
|
13352
|
+
this.preprocessedFiles.add(filePath);
|
|
13296
13353
|
resolvedTraverse(ast, {
|
|
13297
13354
|
ExportNamedDeclaration: (path25) => {
|
|
13298
13355
|
if (t10.isVariableDeclaration(path25.node.declaration)) {
|
|
@@ -13300,15 +13357,19 @@ var ZodSchemaConverter = class {
|
|
|
13300
13357
|
if (t10.isIdentifier(declaration.id) && declaration.init) {
|
|
13301
13358
|
const schemaName = declaration.id.name;
|
|
13302
13359
|
if (this.isZodSchema(declaration.init)) {
|
|
13303
|
-
this.indexSchemaName(schemaName, filePath);
|
|
13304
13360
|
if (!this.getStoredSchema(schemaName)) {
|
|
13305
13361
|
logger.debug(`Pre-processing Zod schema: ${schemaName}`);
|
|
13306
13362
|
this.processingSchemas.add(schemaName);
|
|
13307
13363
|
const schema = this.processZodNode(declaration.init);
|
|
13364
|
+
this.processingSchemas.delete(schemaName);
|
|
13308
13365
|
if (schema) {
|
|
13309
|
-
this.
|
|
13366
|
+
const overrideId = this.extractMetaIdFromNode(declaration.init);
|
|
13367
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
13368
|
+
} else {
|
|
13369
|
+
this.indexSchemaName(schemaName, filePath);
|
|
13310
13370
|
}
|
|
13311
|
-
|
|
13371
|
+
} else {
|
|
13372
|
+
this.indexSchemaName(schemaName, filePath);
|
|
13312
13373
|
}
|
|
13313
13374
|
}
|
|
13314
13375
|
}
|
|
@@ -13321,22 +13382,25 @@ var ZodSchemaConverter = class {
|
|
|
13321
13382
|
if (t10.isIdentifier(declaration.id) && declaration.init) {
|
|
13322
13383
|
const schemaName = declaration.id.name;
|
|
13323
13384
|
if (this.isZodSchema(declaration.init)) {
|
|
13324
|
-
this.indexSchemaName(schemaName, filePath);
|
|
13325
13385
|
if (!this.getStoredSchema(schemaName) && !this.processingSchemas.has(schemaName)) {
|
|
13326
13386
|
logger.debug(`Pre-processing Zod schema: ${schemaName}`);
|
|
13327
13387
|
this.processingSchemas.add(schemaName);
|
|
13328
13388
|
const schema = this.processZodNode(declaration.init);
|
|
13389
|
+
this.processingSchemas.delete(schemaName);
|
|
13329
13390
|
if (schema) {
|
|
13330
|
-
this.
|
|
13391
|
+
const overrideId = this.extractMetaIdFromNode(declaration.init);
|
|
13392
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
13393
|
+
} else {
|
|
13394
|
+
this.indexSchemaName(schemaName, filePath);
|
|
13331
13395
|
}
|
|
13332
|
-
|
|
13396
|
+
} else {
|
|
13397
|
+
this.indexSchemaName(schemaName, filePath);
|
|
13333
13398
|
}
|
|
13334
13399
|
}
|
|
13335
13400
|
}
|
|
13336
13401
|
});
|
|
13337
13402
|
}
|
|
13338
13403
|
});
|
|
13339
|
-
this.preprocessedFiles.add(filePath);
|
|
13340
13404
|
} catch (error2) {
|
|
13341
13405
|
logger.error(`Error pre-processing file ${filePath}: ${error2}`);
|
|
13342
13406
|
}
|
|
@@ -13354,6 +13418,21 @@ var ZodSchemaConverter = class {
|
|
|
13354
13418
|
}
|
|
13355
13419
|
bucket.add(filePath);
|
|
13356
13420
|
}
|
|
13421
|
+
applyMetaIdOverride(schemaName, schema, overrideId, filePath) {
|
|
13422
|
+
const finalName = overrideId && overrideId !== schemaName ? overrideId : schemaName;
|
|
13423
|
+
this.indexSchemaName(schemaName, filePath);
|
|
13424
|
+
if (finalName !== schemaName) {
|
|
13425
|
+
this.indexSchemaName(finalName, filePath);
|
|
13426
|
+
}
|
|
13427
|
+
if (!this.getStoredSchema(finalName)) {
|
|
13428
|
+
if (overrideId && overrideId !== schemaName) {
|
|
13429
|
+
this.typeToSchemaMapping[schemaName] = overrideId;
|
|
13430
|
+
}
|
|
13431
|
+
this.storeResolvedSchema(finalName, schema);
|
|
13432
|
+
} else {
|
|
13433
|
+
logger.warn(`Schema component name '${overrideId ?? finalName}' conflicts with an existing schema, ignoring .meta({ id }) on '${schemaName}'`);
|
|
13434
|
+
}
|
|
13435
|
+
}
|
|
13357
13436
|
/**
|
|
13358
13437
|
* Check if node is Zod schema
|
|
13359
13438
|
*/
|
|
@@ -13557,15 +13636,39 @@ function extractKeysFromLiteralType(node) {
|
|
|
13557
13636
|
}
|
|
13558
13637
|
return [];
|
|
13559
13638
|
}
|
|
13639
|
+
function parsePropertyComment(commentValue) {
|
|
13640
|
+
const text = commentValue.split("\n").map((line) => line.replace(/^\s*\*\s?/, "").trim()).filter((line) => line.length > 0).join(" ").trim();
|
|
13641
|
+
const result = {};
|
|
13642
|
+
let remaining = text;
|
|
13643
|
+
const formatMatch = remaining.match(/@format\s+(\S+)/);
|
|
13644
|
+
if (formatMatch?.[1]) {
|
|
13645
|
+
result.format = formatMatch[1];
|
|
13646
|
+
remaining = remaining.replace(formatMatch[0], "").trim();
|
|
13647
|
+
}
|
|
13648
|
+
const exampleMatch = remaining.match(/@example\s+(.+?)(?=\s*@\w|$)/);
|
|
13649
|
+
if (exampleMatch?.[1]) {
|
|
13650
|
+
const raw = exampleMatch[1].trim();
|
|
13651
|
+
try {
|
|
13652
|
+
result.example = JSON.parse(raw);
|
|
13653
|
+
} catch {
|
|
13654
|
+
result.example = raw;
|
|
13655
|
+
}
|
|
13656
|
+
remaining = remaining.replace(exampleMatch[0], "").trim();
|
|
13657
|
+
}
|
|
13658
|
+
remaining = remaining.replace(/@\w+(?:\s+\S+)*/g, "").trim();
|
|
13659
|
+
if (remaining) {
|
|
13660
|
+
result.description = remaining;
|
|
13661
|
+
}
|
|
13662
|
+
return result;
|
|
13663
|
+
}
|
|
13560
13664
|
function getPropertyOptions(node, contentType) {
|
|
13561
13665
|
const isOptional = !!node.optional;
|
|
13562
|
-
let description = null;
|
|
13563
|
-
if (node.trailingComments && node.trailingComments.length) {
|
|
13564
|
-
description = node.trailingComments[0].value.trim();
|
|
13565
|
-
}
|
|
13566
13666
|
const options = {};
|
|
13567
|
-
|
|
13568
|
-
|
|
13667
|
+
const leadingComment = node.leadingComments?.findLast((c) => c.type === "CommentBlock" || !node.trailingComments?.length);
|
|
13668
|
+
const trailingComment = node.trailingComments?.[0];
|
|
13669
|
+
const sourceComment = leadingComment ?? trailingComment;
|
|
13670
|
+
if (sourceComment) {
|
|
13671
|
+
Object.assign(options, parsePropertyComment(sourceComment.value));
|
|
13569
13672
|
}
|
|
13570
13673
|
if (contentType === "body") {
|
|
13571
13674
|
options.nullable = isOptional;
|
|
@@ -13964,31 +14067,60 @@ function resolveImportPath(importPath, fromFilePath, fileAccess) {
|
|
|
13964
14067
|
}
|
|
13965
14068
|
return null;
|
|
13966
14069
|
}
|
|
13967
|
-
function
|
|
14070
|
+
function collectFirstMemberLeadingComments(interfaceDecl) {
|
|
14071
|
+
const body = interfaceDecl?.body;
|
|
14072
|
+
if (!body)
|
|
14073
|
+
return [];
|
|
14074
|
+
const firstMember = body.body?.[0];
|
|
14075
|
+
return firstMember?.leadingComments ?? [];
|
|
14076
|
+
}
|
|
14077
|
+
function collectAllExportedDefinitions(ast, typeDefinitions, currentFile, schemaIdAliases) {
|
|
14078
|
+
function registerDefinition(name, entry, allComments) {
|
|
14079
|
+
if (!typeDefinitions[name]) {
|
|
14080
|
+
typeDefinitions[name] = entry;
|
|
14081
|
+
}
|
|
14082
|
+
const overrideId = extractSchemaIdFromComments(allComments);
|
|
14083
|
+
if (overrideId && schemaIdAliases) {
|
|
14084
|
+
schemaIdAliases[name] = overrideId;
|
|
14085
|
+
if (!typeDefinitions[overrideId]) {
|
|
14086
|
+
typeDefinitions[overrideId] = entry;
|
|
14087
|
+
}
|
|
14088
|
+
}
|
|
14089
|
+
}
|
|
13968
14090
|
resolvedTraverse(ast, {
|
|
13969
14091
|
TSTypeAliasDeclaration: (path25) => {
|
|
13970
14092
|
if (path25.node.id && t12.isIdentifier(path25.node.id)) {
|
|
13971
14093
|
const name = path25.node.id.name;
|
|
13972
|
-
|
|
13973
|
-
|
|
13974
|
-
|
|
13975
|
-
|
|
14094
|
+
const node = path25.node.typeParameters && path25.node.typeParameters.params.length > 0 ? path25.node : path25.node.typeAnnotation;
|
|
14095
|
+
const allComments = [
|
|
14096
|
+
...path25.parentPath?.node?.leadingComments ?? [],
|
|
14097
|
+
...path25.node.leadingComments ?? [],
|
|
14098
|
+
...path25.node.trailingComments ?? []
|
|
14099
|
+
];
|
|
14100
|
+
registerDefinition(name, { node, filePath: currentFile }, allComments);
|
|
13976
14101
|
}
|
|
13977
14102
|
},
|
|
13978
14103
|
TSInterfaceDeclaration: (path25) => {
|
|
13979
14104
|
if (path25.node.id && t12.isIdentifier(path25.node.id)) {
|
|
13980
14105
|
const name = path25.node.id.name;
|
|
13981
|
-
|
|
13982
|
-
|
|
13983
|
-
|
|
14106
|
+
const allComments = [
|
|
14107
|
+
...path25.parentPath?.node?.leadingComments ?? [],
|
|
14108
|
+
...path25.node.leadingComments ?? [],
|
|
14109
|
+
...path25.node.trailingComments ?? [],
|
|
14110
|
+
...collectFirstMemberLeadingComments(path25.node)
|
|
14111
|
+
];
|
|
14112
|
+
registerDefinition(name, { node: path25.node, filePath: currentFile }, allComments);
|
|
13984
14113
|
}
|
|
13985
14114
|
},
|
|
13986
14115
|
TSEnumDeclaration: (path25) => {
|
|
13987
14116
|
if (path25.node.id && t12.isIdentifier(path25.node.id)) {
|
|
13988
14117
|
const name = path25.node.id.name;
|
|
13989
|
-
|
|
13990
|
-
|
|
13991
|
-
|
|
14118
|
+
const allComments = [
|
|
14119
|
+
...path25.parentPath?.node?.leadingComments ?? [],
|
|
14120
|
+
...path25.node.leadingComments ?? [],
|
|
14121
|
+
...path25.node.trailingComments ?? []
|
|
14122
|
+
];
|
|
14123
|
+
registerDefinition(name, { node: path25.node, filePath: currentFile }, allComments);
|
|
13992
14124
|
}
|
|
13993
14125
|
},
|
|
13994
14126
|
ExportNamedDeclaration: (path25) => {
|
|
@@ -13996,19 +14128,26 @@ function collectAllExportedDefinitions(ast, typeDefinitions, currentFile) {
|
|
|
13996
14128
|
const interfaceDecl = path25.node.declaration;
|
|
13997
14129
|
if (interfaceDecl.id && t12.isIdentifier(interfaceDecl.id)) {
|
|
13998
14130
|
const name = interfaceDecl.id.name;
|
|
13999
|
-
|
|
14000
|
-
|
|
14001
|
-
|
|
14131
|
+
const allComments = [
|
|
14132
|
+
...path25.node.leadingComments ?? [],
|
|
14133
|
+
...interfaceDecl.leadingComments ?? [],
|
|
14134
|
+
...interfaceDecl.trailingComments ?? [],
|
|
14135
|
+
...collectFirstMemberLeadingComments(interfaceDecl)
|
|
14136
|
+
];
|
|
14137
|
+
registerDefinition(name, { node: interfaceDecl, filePath: currentFile }, allComments);
|
|
14002
14138
|
}
|
|
14003
14139
|
}
|
|
14004
14140
|
if (t12.isTSTypeAliasDeclaration(path25.node.declaration)) {
|
|
14005
14141
|
const typeDecl = path25.node.declaration;
|
|
14006
14142
|
if (typeDecl.id && t12.isIdentifier(typeDecl.id)) {
|
|
14007
14143
|
const name = typeDecl.id.name;
|
|
14008
|
-
|
|
14009
|
-
|
|
14010
|
-
|
|
14011
|
-
|
|
14144
|
+
const node = typeDecl.typeParameters && typeDecl.typeParameters.params.length > 0 ? typeDecl : typeDecl.typeAnnotation;
|
|
14145
|
+
const allComments = [
|
|
14146
|
+
...path25.node.leadingComments ?? [],
|
|
14147
|
+
...typeDecl.leadingComments ?? [],
|
|
14148
|
+
...typeDecl.trailingComments ?? []
|
|
14149
|
+
];
|
|
14150
|
+
registerDefinition(name, { node, filePath: currentFile }, allComments);
|
|
14012
14151
|
}
|
|
14013
14152
|
}
|
|
14014
14153
|
}
|
|
@@ -14425,6 +14564,7 @@ var SchemaProcessor = class {
|
|
|
14425
14564
|
zodSchemaProcessor = null;
|
|
14426
14565
|
schemaTypes;
|
|
14427
14566
|
isResolvingPickOmitBase = false;
|
|
14567
|
+
schemaIdAliases = {};
|
|
14428
14568
|
fileAccess;
|
|
14429
14569
|
symbolResolver;
|
|
14430
14570
|
// Track imports per file for resolving ReturnType<typeof func>
|
|
@@ -14465,7 +14605,7 @@ var SchemaProcessor = class {
|
|
|
14465
14605
|
getDefinedSchemas() {
|
|
14466
14606
|
const filteredSchemas = {};
|
|
14467
14607
|
Object.entries(this.openapiDefinitions).forEach(([key, value]) => {
|
|
14468
|
-
if (!this.isGenericTypeParameter(key) && !this.isInvalidSchemaName(key) && !this.isBuiltInUtilityType(key) && !this.isFunctionSchema(key)) {
|
|
14608
|
+
if (!this.schemaIdAliases[key] && !this.isGenericTypeParameter(key) && !this.isInvalidSchemaName(key) && !this.isBuiltInUtilityType(key) && !this.isFunctionSchema(key)) {
|
|
14469
14609
|
filteredSchemas[key] = value;
|
|
14470
14610
|
}
|
|
14471
14611
|
});
|
|
@@ -14480,6 +14620,10 @@ var SchemaProcessor = class {
|
|
|
14480
14620
|
if (schemaName.includes("<") && schemaName.includes(">")) {
|
|
14481
14621
|
return this.resolveGenericTypeFromString(schemaName);
|
|
14482
14622
|
}
|
|
14623
|
+
const overrideId = this.schemaIdAliases[schemaName];
|
|
14624
|
+
if (overrideId) {
|
|
14625
|
+
return this.findSchemaDefinition(overrideId, contentType);
|
|
14626
|
+
}
|
|
14483
14627
|
if (this.openapiDefinitions[schemaName]) {
|
|
14484
14628
|
return this.openapiDefinitions[schemaName];
|
|
14485
14629
|
}
|
|
@@ -14561,6 +14705,7 @@ var SchemaProcessor = class {
|
|
|
14561
14705
|
return;
|
|
14562
14706
|
}
|
|
14563
14707
|
this.collectImports(ast, filePath);
|
|
14708
|
+
const aliasesBeforeFile = new Set(Object.keys(this.schemaIdAliases));
|
|
14564
14709
|
this.collectAllExportedDefinitions(ast, filePath);
|
|
14565
14710
|
collectTopLevelDefinitionNames(ast).forEach((name) => {
|
|
14566
14711
|
const indexedFiles = this.schemaDefinitionIndex[name];
|
|
@@ -14572,6 +14717,16 @@ var SchemaProcessor = class {
|
|
|
14572
14717
|
}
|
|
14573
14718
|
this.schemaDefinitionIndex[name] = [filePath];
|
|
14574
14719
|
});
|
|
14720
|
+
Object.entries(this.schemaIdAliases).forEach(([originalName, aliasName]) => {
|
|
14721
|
+
if (aliasesBeforeFile.has(originalName))
|
|
14722
|
+
return;
|
|
14723
|
+
if (!this.schemaDefinitionIndex[aliasName]) {
|
|
14724
|
+
this.schemaDefinitionIndex[aliasName] = [];
|
|
14725
|
+
}
|
|
14726
|
+
if (!this.schemaDefinitionIndex[aliasName].includes(filePath)) {
|
|
14727
|
+
this.schemaDefinitionIndex[aliasName].push(filePath);
|
|
14728
|
+
}
|
|
14729
|
+
});
|
|
14575
14730
|
}
|
|
14576
14731
|
getParsedSchemaFile(filePath) {
|
|
14577
14732
|
const cachedAst = this.fileASTCache.get(filePath);
|
|
@@ -14610,7 +14765,7 @@ var SchemaProcessor = class {
|
|
|
14610
14765
|
* Used when processing imported files to ensure all referenced types are available
|
|
14611
14766
|
*/
|
|
14612
14767
|
collectAllExportedDefinitions(ast, filePath) {
|
|
14613
|
-
collectAllExportedDefinitions(ast, this.typeDefinitions, filePath || this.currentFilePath);
|
|
14768
|
+
collectAllExportedDefinitions(ast, this.typeDefinitions, filePath || this.currentFilePath, this.schemaIdAliases);
|
|
14614
14769
|
}
|
|
14615
14770
|
collectTypeDefinitions(ast, schemaName, filePath) {
|
|
14616
14771
|
collectTypeDefinitions(ast, schemaName, this.typeDefinitions, filePath || this.currentFilePath);
|
|
@@ -15207,6 +15362,9 @@ var SchemaProcessor = class {
|
|
|
15207
15362
|
logger.debug(`Record<...> used with ${node.typeParameters?.params.length ?? 0} type parameters; expected 2`);
|
|
15208
15363
|
return { type: "object", additionalProperties: true };
|
|
15209
15364
|
}
|
|
15365
|
+
if ((!node.typeParameters || node.typeParameters.params.length === 0) && this.schemaIdAliases[typeName] && this.openapiDefinitions[this.schemaIdAliases[typeName]]) {
|
|
15366
|
+
return { $ref: `#/components/schemas/${this.schemaIdAliases[typeName]}` };
|
|
15367
|
+
}
|
|
15210
15368
|
const utilityType = resolveUtilityTypeReference(node, {
|
|
15211
15369
|
currentFilePath: this.currentFilePath,
|
|
15212
15370
|
contentType: this.contentType,
|
|
@@ -15382,7 +15540,9 @@ var SchemaProcessor = class {
|
|
|
15382
15540
|
};
|
|
15383
15541
|
}
|
|
15384
15542
|
if (t15.isTSTypeReference(node) && t15.isIdentifier(node.typeName)) {
|
|
15385
|
-
|
|
15543
|
+
const refName = node.typeName.name;
|
|
15544
|
+
const aliasedName = this.schemaIdAliases[refName] ?? refName;
|
|
15545
|
+
return { $ref: `#/components/schemas/${aliasedName}` };
|
|
15386
15546
|
}
|
|
15387
15547
|
logger.debug("Unrecognized TypeScript type node:", node);
|
|
15388
15548
|
return { type: "object" };
|
|
@@ -15523,7 +15683,8 @@ var SchemaProcessor = class {
|
|
|
15523
15683
|
if (this.schemaTypes.includes("zod") && this.zodSchemaConverter) {
|
|
15524
15684
|
return this.zodSchemaConverter.getSchemaReferenceName(baseTypeName, contentType);
|
|
15525
15685
|
}
|
|
15526
|
-
|
|
15686
|
+
const aliasedName = this.schemaIdAliases[baseTypeName] ?? baseTypeName;
|
|
15687
|
+
return aliasedName;
|
|
15527
15688
|
}
|
|
15528
15689
|
/**
|
|
15529
15690
|
* Parse and resolve a generic type from a string like "MyApiSuccessResponseBody<LLMSResponse>"
|