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/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":
|
|
@@ -11676,6 +11691,9 @@ var ZodSchemaConverter = class {
|
|
|
11676
11691
|
schemaNameToFiles = /* @__PURE__ */ new Map();
|
|
11677
11692
|
/** Per-file import alias for the `zod` module (`import { z as zod }` sets this to `"zod"`). */
|
|
11678
11693
|
zodImportAlias = /* @__PURE__ */ new Map();
|
|
11694
|
+
/** Schema variable names whose component name was overridden via .meta({ id }). These must
|
|
11695
|
+
* NOT be copied back under the original variable name in the OpenAPI components object. */
|
|
11696
|
+
metaIdSchemaNames = /* @__PURE__ */ new Set();
|
|
11679
11697
|
// Current processing context (set during file processing)
|
|
11680
11698
|
currentFilePath;
|
|
11681
11699
|
currentAST;
|
|
@@ -11702,7 +11720,14 @@ var ZodSchemaConverter = class {
|
|
|
11702
11720
|
}
|
|
11703
11721
|
logger.debug(`Looking for Zod schema: ${schemaName}`);
|
|
11704
11722
|
const requestedSchemaName = schemaName;
|
|
11705
|
-
|
|
11723
|
+
let mappedSchemaName = this.typeToSchemaMapping[schemaName];
|
|
11724
|
+
if (!mappedSchemaName) {
|
|
11725
|
+
const candidate = this.deriveSchemaNameByConvention(schemaName);
|
|
11726
|
+
if (candidate && this.locateSchemaByConvention(candidate)) {
|
|
11727
|
+
this.typeToSchemaMapping[schemaName] = candidate;
|
|
11728
|
+
mappedSchemaName = candidate;
|
|
11729
|
+
}
|
|
11730
|
+
}
|
|
11706
11731
|
if (mappedSchemaName) {
|
|
11707
11732
|
logger.debug(`Type '${schemaName}' is mapped to schema '${mappedSchemaName}'`);
|
|
11708
11733
|
schemaName = mappedSchemaName;
|
|
@@ -11752,7 +11777,7 @@ var ZodSchemaConverter = class {
|
|
|
11752
11777
|
this.processingSchemas.delete(schemaName);
|
|
11753
11778
|
if (mappedSchemaName && requestedSchemaName !== schemaName) {
|
|
11754
11779
|
const resolvedReference = this.getSchemaReferenceName(schemaName, this.currentContentType);
|
|
11755
|
-
if (this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
11780
|
+
if (!this.metaIdSchemaNames.has(requestedSchemaName) && this.zodSchemas[resolvedReference] && !this.zodSchemas[requestedSchemaName]) {
|
|
11756
11781
|
this.zodSchemas[requestedSchemaName] = this.zodSchemas[resolvedReference];
|
|
11757
11782
|
}
|
|
11758
11783
|
this.schemaVariantRefs.set(this.getVariantKey(requestedSchemaName, this.currentContentType), this.zodSchemas[requestedSchemaName] ? requestedSchemaName : resolvedReference);
|
|
@@ -12209,6 +12234,8 @@ var ZodSchemaConverter = class {
|
|
|
12209
12234
|
try {
|
|
12210
12235
|
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
12211
12236
|
const ast = parseTypeScriptFile(content);
|
|
12237
|
+
this.currentFilePath = filePath;
|
|
12238
|
+
this.currentAST = ast;
|
|
12212
12239
|
resolvedTraverse(ast, {
|
|
12213
12240
|
ExportNamedDeclaration: (path25) => {
|
|
12214
12241
|
if (t10.isVariableDeclaration(path25.node.declaration)) {
|
|
@@ -12223,6 +12250,17 @@ var ZodSchemaConverter = class {
|
|
|
12223
12250
|
}
|
|
12224
12251
|
this.processingSchemas.delete(schemaName);
|
|
12225
12252
|
}
|
|
12253
|
+
} else if (t10.isIdentifier(declaration.id) && declaration.init) {
|
|
12254
|
+
const schemaName = declaration.id.name;
|
|
12255
|
+
const overrideId = this.extractMetaIdFromNode(declaration.init);
|
|
12256
|
+
if (overrideId && !this.getStoredSchema(schemaName) && !this.processingSchemas.has(schemaName)) {
|
|
12257
|
+
this.processingSchemas.add(schemaName);
|
|
12258
|
+
const schema = this.processZodNode(declaration.init);
|
|
12259
|
+
this.processingSchemas.delete(schemaName);
|
|
12260
|
+
if (schema) {
|
|
12261
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
12262
|
+
}
|
|
12263
|
+
}
|
|
12226
12264
|
}
|
|
12227
12265
|
});
|
|
12228
12266
|
}
|
|
@@ -12776,6 +12814,24 @@ var ZodSchemaConverter = class {
|
|
|
12776
12814
|
}
|
|
12777
12815
|
return void 0;
|
|
12778
12816
|
}
|
|
12817
|
+
extractMetaIdFromNode(node) {
|
|
12818
|
+
if (!t10.isCallExpression(node))
|
|
12819
|
+
return null;
|
|
12820
|
+
if (t10.isMemberExpression(node.callee) && t10.isIdentifier(node.callee.property)) {
|
|
12821
|
+
if (node.callee.property.name === "meta" && node.arguments.length > 0) {
|
|
12822
|
+
const metadata = this.extractStaticJsonValue(node.arguments[0]);
|
|
12823
|
+
if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
12824
|
+
const id = metadata.id;
|
|
12825
|
+
if (typeof id === "string" && id.length > 0)
|
|
12826
|
+
return id;
|
|
12827
|
+
}
|
|
12828
|
+
}
|
|
12829
|
+
if (t10.isCallExpression(node.callee.object)) {
|
|
12830
|
+
return this.extractMetaIdFromNode(node.callee.object);
|
|
12831
|
+
}
|
|
12832
|
+
}
|
|
12833
|
+
return null;
|
|
12834
|
+
}
|
|
12779
12835
|
shouldUseRuntimeExport(node) {
|
|
12780
12836
|
if (!t10.isCallExpression(node)) {
|
|
12781
12837
|
return false;
|
|
@@ -13016,7 +13072,8 @@ var ZodSchemaConverter = class {
|
|
|
13016
13072
|
if (node.arguments.length > 0) {
|
|
13017
13073
|
const metadata = this.extractStaticJsonValue(node.arguments[0]);
|
|
13018
13074
|
if (metadata && typeof metadata === "object" && !Array.isArray(metadata)) {
|
|
13019
|
-
|
|
13075
|
+
const { id: _id, ...rest } = metadata;
|
|
13076
|
+
Object.assign(schema, rest);
|
|
13020
13077
|
}
|
|
13021
13078
|
}
|
|
13022
13079
|
break;
|
|
@@ -13302,6 +13359,7 @@ var ZodSchemaConverter = class {
|
|
|
13302
13359
|
this.currentFilePath = filePath;
|
|
13303
13360
|
this.currentAST = ast;
|
|
13304
13361
|
this.currentImports = importedModules;
|
|
13362
|
+
this.preprocessedFiles.add(filePath);
|
|
13305
13363
|
resolvedTraverse(ast, {
|
|
13306
13364
|
ExportNamedDeclaration: (path25) => {
|
|
13307
13365
|
if (t10.isVariableDeclaration(path25.node.declaration)) {
|
|
@@ -13309,15 +13367,19 @@ var ZodSchemaConverter = class {
|
|
|
13309
13367
|
if (t10.isIdentifier(declaration.id) && declaration.init) {
|
|
13310
13368
|
const schemaName = declaration.id.name;
|
|
13311
13369
|
if (this.isZodSchema(declaration.init)) {
|
|
13312
|
-
this.indexSchemaName(schemaName, filePath);
|
|
13313
13370
|
if (!this.getStoredSchema(schemaName)) {
|
|
13314
13371
|
logger.debug(`Pre-processing Zod schema: ${schemaName}`);
|
|
13315
13372
|
this.processingSchemas.add(schemaName);
|
|
13316
13373
|
const schema = this.processZodNode(declaration.init);
|
|
13374
|
+
this.processingSchemas.delete(schemaName);
|
|
13317
13375
|
if (schema) {
|
|
13318
|
-
this.
|
|
13376
|
+
const overrideId = this.extractMetaIdFromNode(declaration.init);
|
|
13377
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
13378
|
+
} else {
|
|
13379
|
+
this.indexSchemaName(schemaName, filePath);
|
|
13319
13380
|
}
|
|
13320
|
-
|
|
13381
|
+
} else {
|
|
13382
|
+
this.indexSchemaName(schemaName, filePath);
|
|
13321
13383
|
}
|
|
13322
13384
|
}
|
|
13323
13385
|
}
|
|
@@ -13330,22 +13392,25 @@ var ZodSchemaConverter = class {
|
|
|
13330
13392
|
if (t10.isIdentifier(declaration.id) && declaration.init) {
|
|
13331
13393
|
const schemaName = declaration.id.name;
|
|
13332
13394
|
if (this.isZodSchema(declaration.init)) {
|
|
13333
|
-
this.indexSchemaName(schemaName, filePath);
|
|
13334
13395
|
if (!this.getStoredSchema(schemaName) && !this.processingSchemas.has(schemaName)) {
|
|
13335
13396
|
logger.debug(`Pre-processing Zod schema: ${schemaName}`);
|
|
13336
13397
|
this.processingSchemas.add(schemaName);
|
|
13337
13398
|
const schema = this.processZodNode(declaration.init);
|
|
13399
|
+
this.processingSchemas.delete(schemaName);
|
|
13338
13400
|
if (schema) {
|
|
13339
|
-
this.
|
|
13401
|
+
const overrideId = this.extractMetaIdFromNode(declaration.init);
|
|
13402
|
+
this.applyMetaIdOverride(schemaName, schema, overrideId, filePath);
|
|
13403
|
+
} else {
|
|
13404
|
+
this.indexSchemaName(schemaName, filePath);
|
|
13340
13405
|
}
|
|
13341
|
-
|
|
13406
|
+
} else {
|
|
13407
|
+
this.indexSchemaName(schemaName, filePath);
|
|
13342
13408
|
}
|
|
13343
13409
|
}
|
|
13344
13410
|
}
|
|
13345
13411
|
});
|
|
13346
13412
|
}
|
|
13347
13413
|
});
|
|
13348
|
-
this.preprocessedFiles.add(filePath);
|
|
13349
13414
|
} catch (error2) {
|
|
13350
13415
|
logger.error(`Error pre-processing file ${filePath}: ${error2}`);
|
|
13351
13416
|
}
|
|
@@ -13363,6 +13428,63 @@ var ZodSchemaConverter = class {
|
|
|
13363
13428
|
}
|
|
13364
13429
|
bucket.add(filePath);
|
|
13365
13430
|
}
|
|
13431
|
+
applyMetaIdOverride(schemaName, schema, overrideId, filePath) {
|
|
13432
|
+
const finalName = overrideId && overrideId !== schemaName ? overrideId : schemaName;
|
|
13433
|
+
this.indexSchemaName(schemaName, filePath);
|
|
13434
|
+
if (finalName !== schemaName) {
|
|
13435
|
+
this.indexSchemaName(finalName, filePath);
|
|
13436
|
+
}
|
|
13437
|
+
if (!this.zodSchemas[finalName]) {
|
|
13438
|
+
if (overrideId && overrideId !== schemaName) {
|
|
13439
|
+
this.typeToSchemaMapping[schemaName] = overrideId;
|
|
13440
|
+
this.metaIdSchemaNames.add(schemaName);
|
|
13441
|
+
if (this.typeToSchemaMapping[overrideId] === schemaName) {
|
|
13442
|
+
delete this.typeToSchemaMapping[overrideId];
|
|
13443
|
+
}
|
|
13444
|
+
}
|
|
13445
|
+
const variantKey = this.getVariantKey(finalName, this.currentContentType);
|
|
13446
|
+
this.zodSchemas[finalName] = schema;
|
|
13447
|
+
this.schemaVariantRefs.set(variantKey, finalName);
|
|
13448
|
+
} else {
|
|
13449
|
+
logger.warn(`Schema component name '${overrideId ?? finalName}' conflicts with an existing schema, ignoring .meta({ id }) on '${schemaName}'`);
|
|
13450
|
+
}
|
|
13451
|
+
}
|
|
13452
|
+
/**
|
|
13453
|
+
* Derives the conventional Zod schema name from a TypeScript type name.
|
|
13454
|
+
* e.g. "Slider" → "sliderSchema", "SliderItem" → "sliderItemSchema".
|
|
13455
|
+
* Returns null when the input is already a schema name or is not PascalCase.
|
|
13456
|
+
*/
|
|
13457
|
+
deriveSchemaNameByConvention(typeName) {
|
|
13458
|
+
if (!typeName || !/^[A-Z]/.test(typeName) || typeName.endsWith("Schema")) {
|
|
13459
|
+
return null;
|
|
13460
|
+
}
|
|
13461
|
+
return typeName[0].toLowerCase() + typeName.slice(1) + "Schema";
|
|
13462
|
+
}
|
|
13463
|
+
/**
|
|
13464
|
+
* Checks whether a Zod schema with the given name is present in schemaDirs
|
|
13465
|
+
* WITHOUT populating the processed-schema cache. A file-content substring check
|
|
13466
|
+
* (the same heuristic used by processFileForZodSchema) is sufficient here: we
|
|
13467
|
+
* only want to know whether the candidate *might* live in schemaDirs so that the
|
|
13468
|
+
* convention mapping can be registered; the actual processing happens later in
|
|
13469
|
+
* the normal convertZodSchemaToOpenApi lookup flow.
|
|
13470
|
+
*/
|
|
13471
|
+
locateSchemaByConvention(candidate) {
|
|
13472
|
+
if (this.schemaNameToFiles.has(candidate)) {
|
|
13473
|
+
return true;
|
|
13474
|
+
}
|
|
13475
|
+
for (const dir of this.schemaDirs) {
|
|
13476
|
+
for (const filePath of this.getSchemaFiles(dir)) {
|
|
13477
|
+
try {
|
|
13478
|
+
const content = this.fileAccess.readFileSync(filePath, "utf-8");
|
|
13479
|
+
if (content.includes(candidate)) {
|
|
13480
|
+
return true;
|
|
13481
|
+
}
|
|
13482
|
+
} catch {
|
|
13483
|
+
}
|
|
13484
|
+
}
|
|
13485
|
+
}
|
|
13486
|
+
return false;
|
|
13487
|
+
}
|
|
13366
13488
|
/**
|
|
13367
13489
|
* Check if node is Zod schema
|
|
13368
13490
|
*/
|
|
@@ -13594,7 +13716,7 @@ function parsePropertyComment(commentValue) {
|
|
|
13594
13716
|
function getPropertyOptions(node, contentType) {
|
|
13595
13717
|
const isOptional = !!node.optional;
|
|
13596
13718
|
const options = {};
|
|
13597
|
-
const leadingComment = node.leadingComments?.
|
|
13719
|
+
const leadingComment = node.leadingComments?.findLast((c) => c.type === "CommentBlock" || !node.trailingComments?.length);
|
|
13598
13720
|
const trailingComment = node.trailingComments?.[0];
|
|
13599
13721
|
const sourceComment = leadingComment ?? trailingComment;
|
|
13600
13722
|
if (sourceComment) {
|
|
@@ -13997,31 +14119,60 @@ function resolveImportPath(importPath, fromFilePath, fileAccess) {
|
|
|
13997
14119
|
}
|
|
13998
14120
|
return null;
|
|
13999
14121
|
}
|
|
14000
|
-
function
|
|
14122
|
+
function collectFirstMemberLeadingComments(interfaceDecl) {
|
|
14123
|
+
const body = interfaceDecl?.body;
|
|
14124
|
+
if (!body)
|
|
14125
|
+
return [];
|
|
14126
|
+
const firstMember = body.body?.[0];
|
|
14127
|
+
return firstMember?.leadingComments ?? [];
|
|
14128
|
+
}
|
|
14129
|
+
function collectAllExportedDefinitions(ast, typeDefinitions, currentFile, schemaIdAliases) {
|
|
14130
|
+
function registerDefinition(name, entry, allComments) {
|
|
14131
|
+
if (!typeDefinitions[name]) {
|
|
14132
|
+
typeDefinitions[name] = entry;
|
|
14133
|
+
}
|
|
14134
|
+
const overrideId = extractSchemaIdFromComments(allComments);
|
|
14135
|
+
if (overrideId && schemaIdAliases) {
|
|
14136
|
+
schemaIdAliases[name] = overrideId;
|
|
14137
|
+
if (!typeDefinitions[overrideId]) {
|
|
14138
|
+
typeDefinitions[overrideId] = entry;
|
|
14139
|
+
}
|
|
14140
|
+
}
|
|
14141
|
+
}
|
|
14001
14142
|
resolvedTraverse(ast, {
|
|
14002
14143
|
TSTypeAliasDeclaration: (path25) => {
|
|
14003
14144
|
if (path25.node.id && t12.isIdentifier(path25.node.id)) {
|
|
14004
14145
|
const name = path25.node.id.name;
|
|
14005
|
-
|
|
14006
|
-
|
|
14007
|
-
|
|
14008
|
-
|
|
14146
|
+
const node = path25.node.typeParameters && path25.node.typeParameters.params.length > 0 ? path25.node : path25.node.typeAnnotation;
|
|
14147
|
+
const allComments = [
|
|
14148
|
+
...path25.parentPath?.node?.leadingComments ?? [],
|
|
14149
|
+
...path25.node.leadingComments ?? [],
|
|
14150
|
+
...path25.node.trailingComments ?? []
|
|
14151
|
+
];
|
|
14152
|
+
registerDefinition(name, { node, filePath: currentFile }, allComments);
|
|
14009
14153
|
}
|
|
14010
14154
|
},
|
|
14011
14155
|
TSInterfaceDeclaration: (path25) => {
|
|
14012
14156
|
if (path25.node.id && t12.isIdentifier(path25.node.id)) {
|
|
14013
14157
|
const name = path25.node.id.name;
|
|
14014
|
-
|
|
14015
|
-
|
|
14016
|
-
|
|
14158
|
+
const allComments = [
|
|
14159
|
+
...path25.parentPath?.node?.leadingComments ?? [],
|
|
14160
|
+
...path25.node.leadingComments ?? [],
|
|
14161
|
+
...path25.node.trailingComments ?? [],
|
|
14162
|
+
...collectFirstMemberLeadingComments(path25.node)
|
|
14163
|
+
];
|
|
14164
|
+
registerDefinition(name, { node: path25.node, filePath: currentFile }, allComments);
|
|
14017
14165
|
}
|
|
14018
14166
|
},
|
|
14019
14167
|
TSEnumDeclaration: (path25) => {
|
|
14020
14168
|
if (path25.node.id && t12.isIdentifier(path25.node.id)) {
|
|
14021
14169
|
const name = path25.node.id.name;
|
|
14022
|
-
|
|
14023
|
-
|
|
14024
|
-
|
|
14170
|
+
const allComments = [
|
|
14171
|
+
...path25.parentPath?.node?.leadingComments ?? [],
|
|
14172
|
+
...path25.node.leadingComments ?? [],
|
|
14173
|
+
...path25.node.trailingComments ?? []
|
|
14174
|
+
];
|
|
14175
|
+
registerDefinition(name, { node: path25.node, filePath: currentFile }, allComments);
|
|
14025
14176
|
}
|
|
14026
14177
|
},
|
|
14027
14178
|
ExportNamedDeclaration: (path25) => {
|
|
@@ -14029,19 +14180,26 @@ function collectAllExportedDefinitions(ast, typeDefinitions, currentFile) {
|
|
|
14029
14180
|
const interfaceDecl = path25.node.declaration;
|
|
14030
14181
|
if (interfaceDecl.id && t12.isIdentifier(interfaceDecl.id)) {
|
|
14031
14182
|
const name = interfaceDecl.id.name;
|
|
14032
|
-
|
|
14033
|
-
|
|
14034
|
-
|
|
14183
|
+
const allComments = [
|
|
14184
|
+
...path25.node.leadingComments ?? [],
|
|
14185
|
+
...interfaceDecl.leadingComments ?? [],
|
|
14186
|
+
...interfaceDecl.trailingComments ?? [],
|
|
14187
|
+
...collectFirstMemberLeadingComments(interfaceDecl)
|
|
14188
|
+
];
|
|
14189
|
+
registerDefinition(name, { node: interfaceDecl, filePath: currentFile }, allComments);
|
|
14035
14190
|
}
|
|
14036
14191
|
}
|
|
14037
14192
|
if (t12.isTSTypeAliasDeclaration(path25.node.declaration)) {
|
|
14038
14193
|
const typeDecl = path25.node.declaration;
|
|
14039
14194
|
if (typeDecl.id && t12.isIdentifier(typeDecl.id)) {
|
|
14040
14195
|
const name = typeDecl.id.name;
|
|
14041
|
-
|
|
14042
|
-
|
|
14043
|
-
|
|
14044
|
-
|
|
14196
|
+
const node = typeDecl.typeParameters && typeDecl.typeParameters.params.length > 0 ? typeDecl : typeDecl.typeAnnotation;
|
|
14197
|
+
const allComments = [
|
|
14198
|
+
...path25.node.leadingComments ?? [],
|
|
14199
|
+
...typeDecl.leadingComments ?? [],
|
|
14200
|
+
...typeDecl.trailingComments ?? []
|
|
14201
|
+
];
|
|
14202
|
+
registerDefinition(name, { node, filePath: currentFile }, allComments);
|
|
14045
14203
|
}
|
|
14046
14204
|
}
|
|
14047
14205
|
}
|
|
@@ -14458,6 +14616,7 @@ var SchemaProcessor = class {
|
|
|
14458
14616
|
zodSchemaProcessor = null;
|
|
14459
14617
|
schemaTypes;
|
|
14460
14618
|
isResolvingPickOmitBase = false;
|
|
14619
|
+
schemaIdAliases = {};
|
|
14461
14620
|
fileAccess;
|
|
14462
14621
|
symbolResolver;
|
|
14463
14622
|
// Track imports per file for resolving ReturnType<typeof func>
|
|
@@ -14498,7 +14657,7 @@ var SchemaProcessor = class {
|
|
|
14498
14657
|
getDefinedSchemas() {
|
|
14499
14658
|
const filteredSchemas = {};
|
|
14500
14659
|
Object.entries(this.openapiDefinitions).forEach(([key, value]) => {
|
|
14501
|
-
if (!this.isGenericTypeParameter(key) && !this.isInvalidSchemaName(key) && !this.isBuiltInUtilityType(key) && !this.isFunctionSchema(key)) {
|
|
14660
|
+
if (!this.schemaIdAliases[key] && !this.isGenericTypeParameter(key) && !this.isInvalidSchemaName(key) && !this.isBuiltInUtilityType(key) && !this.isFunctionSchema(key)) {
|
|
14502
14661
|
filteredSchemas[key] = value;
|
|
14503
14662
|
}
|
|
14504
14663
|
});
|
|
@@ -14513,6 +14672,10 @@ var SchemaProcessor = class {
|
|
|
14513
14672
|
if (schemaName.includes("<") && schemaName.includes(">")) {
|
|
14514
14673
|
return this.resolveGenericTypeFromString(schemaName);
|
|
14515
14674
|
}
|
|
14675
|
+
const overrideId = this.schemaIdAliases[schemaName];
|
|
14676
|
+
if (overrideId) {
|
|
14677
|
+
return this.findSchemaDefinition(overrideId, contentType);
|
|
14678
|
+
}
|
|
14516
14679
|
if (this.openapiDefinitions[schemaName]) {
|
|
14517
14680
|
return this.openapiDefinitions[schemaName];
|
|
14518
14681
|
}
|
|
@@ -14594,6 +14757,7 @@ var SchemaProcessor = class {
|
|
|
14594
14757
|
return;
|
|
14595
14758
|
}
|
|
14596
14759
|
this.collectImports(ast, filePath);
|
|
14760
|
+
const aliasesBeforeFile = new Set(Object.keys(this.schemaIdAliases));
|
|
14597
14761
|
this.collectAllExportedDefinitions(ast, filePath);
|
|
14598
14762
|
collectTopLevelDefinitionNames(ast).forEach((name) => {
|
|
14599
14763
|
const indexedFiles = this.schemaDefinitionIndex[name];
|
|
@@ -14605,6 +14769,16 @@ var SchemaProcessor = class {
|
|
|
14605
14769
|
}
|
|
14606
14770
|
this.schemaDefinitionIndex[name] = [filePath];
|
|
14607
14771
|
});
|
|
14772
|
+
Object.entries(this.schemaIdAliases).forEach(([originalName, aliasName]) => {
|
|
14773
|
+
if (aliasesBeforeFile.has(originalName))
|
|
14774
|
+
return;
|
|
14775
|
+
if (!this.schemaDefinitionIndex[aliasName]) {
|
|
14776
|
+
this.schemaDefinitionIndex[aliasName] = [];
|
|
14777
|
+
}
|
|
14778
|
+
if (!this.schemaDefinitionIndex[aliasName].includes(filePath)) {
|
|
14779
|
+
this.schemaDefinitionIndex[aliasName].push(filePath);
|
|
14780
|
+
}
|
|
14781
|
+
});
|
|
14608
14782
|
}
|
|
14609
14783
|
getParsedSchemaFile(filePath) {
|
|
14610
14784
|
const cachedAst = this.fileASTCache.get(filePath);
|
|
@@ -14643,7 +14817,7 @@ var SchemaProcessor = class {
|
|
|
14643
14817
|
* Used when processing imported files to ensure all referenced types are available
|
|
14644
14818
|
*/
|
|
14645
14819
|
collectAllExportedDefinitions(ast, filePath) {
|
|
14646
|
-
collectAllExportedDefinitions(ast, this.typeDefinitions, filePath || this.currentFilePath);
|
|
14820
|
+
collectAllExportedDefinitions(ast, this.typeDefinitions, filePath || this.currentFilePath, this.schemaIdAliases);
|
|
14647
14821
|
}
|
|
14648
14822
|
collectTypeDefinitions(ast, schemaName, filePath) {
|
|
14649
14823
|
collectTypeDefinitions(ast, schemaName, this.typeDefinitions, filePath || this.currentFilePath);
|
|
@@ -15240,6 +15414,9 @@ var SchemaProcessor = class {
|
|
|
15240
15414
|
logger.debug(`Record<...> used with ${node.typeParameters?.params.length ?? 0} type parameters; expected 2`);
|
|
15241
15415
|
return { type: "object", additionalProperties: true };
|
|
15242
15416
|
}
|
|
15417
|
+
if ((!node.typeParameters || node.typeParameters.params.length === 0) && this.schemaIdAliases[typeName] && this.openapiDefinitions[this.schemaIdAliases[typeName]]) {
|
|
15418
|
+
return { $ref: `#/components/schemas/${this.schemaIdAliases[typeName]}` };
|
|
15419
|
+
}
|
|
15243
15420
|
const utilityType = resolveUtilityTypeReference(node, {
|
|
15244
15421
|
currentFilePath: this.currentFilePath,
|
|
15245
15422
|
contentType: this.contentType,
|
|
@@ -15415,7 +15592,9 @@ var SchemaProcessor = class {
|
|
|
15415
15592
|
};
|
|
15416
15593
|
}
|
|
15417
15594
|
if (t15.isTSTypeReference(node) && t15.isIdentifier(node.typeName)) {
|
|
15418
|
-
|
|
15595
|
+
const refName = node.typeName.name;
|
|
15596
|
+
const aliasedName = this.schemaIdAliases[refName] ?? refName;
|
|
15597
|
+
return { $ref: `#/components/schemas/${aliasedName}` };
|
|
15419
15598
|
}
|
|
15420
15599
|
logger.debug("Unrecognized TypeScript type node:", node);
|
|
15421
15600
|
return { type: "object" };
|
|
@@ -15556,7 +15735,8 @@ var SchemaProcessor = class {
|
|
|
15556
15735
|
if (this.schemaTypes.includes("zod") && this.zodSchemaConverter) {
|
|
15557
15736
|
return this.zodSchemaConverter.getSchemaReferenceName(baseTypeName, contentType);
|
|
15558
15737
|
}
|
|
15559
|
-
|
|
15738
|
+
const aliasedName = this.schemaIdAliases[baseTypeName] ?? baseTypeName;
|
|
15739
|
+
return aliasedName;
|
|
15560
15740
|
}
|
|
15561
15741
|
/**
|
|
15562
15742
|
* Parse and resolve a generic type from a string like "MyApiSuccessResponseBody<LLMSResponse>"
|