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/next/index.js
CHANGED
|
@@ -1306,6 +1306,17 @@ function mergeJSDocData(target, source) {
|
|
|
1306
1306
|
function cleanComment(commentValue) {
|
|
1307
1307
|
return commentValue.replace(/\*\s*/g, "").trim();
|
|
1308
1308
|
}
|
|
1309
|
+
function extractSchemaIdFromComments(comments) {
|
|
1310
|
+
if (!comments)
|
|
1311
|
+
return null;
|
|
1312
|
+
for (const comment of comments) {
|
|
1313
|
+
const cleaned = cleanComment(comment.value);
|
|
1314
|
+
const id = extractTokenValue(cleaned, "@id");
|
|
1315
|
+
if (id)
|
|
1316
|
+
return id;
|
|
1317
|
+
}
|
|
1318
|
+
return null;
|
|
1319
|
+
}
|
|
1309
1320
|
function extractLineValue(commentValue, tag) {
|
|
1310
1321
|
return commentValue.match(new RegExp(`${escapeRegExp(tag)}\\s*(.*)`, "m"))?.[1]?.trim() || "";
|
|
1311
1322
|
}
|
|
@@ -4168,7 +4179,8 @@ var DrizzleZodProcessor = class _DrizzleZodProcessor {
|
|
|
4168
4179
|
if (firstArg && !t5.isSpreadElement(firstArg) && !t5.isArgumentPlaceholder(firstArg)) {
|
|
4169
4180
|
const metadata = _DrizzleZodProcessor.extractStaticObject(firstArg);
|
|
4170
4181
|
if (metadata) {
|
|
4171
|
-
|
|
4182
|
+
const { id: _id, ...rest } = metadata;
|
|
4183
|
+
Object.assign(result, rest);
|
|
4172
4184
|
}
|
|
4173
4185
|
}
|
|
4174
4186
|
break;
|
|
@@ -12452,8 +12464,11 @@ var ZodRuntimeExporter = class {
|
|
|
12452
12464
|
case "deprecated":
|
|
12453
12465
|
return schema.meta({ deprecated: true });
|
|
12454
12466
|
case "meta": {
|
|
12455
|
-
const
|
|
12456
|
-
|
|
12467
|
+
const rawMetadata = node.arguments[0] ? this.buildMetadataObject(node.arguments[0]) : null;
|
|
12468
|
+
if (!rawMetadata)
|
|
12469
|
+
return schema;
|
|
12470
|
+
const { id: _id, ...metadata } = rawMetadata;
|
|
12471
|
+
return Object.keys(metadata).length > 0 ? schema.meta(metadata) : schema;
|
|
12457
12472
|
}
|
|
12458
12473
|
case "default":
|
|
12459
12474
|
case "prefault":
|
|
@@ -12689,7 +12704,9 @@ var ZodSchemaConverter = class {
|
|
|
12689
12704
|
apiDir;
|
|
12690
12705
|
zodSchemas = {};
|
|
12691
12706
|
processingSchemas = /* @__PURE__ */ new Set();
|
|
12692
|
-
|
|
12707
|
+
/** Memoization guard for processFileForZodSchema. Keys: `${filePath}|${schemaName}`.
|
|
12708
|
+
* Prevents infinite recursion when re-export files reference schemas via z.infer<typeof X>. */
|
|
12709
|
+
processedFileSchemaPairs = /* @__PURE__ */ new Set();
|
|
12693
12710
|
typeToSchemaMapping = {};
|
|
12694
12711
|
drizzleZodImports = /* @__PURE__ */ new Set();
|
|
12695
12712
|
factoryCache = /* @__PURE__ */ new Map();
|
|
@@ -12903,6 +12920,11 @@ var ZodSchemaConverter = class {
|
|
|
12903
12920
|
* Process a file to find Zod schema definitions
|
|
12904
12921
|
*/
|
|
12905
12922
|
processFileForZodSchema(filePath, schemaName) {
|
|
12923
|
+
const visitKey = `${filePath}|${schemaName}|${this.currentContentType}`;
|
|
12924
|
+
if (this.processedFileSchemaPairs.has(visitKey)) {
|
|
12925
|
+
return;
|
|
12926
|
+
}
|
|
12927
|
+
this.processedFileSchemaPairs.add(visitKey);
|
|
12906
12928
|
try {
|
|
12907
12929
|
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
12908
12930
|
if (!content.includes(schemaName)) {
|
|
@@ -13216,7 +13238,9 @@ var ZodSchemaConverter = class {
|
|
|
13216
13238
|
const param = path19.node.typeAnnotation.typeParameters.params[0];
|
|
13217
13239
|
if (t11.isTSTypeQuery(param) && t11.isIdentifier(param.exprName)) {
|
|
13218
13240
|
const referencedSchemaName = param.exprName.name;
|
|
13219
|
-
this.
|
|
13241
|
+
if (!this.getStoredSchema(referencedSchemaName)) {
|
|
13242
|
+
this.processFileForZodSchema(filePath, referencedSchemaName);
|
|
13243
|
+
}
|
|
13220
13244
|
}
|
|
13221
13245
|
}
|
|
13222
13246
|
}
|
|
@@ -13234,6 +13258,8 @@ var ZodSchemaConverter = class {
|
|
|
13234
13258
|
try {
|
|
13235
13259
|
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
13236
13260
|
const ast = parseTypeScriptFile(content);
|
|
13261
|
+
this.currentFilePath = filePath;
|
|
13262
|
+
this.currentAST = ast;
|
|
13237
13263
|
resolvedTraverse(ast, {
|
|
13238
13264
|
ExportNamedDeclaration: (path19) => {
|
|
13239
13265
|
if (t11.isVariableDeclaration(path19.node.declaration)) {
|
|
@@ -13248,6 +13274,17 @@ var ZodSchemaConverter = class {
|
|
|
13248
13274
|
}
|
|
13249
13275
|
this.processingSchemas.delete(schemaName);
|
|
13250
13276
|
}
|
|
13277
|
+
} else if (t11.isIdentifier(declaration.id) && declaration.init) {
|
|
13278
|
+
const schemaName = declaration.id.name;
|
|
13279
|
+
const overrideId = this.extractMetaIdFromNode(declaration.init);
|
|
13280
|
+
if (overrideId && !this.getStoredSchema(schemaName) && !this.processingSchemas.has(schemaName)) {
|
|
13281
|
+
this.processingSchemas.add(schemaName);
|
|
13282
|
+
const schema = this.processZodNode(declaration.init);
|
|
13283
|
+
this.processingSchemas.delete(schemaName);
|
|
13284
|
+
if (schema) {
|
|
13285
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
13286
|
+
}
|
|
13287
|
+
}
|
|
13251
13288
|
}
|
|
13252
13289
|
});
|
|
13253
13290
|
}
|
|
@@ -13801,6 +13838,24 @@ var ZodSchemaConverter = class {
|
|
|
13801
13838
|
}
|
|
13802
13839
|
return void 0;
|
|
13803
13840
|
}
|
|
13841
|
+
extractMetaIdFromNode(node) {
|
|
13842
|
+
if (!t11.isCallExpression(node))
|
|
13843
|
+
return null;
|
|
13844
|
+
if (t11.isMemberExpression(node.callee) && t11.isIdentifier(node.callee.property)) {
|
|
13845
|
+
if (node.callee.property.name === "meta" && node.arguments.length > 0) {
|
|
13846
|
+
const metadata = this.extractStaticJsonValue(node.arguments[0]);
|
|
13847
|
+
if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
13848
|
+
const id = metadata.id;
|
|
13849
|
+
if (typeof id === "string" && id.length > 0)
|
|
13850
|
+
return id;
|
|
13851
|
+
}
|
|
13852
|
+
}
|
|
13853
|
+
if (t11.isCallExpression(node.callee.object)) {
|
|
13854
|
+
return this.extractMetaIdFromNode(node.callee.object);
|
|
13855
|
+
}
|
|
13856
|
+
}
|
|
13857
|
+
return null;
|
|
13858
|
+
}
|
|
13804
13859
|
shouldUseRuntimeExport(node) {
|
|
13805
13860
|
if (!t11.isCallExpression(node)) {
|
|
13806
13861
|
return false;
|
|
@@ -14041,7 +14096,8 @@ var ZodSchemaConverter = class {
|
|
|
14041
14096
|
if (node.arguments.length > 0) {
|
|
14042
14097
|
const metadata = this.extractStaticJsonValue(node.arguments[0]);
|
|
14043
14098
|
if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
14044
|
-
|
|
14099
|
+
const { id: _id, ...rest } = metadata;
|
|
14100
|
+
Object.assign(schema, rest);
|
|
14045
14101
|
}
|
|
14046
14102
|
}
|
|
14047
14103
|
break;
|
|
@@ -14327,6 +14383,7 @@ var ZodSchemaConverter = class {
|
|
|
14327
14383
|
this.currentFilePath = filePath;
|
|
14328
14384
|
this.currentAST = ast;
|
|
14329
14385
|
this.currentImports = importedModules;
|
|
14386
|
+
this.preprocessedFiles.add(filePath);
|
|
14330
14387
|
resolvedTraverse(ast, {
|
|
14331
14388
|
ExportNamedDeclaration: (path19) => {
|
|
14332
14389
|
if (t11.isVariableDeclaration(path19.node.declaration)) {
|
|
@@ -14334,15 +14391,19 @@ var ZodSchemaConverter = class {
|
|
|
14334
14391
|
if (t11.isIdentifier(declaration.id) && declaration.init) {
|
|
14335
14392
|
const schemaName = declaration.id.name;
|
|
14336
14393
|
if (this.isZodSchema(declaration.init)) {
|
|
14337
|
-
this.indexSchemaName(schemaName, filePath);
|
|
14338
14394
|
if (!this.getStoredSchema(schemaName)) {
|
|
14339
14395
|
logger.debug(`Pre-processing Zod schema: ${schemaName}`);
|
|
14340
14396
|
this.processingSchemas.add(schemaName);
|
|
14341
14397
|
const schema = this.processZodNode(declaration.init);
|
|
14398
|
+
this.processingSchemas.delete(schemaName);
|
|
14342
14399
|
if (schema) {
|
|
14343
|
-
this.
|
|
14400
|
+
const overrideId = this.extractMetaIdFromNode(declaration.init);
|
|
14401
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
14402
|
+
} else {
|
|
14403
|
+
this.indexSchemaName(schemaName, filePath);
|
|
14344
14404
|
}
|
|
14345
|
-
|
|
14405
|
+
} else {
|
|
14406
|
+
this.indexSchemaName(schemaName, filePath);
|
|
14346
14407
|
}
|
|
14347
14408
|
}
|
|
14348
14409
|
}
|
|
@@ -14355,22 +14416,25 @@ var ZodSchemaConverter = class {
|
|
|
14355
14416
|
if (t11.isIdentifier(declaration.id) && declaration.init) {
|
|
14356
14417
|
const schemaName = declaration.id.name;
|
|
14357
14418
|
if (this.isZodSchema(declaration.init)) {
|
|
14358
|
-
this.indexSchemaName(schemaName, filePath);
|
|
14359
14419
|
if (!this.getStoredSchema(schemaName) && !this.processingSchemas.has(schemaName)) {
|
|
14360
14420
|
logger.debug(`Pre-processing Zod schema: ${schemaName}`);
|
|
14361
14421
|
this.processingSchemas.add(schemaName);
|
|
14362
14422
|
const schema = this.processZodNode(declaration.init);
|
|
14423
|
+
this.processingSchemas.delete(schemaName);
|
|
14363
14424
|
if (schema) {
|
|
14364
|
-
this.
|
|
14425
|
+
const overrideId = this.extractMetaIdFromNode(declaration.init);
|
|
14426
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
14427
|
+
} else {
|
|
14428
|
+
this.indexSchemaName(schemaName, filePath);
|
|
14365
14429
|
}
|
|
14366
|
-
|
|
14430
|
+
} else {
|
|
14431
|
+
this.indexSchemaName(schemaName, filePath);
|
|
14367
14432
|
}
|
|
14368
14433
|
}
|
|
14369
14434
|
}
|
|
14370
14435
|
});
|
|
14371
14436
|
}
|
|
14372
14437
|
});
|
|
14373
|
-
this.preprocessedFiles.add(filePath);
|
|
14374
14438
|
} catch (error2) {
|
|
14375
14439
|
logger.error(`Error pre-processing file ${filePath}: ${error2}`);
|
|
14376
14440
|
}
|
|
@@ -14388,6 +14452,21 @@ var ZodSchemaConverter = class {
|
|
|
14388
14452
|
}
|
|
14389
14453
|
bucket.add(filePath);
|
|
14390
14454
|
}
|
|
14455
|
+
applyMetaIdOverride(schemaName, schema, overrideId, filePath) {
|
|
14456
|
+
const finalName = overrideId && overrideId !== schemaName ? overrideId : schemaName;
|
|
14457
|
+
this.indexSchemaName(schemaName, filePath);
|
|
14458
|
+
if (finalName !== schemaName) {
|
|
14459
|
+
this.indexSchemaName(finalName, filePath);
|
|
14460
|
+
}
|
|
14461
|
+
if (!this.getStoredSchema(finalName)) {
|
|
14462
|
+
if (overrideId && overrideId !== schemaName) {
|
|
14463
|
+
this.typeToSchemaMapping[schemaName] = overrideId;
|
|
14464
|
+
}
|
|
14465
|
+
this.storeResolvedSchema(finalName, schema);
|
|
14466
|
+
} else {
|
|
14467
|
+
logger.warn(`Schema component name '${overrideId ?? finalName}' conflicts with an existing schema, ignoring .meta({ id }) on '${schemaName}'`);
|
|
14468
|
+
}
|
|
14469
|
+
}
|
|
14391
14470
|
/**
|
|
14392
14471
|
* Check if node is Zod schema
|
|
14393
14472
|
*/
|
|
@@ -14591,15 +14670,39 @@ function extractKeysFromLiteralType(node) {
|
|
|
14591
14670
|
}
|
|
14592
14671
|
return [];
|
|
14593
14672
|
}
|
|
14673
|
+
function parsePropertyComment(commentValue) {
|
|
14674
|
+
const text = commentValue.split("\n").map((line) => line.replace(/^\s*\*\s?/, "").trim()).filter((line) => line.length > 0).join(" ").trim();
|
|
14675
|
+
const result = {};
|
|
14676
|
+
let remaining = text;
|
|
14677
|
+
const formatMatch = remaining.match(/@format\s+(\S+)/);
|
|
14678
|
+
if (formatMatch?.[1]) {
|
|
14679
|
+
result.format = formatMatch[1];
|
|
14680
|
+
remaining = remaining.replace(formatMatch[0], "").trim();
|
|
14681
|
+
}
|
|
14682
|
+
const exampleMatch = remaining.match(/@example\s+(.+?)(?=\s*@\w|$)/);
|
|
14683
|
+
if (exampleMatch?.[1]) {
|
|
14684
|
+
const raw = exampleMatch[1].trim();
|
|
14685
|
+
try {
|
|
14686
|
+
result.example = JSON.parse(raw);
|
|
14687
|
+
} catch {
|
|
14688
|
+
result.example = raw;
|
|
14689
|
+
}
|
|
14690
|
+
remaining = remaining.replace(exampleMatch[0], "").trim();
|
|
14691
|
+
}
|
|
14692
|
+
remaining = remaining.replace(/@\w+(?:\s+\S+)*/g, "").trim();
|
|
14693
|
+
if (remaining) {
|
|
14694
|
+
result.description = remaining;
|
|
14695
|
+
}
|
|
14696
|
+
return result;
|
|
14697
|
+
}
|
|
14594
14698
|
function getPropertyOptions(node, contentType) {
|
|
14595
14699
|
const isOptional = !!node.optional;
|
|
14596
|
-
let description = null;
|
|
14597
|
-
if (node.trailingComments && node.trailingComments.length) {
|
|
14598
|
-
description = node.trailingComments[0].value.trim();
|
|
14599
|
-
}
|
|
14600
14700
|
const options = {};
|
|
14601
|
-
|
|
14602
|
-
|
|
14701
|
+
const leadingComment = node.leadingComments?.findLast((c) => c.type === "CommentBlock" || !node.trailingComments?.length);
|
|
14702
|
+
const trailingComment = node.trailingComments?.[0];
|
|
14703
|
+
const sourceComment = leadingComment ?? trailingComment;
|
|
14704
|
+
if (sourceComment) {
|
|
14705
|
+
Object.assign(options, parsePropertyComment(sourceComment.value));
|
|
14603
14706
|
}
|
|
14604
14707
|
if (contentType === "body") {
|
|
14605
14708
|
options.nullable = isOptional;
|
|
@@ -14998,31 +15101,60 @@ function resolveImportPath(importPath, fromFilePath, fileAccess) {
|
|
|
14998
15101
|
}
|
|
14999
15102
|
return null;
|
|
15000
15103
|
}
|
|
15001
|
-
function
|
|
15104
|
+
function collectFirstMemberLeadingComments(interfaceDecl) {
|
|
15105
|
+
const body = interfaceDecl?.body;
|
|
15106
|
+
if (!body)
|
|
15107
|
+
return [];
|
|
15108
|
+
const firstMember = body.body?.[0];
|
|
15109
|
+
return firstMember?.leadingComments ?? [];
|
|
15110
|
+
}
|
|
15111
|
+
function collectAllExportedDefinitions(ast, typeDefinitions, currentFile, schemaIdAliases) {
|
|
15112
|
+
function registerDefinition(name, entry, allComments) {
|
|
15113
|
+
if (!typeDefinitions[name]) {
|
|
15114
|
+
typeDefinitions[name] = entry;
|
|
15115
|
+
}
|
|
15116
|
+
const overrideId = extractSchemaIdFromComments(allComments);
|
|
15117
|
+
if (overrideId && schemaIdAliases) {
|
|
15118
|
+
schemaIdAliases[name] = overrideId;
|
|
15119
|
+
if (!typeDefinitions[overrideId]) {
|
|
15120
|
+
typeDefinitions[overrideId] = entry;
|
|
15121
|
+
}
|
|
15122
|
+
}
|
|
15123
|
+
}
|
|
15002
15124
|
resolvedTraverse(ast, {
|
|
15003
15125
|
TSTypeAliasDeclaration: (path19) => {
|
|
15004
15126
|
if (path19.node.id && t13.isIdentifier(path19.node.id)) {
|
|
15005
15127
|
const name = path19.node.id.name;
|
|
15006
|
-
|
|
15007
|
-
|
|
15008
|
-
|
|
15009
|
-
|
|
15128
|
+
const node = path19.node.typeParameters && path19.node.typeParameters.params.length > 0 ? path19.node : path19.node.typeAnnotation;
|
|
15129
|
+
const allComments = [
|
|
15130
|
+
...path19.parentPath?.node?.leadingComments ?? [],
|
|
15131
|
+
...path19.node.leadingComments ?? [],
|
|
15132
|
+
...path19.node.trailingComments ?? []
|
|
15133
|
+
];
|
|
15134
|
+
registerDefinition(name, { node, filePath: currentFile }, allComments);
|
|
15010
15135
|
}
|
|
15011
15136
|
},
|
|
15012
15137
|
TSInterfaceDeclaration: (path19) => {
|
|
15013
15138
|
if (path19.node.id && t13.isIdentifier(path19.node.id)) {
|
|
15014
15139
|
const name = path19.node.id.name;
|
|
15015
|
-
|
|
15016
|
-
|
|
15017
|
-
|
|
15140
|
+
const allComments = [
|
|
15141
|
+
...path19.parentPath?.node?.leadingComments ?? [],
|
|
15142
|
+
...path19.node.leadingComments ?? [],
|
|
15143
|
+
...path19.node.trailingComments ?? [],
|
|
15144
|
+
...collectFirstMemberLeadingComments(path19.node)
|
|
15145
|
+
];
|
|
15146
|
+
registerDefinition(name, { node: path19.node, filePath: currentFile }, allComments);
|
|
15018
15147
|
}
|
|
15019
15148
|
},
|
|
15020
15149
|
TSEnumDeclaration: (path19) => {
|
|
15021
15150
|
if (path19.node.id && t13.isIdentifier(path19.node.id)) {
|
|
15022
15151
|
const name = path19.node.id.name;
|
|
15023
|
-
|
|
15024
|
-
|
|
15025
|
-
|
|
15152
|
+
const allComments = [
|
|
15153
|
+
...path19.parentPath?.node?.leadingComments ?? [],
|
|
15154
|
+
...path19.node.leadingComments ?? [],
|
|
15155
|
+
...path19.node.trailingComments ?? []
|
|
15156
|
+
];
|
|
15157
|
+
registerDefinition(name, { node: path19.node, filePath: currentFile }, allComments);
|
|
15026
15158
|
}
|
|
15027
15159
|
},
|
|
15028
15160
|
ExportNamedDeclaration: (path19) => {
|
|
@@ -15030,19 +15162,26 @@ function collectAllExportedDefinitions(ast, typeDefinitions, currentFile) {
|
|
|
15030
15162
|
const interfaceDecl = path19.node.declaration;
|
|
15031
15163
|
if (interfaceDecl.id && t13.isIdentifier(interfaceDecl.id)) {
|
|
15032
15164
|
const name = interfaceDecl.id.name;
|
|
15033
|
-
|
|
15034
|
-
|
|
15035
|
-
|
|
15165
|
+
const allComments = [
|
|
15166
|
+
...path19.node.leadingComments ?? [],
|
|
15167
|
+
...interfaceDecl.leadingComments ?? [],
|
|
15168
|
+
...interfaceDecl.trailingComments ?? [],
|
|
15169
|
+
...collectFirstMemberLeadingComments(interfaceDecl)
|
|
15170
|
+
];
|
|
15171
|
+
registerDefinition(name, { node: interfaceDecl, filePath: currentFile }, allComments);
|
|
15036
15172
|
}
|
|
15037
15173
|
}
|
|
15038
15174
|
if (t13.isTSTypeAliasDeclaration(path19.node.declaration)) {
|
|
15039
15175
|
const typeDecl = path19.node.declaration;
|
|
15040
15176
|
if (typeDecl.id && t13.isIdentifier(typeDecl.id)) {
|
|
15041
15177
|
const name = typeDecl.id.name;
|
|
15042
|
-
|
|
15043
|
-
|
|
15044
|
-
|
|
15045
|
-
|
|
15178
|
+
const node = typeDecl.typeParameters && typeDecl.typeParameters.params.length > 0 ? typeDecl : typeDecl.typeAnnotation;
|
|
15179
|
+
const allComments = [
|
|
15180
|
+
...path19.node.leadingComments ?? [],
|
|
15181
|
+
...typeDecl.leadingComments ?? [],
|
|
15182
|
+
...typeDecl.trailingComments ?? []
|
|
15183
|
+
];
|
|
15184
|
+
registerDefinition(name, { node, filePath: currentFile }, allComments);
|
|
15046
15185
|
}
|
|
15047
15186
|
}
|
|
15048
15187
|
}
|
|
@@ -15459,6 +15598,7 @@ var SchemaProcessor = class {
|
|
|
15459
15598
|
zodSchemaProcessor = null;
|
|
15460
15599
|
schemaTypes;
|
|
15461
15600
|
isResolvingPickOmitBase = false;
|
|
15601
|
+
schemaIdAliases = {};
|
|
15462
15602
|
fileAccess;
|
|
15463
15603
|
symbolResolver;
|
|
15464
15604
|
// Track imports per file for resolving ReturnType<typeof func>
|
|
@@ -15499,7 +15639,7 @@ var SchemaProcessor = class {
|
|
|
15499
15639
|
getDefinedSchemas() {
|
|
15500
15640
|
const filteredSchemas = {};
|
|
15501
15641
|
Object.entries(this.openapiDefinitions).forEach(([key, value]) => {
|
|
15502
|
-
if (!this.isGenericTypeParameter(key) && !this.isInvalidSchemaName(key) && !this.isBuiltInUtilityType(key) && !this.isFunctionSchema(key)) {
|
|
15642
|
+
if (!this.schemaIdAliases[key] && !this.isGenericTypeParameter(key) && !this.isInvalidSchemaName(key) && !this.isBuiltInUtilityType(key) && !this.isFunctionSchema(key)) {
|
|
15503
15643
|
filteredSchemas[key] = value;
|
|
15504
15644
|
}
|
|
15505
15645
|
});
|
|
@@ -15514,6 +15654,10 @@ var SchemaProcessor = class {
|
|
|
15514
15654
|
if (schemaName.includes("<") && schemaName.includes(">")) {
|
|
15515
15655
|
return this.resolveGenericTypeFromString(schemaName);
|
|
15516
15656
|
}
|
|
15657
|
+
const overrideId = this.schemaIdAliases[schemaName];
|
|
15658
|
+
if (overrideId) {
|
|
15659
|
+
return this.findSchemaDefinition(overrideId, contentType);
|
|
15660
|
+
}
|
|
15517
15661
|
if (this.openapiDefinitions[schemaName]) {
|
|
15518
15662
|
return this.openapiDefinitions[schemaName];
|
|
15519
15663
|
}
|
|
@@ -15595,6 +15739,7 @@ var SchemaProcessor = class {
|
|
|
15595
15739
|
return;
|
|
15596
15740
|
}
|
|
15597
15741
|
this.collectImports(ast, filePath);
|
|
15742
|
+
const aliasesBeforeFile = new Set(Object.keys(this.schemaIdAliases));
|
|
15598
15743
|
this.collectAllExportedDefinitions(ast, filePath);
|
|
15599
15744
|
collectTopLevelDefinitionNames(ast).forEach((name) => {
|
|
15600
15745
|
const indexedFiles = this.schemaDefinitionIndex[name];
|
|
@@ -15606,6 +15751,16 @@ var SchemaProcessor = class {
|
|
|
15606
15751
|
}
|
|
15607
15752
|
this.schemaDefinitionIndex[name] = [filePath];
|
|
15608
15753
|
});
|
|
15754
|
+
Object.entries(this.schemaIdAliases).forEach(([originalName, aliasName]) => {
|
|
15755
|
+
if (aliasesBeforeFile.has(originalName))
|
|
15756
|
+
return;
|
|
15757
|
+
if (!this.schemaDefinitionIndex[aliasName]) {
|
|
15758
|
+
this.schemaDefinitionIndex[aliasName] = [];
|
|
15759
|
+
}
|
|
15760
|
+
if (!this.schemaDefinitionIndex[aliasName].includes(filePath)) {
|
|
15761
|
+
this.schemaDefinitionIndex[aliasName].push(filePath);
|
|
15762
|
+
}
|
|
15763
|
+
});
|
|
15609
15764
|
}
|
|
15610
15765
|
getParsedSchemaFile(filePath) {
|
|
15611
15766
|
const cachedAst = this.fileASTCache.get(filePath);
|
|
@@ -15644,7 +15799,7 @@ var SchemaProcessor = class {
|
|
|
15644
15799
|
* Used when processing imported files to ensure all referenced types are available
|
|
15645
15800
|
*/
|
|
15646
15801
|
collectAllExportedDefinitions(ast, filePath) {
|
|
15647
|
-
collectAllExportedDefinitions(ast, this.typeDefinitions, filePath || this.currentFilePath);
|
|
15802
|
+
collectAllExportedDefinitions(ast, this.typeDefinitions, filePath || this.currentFilePath, this.schemaIdAliases);
|
|
15648
15803
|
}
|
|
15649
15804
|
collectTypeDefinitions(ast, schemaName, filePath) {
|
|
15650
15805
|
collectTypeDefinitions(ast, schemaName, this.typeDefinitions, filePath || this.currentFilePath);
|
|
@@ -16241,6 +16396,9 @@ var SchemaProcessor = class {
|
|
|
16241
16396
|
logger.debug(`Record<...> used with ${node.typeParameters?.params.length ?? 0} type parameters; expected 2`);
|
|
16242
16397
|
return { type: "object", additionalProperties: true };
|
|
16243
16398
|
}
|
|
16399
|
+
if ((!node.typeParameters || node.typeParameters.params.length === 0) && this.schemaIdAliases[typeName] && this.openapiDefinitions[this.schemaIdAliases[typeName]]) {
|
|
16400
|
+
return { $ref: `#/components/schemas/${this.schemaIdAliases[typeName]}` };
|
|
16401
|
+
}
|
|
16244
16402
|
const utilityType = resolveUtilityTypeReference(node, {
|
|
16245
16403
|
currentFilePath: this.currentFilePath,
|
|
16246
16404
|
contentType: this.contentType,
|
|
@@ -16416,7 +16574,9 @@ var SchemaProcessor = class {
|
|
|
16416
16574
|
};
|
|
16417
16575
|
}
|
|
16418
16576
|
if (t16.isTSTypeReference(node) && t16.isIdentifier(node.typeName)) {
|
|
16419
|
-
|
|
16577
|
+
const refName = node.typeName.name;
|
|
16578
|
+
const aliasedName = this.schemaIdAliases[refName] ?? refName;
|
|
16579
|
+
return { $ref: `#/components/schemas/${aliasedName}` };
|
|
16420
16580
|
}
|
|
16421
16581
|
logger.debug("Unrecognized TypeScript type node:", node);
|
|
16422
16582
|
return { type: "object" };
|
|
@@ -16557,7 +16717,8 @@ var SchemaProcessor = class {
|
|
|
16557
16717
|
if (this.schemaTypes.includes("zod") && this.zodSchemaConverter) {
|
|
16558
16718
|
return this.zodSchemaConverter.getSchemaReferenceName(baseTypeName, contentType);
|
|
16559
16719
|
}
|
|
16560
|
-
|
|
16720
|
+
const aliasedName = this.schemaIdAliases[baseTypeName] ?? baseTypeName;
|
|
16721
|
+
return aliasedName;
|
|
16561
16722
|
}
|
|
16562
16723
|
/**
|
|
16563
16724
|
* Parse and resolve a generic type from a string like "MyApiSuccessResponseBody<LLMSResponse>"
|