next-openapi-gen 1.2.1 → 1.2.3
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 +216 -36
- package/dist/index.js +216 -36
- package/dist/next/index.js +216 -36
- package/dist/react-router/index.js +216 -36
- package/dist/vite/index.js +216 -36
- 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":
|
|
@@ -12710,6 +12725,9 @@ var ZodSchemaConverter = class {
|
|
|
12710
12725
|
schemaNameToFiles = /* @__PURE__ */ new Map();
|
|
12711
12726
|
/** Per-file import alias for the `zod` module (`import { z as zod }` sets this to `"zod"`). */
|
|
12712
12727
|
zodImportAlias = /* @__PURE__ */ new Map();
|
|
12728
|
+
/** Schema variable names whose component name was overridden via .meta({ id }). These must
|
|
12729
|
+
* NOT be copied back under the original variable name in the OpenAPI components object. */
|
|
12730
|
+
metaIdSchemaNames = /* @__PURE__ */ new Set();
|
|
12713
12731
|
// Current processing context (set during file processing)
|
|
12714
12732
|
currentFilePath;
|
|
12715
12733
|
currentAST;
|
|
@@ -12736,7 +12754,14 @@ var ZodSchemaConverter = class {
|
|
|
12736
12754
|
}
|
|
12737
12755
|
logger.debug(`Looking for Zod schema: ${schemaName}`);
|
|
12738
12756
|
const requestedSchemaName = schemaName;
|
|
12739
|
-
|
|
12757
|
+
let mappedSchemaName = this.typeToSchemaMapping[schemaName];
|
|
12758
|
+
if (!mappedSchemaName) {
|
|
12759
|
+
const candidate = this.deriveSchemaNameByConvention(schemaName);
|
|
12760
|
+
if (candidate && this.locateSchemaByConvention(candidate)) {
|
|
12761
|
+
this.typeToSchemaMapping[schemaName] = candidate;
|
|
12762
|
+
mappedSchemaName = candidate;
|
|
12763
|
+
}
|
|
12764
|
+
}
|
|
12740
12765
|
if (mappedSchemaName) {
|
|
12741
12766
|
logger.debug(`Type '${schemaName}' is mapped to schema '${mappedSchemaName}'`);
|
|
12742
12767
|
schemaName = mappedSchemaName;
|
|
@@ -12786,7 +12811,7 @@ var ZodSchemaConverter = class {
|
|
|
12786
12811
|
this.processingSchemas.delete(schemaName);
|
|
12787
12812
|
if (mappedSchemaName && requestedSchemaName !== schemaName) {
|
|
12788
12813
|
const resolvedReference = this.getSchemaReferenceName(schemaName, this.currentContentType);
|
|
12789
|
-
if (this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
12814
|
+
if (!this.metaIdSchemaNames.has(requestedSchemaName) && this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
12790
12815
|
this.zodSchemas[requestedSchemaName] = this.zodSchemas[resolvedReference];
|
|
12791
12816
|
}
|
|
12792
12817
|
this.schemaVariantRefs.set(this.getVariantKey(requestedSchemaName, this.currentContentType), this.zodSchemas[requestedSchemaName] ? requestedSchemaName : resolvedReference);
|
|
@@ -13243,6 +13268,8 @@ var ZodSchemaConverter = class {
|
|
|
13243
13268
|
try {
|
|
13244
13269
|
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
13245
13270
|
const ast = parseTypeScriptFile(content);
|
|
13271
|
+
this.currentFilePath = filePath;
|
|
13272
|
+
this.currentAST = ast;
|
|
13246
13273
|
resolvedTraverse(ast, {
|
|
13247
13274
|
ExportNamedDeclaration: (path19) => {
|
|
13248
13275
|
if (t11.isVariableDeclaration(path19.node.declaration)) {
|
|
@@ -13257,6 +13284,17 @@ var ZodSchemaConverter = class {
|
|
|
13257
13284
|
}
|
|
13258
13285
|
this.processingSchemas.delete(schemaName);
|
|
13259
13286
|
}
|
|
13287
|
+
} else if (t11.isIdentifier(declaration.id) && declaration.init) {
|
|
13288
|
+
const schemaName = declaration.id.name;
|
|
13289
|
+
const overrideId = this.extractMetaIdFromNode(declaration.init);
|
|
13290
|
+
if (overrideId && !this.getStoredSchema(schemaName) && !this.processingSchemas.has(schemaName)) {
|
|
13291
|
+
this.processingSchemas.add(schemaName);
|
|
13292
|
+
const schema = this.processZodNode(declaration.init);
|
|
13293
|
+
this.processingSchemas.delete(schemaName);
|
|
13294
|
+
if (schema) {
|
|
13295
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
13296
|
+
}
|
|
13297
|
+
}
|
|
13260
13298
|
}
|
|
13261
13299
|
});
|
|
13262
13300
|
}
|
|
@@ -13810,6 +13848,24 @@ var ZodSchemaConverter = class {
|
|
|
13810
13848
|
}
|
|
13811
13849
|
return void 0;
|
|
13812
13850
|
}
|
|
13851
|
+
extractMetaIdFromNode(node) {
|
|
13852
|
+
if (!t11.isCallExpression(node))
|
|
13853
|
+
return null;
|
|
13854
|
+
if (t11.isMemberExpression(node.callee) && t11.isIdentifier(node.callee.property)) {
|
|
13855
|
+
if (node.callee.property.name === "meta" && node.arguments.length > 0) {
|
|
13856
|
+
const metadata = this.extractStaticJsonValue(node.arguments[0]);
|
|
13857
|
+
if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
13858
|
+
const id = metadata.id;
|
|
13859
|
+
if (typeof id === "string" && id.length > 0)
|
|
13860
|
+
return id;
|
|
13861
|
+
}
|
|
13862
|
+
}
|
|
13863
|
+
if (t11.isCallExpression(node.callee.object)) {
|
|
13864
|
+
return this.extractMetaIdFromNode(node.callee.object);
|
|
13865
|
+
}
|
|
13866
|
+
}
|
|
13867
|
+
return null;
|
|
13868
|
+
}
|
|
13813
13869
|
shouldUseRuntimeExport(node) {
|
|
13814
13870
|
if (!t11.isCallExpression(node)) {
|
|
13815
13871
|
return false;
|
|
@@ -14050,7 +14106,8 @@ var ZodSchemaConverter = class {
|
|
|
14050
14106
|
if (node.arguments.length > 0) {
|
|
14051
14107
|
const metadata = this.extractStaticJsonValue(node.arguments[0]);
|
|
14052
14108
|
if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
14053
|
-
|
|
14109
|
+
const { id: _id, ...rest } = metadata;
|
|
14110
|
+
Object.assign(schema, rest);
|
|
14054
14111
|
}
|
|
14055
14112
|
}
|
|
14056
14113
|
break;
|
|
@@ -14336,6 +14393,7 @@ var ZodSchemaConverter = class {
|
|
|
14336
14393
|
this.currentFilePath = filePath;
|
|
14337
14394
|
this.currentAST = ast;
|
|
14338
14395
|
this.currentImports = importedModules;
|
|
14396
|
+
this.preprocessedFiles.add(filePath);
|
|
14339
14397
|
resolvedTraverse(ast, {
|
|
14340
14398
|
ExportNamedDeclaration: (path19) => {
|
|
14341
14399
|
if (t11.isVariableDeclaration(path19.node.declaration)) {
|
|
@@ -14343,15 +14401,19 @@ var ZodSchemaConverter = class {
|
|
|
14343
14401
|
if (t11.isIdentifier(declaration.id) && declaration.init) {
|
|
14344
14402
|
const schemaName = declaration.id.name;
|
|
14345
14403
|
if (this.isZodSchema(declaration.init)) {
|
|
14346
|
-
this.indexSchemaName(schemaName, filePath);
|
|
14347
14404
|
if (!this.getStoredSchema(schemaName)) {
|
|
14348
14405
|
logger.debug(`Pre-processing Zod schema: ${schemaName}`);
|
|
14349
14406
|
this.processingSchemas.add(schemaName);
|
|
14350
14407
|
const schema = this.processZodNode(declaration.init);
|
|
14408
|
+
this.processingSchemas.delete(schemaName);
|
|
14351
14409
|
if (schema) {
|
|
14352
|
-
this.
|
|
14410
|
+
const overrideId = this.extractMetaIdFromNode(declaration.init);
|
|
14411
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
14412
|
+
} else {
|
|
14413
|
+
this.indexSchemaName(schemaName, filePath);
|
|
14353
14414
|
}
|
|
14354
|
-
|
|
14415
|
+
} else {
|
|
14416
|
+
this.indexSchemaName(schemaName, filePath);
|
|
14355
14417
|
}
|
|
14356
14418
|
}
|
|
14357
14419
|
}
|
|
@@ -14364,22 +14426,25 @@ var ZodSchemaConverter = class {
|
|
|
14364
14426
|
if (t11.isIdentifier(declaration.id) && declaration.init) {
|
|
14365
14427
|
const schemaName = declaration.id.name;
|
|
14366
14428
|
if (this.isZodSchema(declaration.init)) {
|
|
14367
|
-
this.indexSchemaName(schemaName, filePath);
|
|
14368
14429
|
if (!this.getStoredSchema(schemaName) && !this.processingSchemas.has(schemaName)) {
|
|
14369
14430
|
logger.debug(`Pre-processing Zod schema: ${schemaName}`);
|
|
14370
14431
|
this.processingSchemas.add(schemaName);
|
|
14371
14432
|
const schema = this.processZodNode(declaration.init);
|
|
14433
|
+
this.processingSchemas.delete(schemaName);
|
|
14372
14434
|
if (schema) {
|
|
14373
|
-
this.
|
|
14435
|
+
const overrideId = this.extractMetaIdFromNode(declaration.init);
|
|
14436
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
14437
|
+
} else {
|
|
14438
|
+
this.indexSchemaName(schemaName, filePath);
|
|
14374
14439
|
}
|
|
14375
|
-
|
|
14440
|
+
} else {
|
|
14441
|
+
this.indexSchemaName(schemaName, filePath);
|
|
14376
14442
|
}
|
|
14377
14443
|
}
|
|
14378
14444
|
}
|
|
14379
14445
|
});
|
|
14380
14446
|
}
|
|
14381
14447
|
});
|
|
14382
|
-
this.preprocessedFiles.add(filePath);
|
|
14383
14448
|
} catch (error2) {
|
|
14384
14449
|
logger.error(`Error pre-processing file ${filePath}: ${error2}`);
|
|
14385
14450
|
}
|
|
@@ -14397,6 +14462,63 @@ var ZodSchemaConverter = class {
|
|
|
14397
14462
|
}
|
|
14398
14463
|
bucket.add(filePath);
|
|
14399
14464
|
}
|
|
14465
|
+
applyMetaIdOverride(schemaName, schema, overrideId, filePath) {
|
|
14466
|
+
const finalName = overrideId && overrideId !== schemaName ? overrideId : schemaName;
|
|
14467
|
+
this.indexSchemaName(schemaName, filePath);
|
|
14468
|
+
if (finalName !== schemaName) {
|
|
14469
|
+
this.indexSchemaName(finalName, filePath);
|
|
14470
|
+
}
|
|
14471
|
+
if (!this.zodSchemas[finalName]) {
|
|
14472
|
+
if (overrideId && overrideId !== schemaName) {
|
|
14473
|
+
this.typeToSchemaMapping[schemaName] = overrideId;
|
|
14474
|
+
this.metaIdSchemaNames.add(schemaName);
|
|
14475
|
+
if (this.typeToSchemaMapping[overrideId] === schemaName) {
|
|
14476
|
+
delete this.typeToSchemaMapping[overrideId];
|
|
14477
|
+
}
|
|
14478
|
+
}
|
|
14479
|
+
const variantKey = this.getVariantKey(finalName, this.currentContentType);
|
|
14480
|
+
this.zodSchemas[finalName] = schema;
|
|
14481
|
+
this.schemaVariantRefs.set(variantKey, finalName);
|
|
14482
|
+
} else {
|
|
14483
|
+
logger.warn(`Schema component name '${overrideId ?? finalName}' conflicts with an existing schema, ignoring .meta({ id }) on '${schemaName}'`);
|
|
14484
|
+
}
|
|
14485
|
+
}
|
|
14486
|
+
/**
|
|
14487
|
+
* Derives the conventional Zod schema name from a TypeScript type name.
|
|
14488
|
+
* e.g. "Slider" → "sliderSchema", "SliderItem" → "sliderItemSchema".
|
|
14489
|
+
* Returns null when the input is already a schema name or is not PascalCase.
|
|
14490
|
+
*/
|
|
14491
|
+
deriveSchemaNameByConvention(typeName) {
|
|
14492
|
+
if (!typeName || !/^[A-Z]/.test(typeName) || typeName.endsWith("Schema")) {
|
|
14493
|
+
return null;
|
|
14494
|
+
}
|
|
14495
|
+
return typeName[0].toLowerCase() + typeName.slice(1) + "Schema";
|
|
14496
|
+
}
|
|
14497
|
+
/**
|
|
14498
|
+
* Checks whether a Zod schema with the given name is present in schemaDirs
|
|
14499
|
+
* WITHOUT populating the processed-schema cache. A file-content substring check
|
|
14500
|
+
* (the same heuristic used by processFileForZodSchema) is sufficient here: we
|
|
14501
|
+
* only want to know whether the candidate *might* live in schemaDirs so that the
|
|
14502
|
+
* convention mapping can be registered; the actual processing happens later in
|
|
14503
|
+
* the normal convertZodSchemaToOpenApi lookup flow.
|
|
14504
|
+
*/
|
|
14505
|
+
locateSchemaByConvention(candidate) {
|
|
14506
|
+
if (this.schemaNameToFiles.has(candidate)) {
|
|
14507
|
+
return true;
|
|
14508
|
+
}
|
|
14509
|
+
for (const dir of this.schemaDirs) {
|
|
14510
|
+
for (const filePath of this.getSchemaFiles(dir)) {
|
|
14511
|
+
try {
|
|
14512
|
+
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
14513
|
+
if (content.includes(candidate)) {
|
|
14514
|
+
return true;
|
|
14515
|
+
}
|
|
14516
|
+
} catch {
|
|
14517
|
+
}
|
|
14518
|
+
}
|
|
14519
|
+
}
|
|
14520
|
+
return false;
|
|
14521
|
+
}
|
|
14400
14522
|
/**
|
|
14401
14523
|
* Check if node is Zod schema
|
|
14402
14524
|
*/
|
|
@@ -14628,7 +14750,7 @@ function parsePropertyComment(commentValue) {
|
|
|
14628
14750
|
function getPropertyOptions(node, contentType) {
|
|
14629
14751
|
const isOptional = !!node.optional;
|
|
14630
14752
|
const options = {};
|
|
14631
|
-
const leadingComment = node.leadingComments?.
|
|
14753
|
+
const leadingComment = node.leadingComments?.findLast((c) => c.type === "CommentBlock" || !node.trailingComments?.length);
|
|
14632
14754
|
const trailingComment = node.trailingComments?.[0];
|
|
14633
14755
|
const sourceComment = leadingComment ?? trailingComment;
|
|
14634
14756
|
if (sourceComment) {
|
|
@@ -15031,31 +15153,60 @@ function resolveImportPath(importPath, fromFilePath, fileAccess) {
|
|
|
15031
15153
|
}
|
|
15032
15154
|
return null;
|
|
15033
15155
|
}
|
|
15034
|
-
function
|
|
15156
|
+
function collectFirstMemberLeadingComments(interfaceDecl) {
|
|
15157
|
+
const body = interfaceDecl?.body;
|
|
15158
|
+
if (!body)
|
|
15159
|
+
return [];
|
|
15160
|
+
const firstMember = body.body?.[0];
|
|
15161
|
+
return firstMember?.leadingComments ?? [];
|
|
15162
|
+
}
|
|
15163
|
+
function collectAllExportedDefinitions(ast, typeDefinitions, currentFile, schemaIdAliases) {
|
|
15164
|
+
function registerDefinition(name, entry, allComments) {
|
|
15165
|
+
if (!typeDefinitions[name]) {
|
|
15166
|
+
typeDefinitions[name] = entry;
|
|
15167
|
+
}
|
|
15168
|
+
const overrideId = extractSchemaIdFromComments(allComments);
|
|
15169
|
+
if (overrideId && schemaIdAliases) {
|
|
15170
|
+
schemaIdAliases[name] = overrideId;
|
|
15171
|
+
if (!typeDefinitions[overrideId]) {
|
|
15172
|
+
typeDefinitions[overrideId] = entry;
|
|
15173
|
+
}
|
|
15174
|
+
}
|
|
15175
|
+
}
|
|
15035
15176
|
resolvedTraverse(ast, {
|
|
15036
15177
|
TSTypeAliasDeclaration: (path19) => {
|
|
15037
15178
|
if (path19.node.id && t13.isIdentifier(path19.node.id)) {
|
|
15038
15179
|
const name = path19.node.id.name;
|
|
15039
|
-
|
|
15040
|
-
|
|
15041
|
-
|
|
15042
|
-
|
|
15180
|
+
const node = path19.node.typeParameters && path19.node.typeParameters.params.length > 0 ? path19.node : path19.node.typeAnnotation;
|
|
15181
|
+
const allComments = [
|
|
15182
|
+
...path19.parentPath?.node?.leadingComments ?? [],
|
|
15183
|
+
...path19.node.leadingComments ?? [],
|
|
15184
|
+
...path19.node.trailingComments ?? []
|
|
15185
|
+
];
|
|
15186
|
+
registerDefinition(name, { node, filePath: currentFile }, allComments);
|
|
15043
15187
|
}
|
|
15044
15188
|
},
|
|
15045
15189
|
TSInterfaceDeclaration: (path19) => {
|
|
15046
15190
|
if (path19.node.id && t13.isIdentifier(path19.node.id)) {
|
|
15047
15191
|
const name = path19.node.id.name;
|
|
15048
|
-
|
|
15049
|
-
|
|
15050
|
-
|
|
15192
|
+
const allComments = [
|
|
15193
|
+
...path19.parentPath?.node?.leadingComments ?? [],
|
|
15194
|
+
...path19.node.leadingComments ?? [],
|
|
15195
|
+
...path19.node.trailingComments ?? [],
|
|
15196
|
+
...collectFirstMemberLeadingComments(path19.node)
|
|
15197
|
+
];
|
|
15198
|
+
registerDefinition(name, { node: path19.node, filePath: currentFile }, allComments);
|
|
15051
15199
|
}
|
|
15052
15200
|
},
|
|
15053
15201
|
TSEnumDeclaration: (path19) => {
|
|
15054
15202
|
if (path19.node.id && t13.isIdentifier(path19.node.id)) {
|
|
15055
15203
|
const name = path19.node.id.name;
|
|
15056
|
-
|
|
15057
|
-
|
|
15058
|
-
|
|
15204
|
+
const allComments = [
|
|
15205
|
+
...path19.parentPath?.node?.leadingComments ?? [],
|
|
15206
|
+
...path19.node.leadingComments ?? [],
|
|
15207
|
+
...path19.node.trailingComments ?? []
|
|
15208
|
+
];
|
|
15209
|
+
registerDefinition(name, { node: path19.node, filePath: currentFile }, allComments);
|
|
15059
15210
|
}
|
|
15060
15211
|
},
|
|
15061
15212
|
ExportNamedDeclaration: (path19) => {
|
|
@@ -15063,19 +15214,26 @@ function collectAllExportedDefinitions(ast, typeDefinitions, currentFile) {
|
|
|
15063
15214
|
const interfaceDecl = path19.node.declaration;
|
|
15064
15215
|
if (interfaceDecl.id && t13.isIdentifier(interfaceDecl.id)) {
|
|
15065
15216
|
const name = interfaceDecl.id.name;
|
|
15066
|
-
|
|
15067
|
-
|
|
15068
|
-
|
|
15217
|
+
const allComments = [
|
|
15218
|
+
...path19.node.leadingComments ?? [],
|
|
15219
|
+
...interfaceDecl.leadingComments ?? [],
|
|
15220
|
+
...interfaceDecl.trailingComments ?? [],
|
|
15221
|
+
...collectFirstMemberLeadingComments(interfaceDecl)
|
|
15222
|
+
];
|
|
15223
|
+
registerDefinition(name, { node: interfaceDecl, filePath: currentFile }, allComments);
|
|
15069
15224
|
}
|
|
15070
15225
|
}
|
|
15071
15226
|
if (t13.isTSTypeAliasDeclaration(path19.node.declaration)) {
|
|
15072
15227
|
const typeDecl = path19.node.declaration;
|
|
15073
15228
|
if (typeDecl.id && t13.isIdentifier(typeDecl.id)) {
|
|
15074
15229
|
const name = typeDecl.id.name;
|
|
15075
|
-
|
|
15076
|
-
|
|
15077
|
-
|
|
15078
|
-
|
|
15230
|
+
const node = typeDecl.typeParameters && typeDecl.typeParameters.params.length > 0 ? typeDecl : typeDecl.typeAnnotation;
|
|
15231
|
+
const allComments = [
|
|
15232
|
+
...path19.node.leadingComments ?? [],
|
|
15233
|
+
...typeDecl.leadingComments ?? [],
|
|
15234
|
+
...typeDecl.trailingComments ?? []
|
|
15235
|
+
];
|
|
15236
|
+
registerDefinition(name, { node, filePath: currentFile }, allComments);
|
|
15079
15237
|
}
|
|
15080
15238
|
}
|
|
15081
15239
|
}
|
|
@@ -15492,6 +15650,7 @@ var SchemaProcessor = class {
|
|
|
15492
15650
|
zodSchemaProcessor = null;
|
|
15493
15651
|
schemaTypes;
|
|
15494
15652
|
isResolvingPickOmitBase = false;
|
|
15653
|
+
schemaIdAliases = {};
|
|
15495
15654
|
fileAccess;
|
|
15496
15655
|
symbolResolver;
|
|
15497
15656
|
// Track imports per file for resolving ReturnType<typeof func>
|
|
@@ -15532,7 +15691,7 @@ var SchemaProcessor = class {
|
|
|
15532
15691
|
getDefinedSchemas() {
|
|
15533
15692
|
const filteredSchemas = {};
|
|
15534
15693
|
Object.entries(this.openapiDefinitions).forEach(([key, value]) => {
|
|
15535
|
-
if (!this.isGenericTypeParameter(key) && !this.isInvalidSchemaName(key) && !this.isBuiltInUtilityType(key) && !this.isFunctionSchema(key)) {
|
|
15694
|
+
if (!this.schemaIdAliases[key] && !this.isGenericTypeParameter(key) && !this.isInvalidSchemaName(key) && !this.isBuiltInUtilityType(key) && !this.isFunctionSchema(key)) {
|
|
15536
15695
|
filteredSchemas[key] = value;
|
|
15537
15696
|
}
|
|
15538
15697
|
});
|
|
@@ -15547,6 +15706,10 @@ var SchemaProcessor = class {
|
|
|
15547
15706
|
if (schemaName.includes("<") && schemaName.includes(">")) {
|
|
15548
15707
|
return this.resolveGenericTypeFromString(schemaName);
|
|
15549
15708
|
}
|
|
15709
|
+
const overrideId = this.schemaIdAliases[schemaName];
|
|
15710
|
+
if (overrideId) {
|
|
15711
|
+
return this.findSchemaDefinition(overrideId, contentType);
|
|
15712
|
+
}
|
|
15550
15713
|
if (this.openapiDefinitions[schemaName]) {
|
|
15551
15714
|
return this.openapiDefinitions[schemaName];
|
|
15552
15715
|
}
|
|
@@ -15628,6 +15791,7 @@ var SchemaProcessor = class {
|
|
|
15628
15791
|
return;
|
|
15629
15792
|
}
|
|
15630
15793
|
this.collectImports(ast, filePath);
|
|
15794
|
+
const aliasesBeforeFile = new Set(Object.keys(this.schemaIdAliases));
|
|
15631
15795
|
this.collectAllExportedDefinitions(ast, filePath);
|
|
15632
15796
|
collectTopLevelDefinitionNames(ast).forEach((name) => {
|
|
15633
15797
|
const indexedFiles = this.schemaDefinitionIndex[name];
|
|
@@ -15639,6 +15803,16 @@ var SchemaProcessor = class {
|
|
|
15639
15803
|
}
|
|
15640
15804
|
this.schemaDefinitionIndex[name] = [filePath];
|
|
15641
15805
|
});
|
|
15806
|
+
Object.entries(this.schemaIdAliases).forEach(([originalName, aliasName]) => {
|
|
15807
|
+
if (aliasesBeforeFile.has(originalName))
|
|
15808
|
+
return;
|
|
15809
|
+
if (!this.schemaDefinitionIndex[aliasName]) {
|
|
15810
|
+
this.schemaDefinitionIndex[aliasName] = [];
|
|
15811
|
+
}
|
|
15812
|
+
if (!this.schemaDefinitionIndex[aliasName].includes(filePath)) {
|
|
15813
|
+
this.schemaDefinitionIndex[aliasName].push(filePath);
|
|
15814
|
+
}
|
|
15815
|
+
});
|
|
15642
15816
|
}
|
|
15643
15817
|
getParsedSchemaFile(filePath) {
|
|
15644
15818
|
const cachedAst = this.fileASTCache.get(filePath);
|
|
@@ -15677,7 +15851,7 @@ var SchemaProcessor = class {
|
|
|
15677
15851
|
* Used when processing imported files to ensure all referenced types are available
|
|
15678
15852
|
*/
|
|
15679
15853
|
collectAllExportedDefinitions(ast, filePath) {
|
|
15680
|
-
collectAllExportedDefinitions(ast, this.typeDefinitions, filePath || this.currentFilePath);
|
|
15854
|
+
collectAllExportedDefinitions(ast, this.typeDefinitions, filePath || this.currentFilePath, this.schemaIdAliases);
|
|
15681
15855
|
}
|
|
15682
15856
|
collectTypeDefinitions(ast, schemaName, filePath) {
|
|
15683
15857
|
collectTypeDefinitions(ast, schemaName, this.typeDefinitions, filePath || this.currentFilePath);
|
|
@@ -16274,6 +16448,9 @@ var SchemaProcessor = class {
|
|
|
16274
16448
|
logger.debug(`Record<...> used with ${node.typeParameters?.params.length ?? 0} type parameters; expected 2`);
|
|
16275
16449
|
return { type: "object", additionalProperties: true };
|
|
16276
16450
|
}
|
|
16451
|
+
if ((!node.typeParameters || node.typeParameters.params.length === 0) && this.schemaIdAliases[typeName] && this.openapiDefinitions[this.schemaIdAliases[typeName]]) {
|
|
16452
|
+
return { $ref: `#/components/schemas/${this.schemaIdAliases[typeName]}` };
|
|
16453
|
+
}
|
|
16277
16454
|
const utilityType = resolveUtilityTypeReference(node, {
|
|
16278
16455
|
currentFilePath: this.currentFilePath,
|
|
16279
16456
|
contentType: this.contentType,
|
|
@@ -16449,7 +16626,9 @@ var SchemaProcessor = class {
|
|
|
16449
16626
|
};
|
|
16450
16627
|
}
|
|
16451
16628
|
if (t16.isTSTypeReference(node) && t16.isIdentifier(node.typeName)) {
|
|
16452
|
-
|
|
16629
|
+
const refName = node.typeName.name;
|
|
16630
|
+
const aliasedName = this.schemaIdAliases[refName] ?? refName;
|
|
16631
|
+
return { $ref: `#/components/schemas/${aliasedName}` };
|
|
16453
16632
|
}
|
|
16454
16633
|
logger.debug("Unrecognized TypeScript type node:", node);
|
|
16455
16634
|
return { type: "object" };
|
|
@@ -16590,7 +16769,8 @@ var SchemaProcessor = class {
|
|
|
16590
16769
|
if (this.schemaTypes.includes("zod") && this.zodSchemaConverter) {
|
|
16591
16770
|
return this.zodSchemaConverter.getSchemaReferenceName(baseTypeName, contentType);
|
|
16592
16771
|
}
|
|
16593
|
-
|
|
16772
|
+
const aliasedName = this.schemaIdAliases[baseTypeName] ?? baseTypeName;
|
|
16773
|
+
return aliasedName;
|
|
16594
16774
|
}
|
|
16595
16775
|
/**
|
|
16596
16776
|
* Parse and resolve a generic type from a string like "MyApiSuccessResponseBody<LLMSResponse>"
|