Skip to content

Commit 6ac750e

Browse files
author
Travis Wagner
committed
rename duplicate named models
1 parent 91bd685 commit 6ac750e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

bun.lockb

532 KB
Binary file not shown.

src/utils/writeClient.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@ export const writeClient = async (
5050
clientName?: string,
5151
request?: string
5252
): Promise<void> => {
53+
// if there are any duplicates in the models, append a number
54+
const modelNames = client.models.map((model) => model.name);
55+
const modelNamesSet = new Set(modelNames);
56+
if (modelNames.length !== modelNamesSet.size) {
57+
const modelNamesMap = new Map<string, number>();
58+
for (const modelName of modelNames) {
59+
if (modelNamesMap.has(modelName)) {
60+
modelNamesMap.set(modelName, modelNamesMap.get(modelName)! + 1);
61+
} else {
62+
modelNamesMap.set(modelName, 1);
63+
}
64+
}
65+
for (const model of client.models) {
66+
if (modelNamesMap.get(model.name)! > 1) {
67+
model.name = `${model.name}${modelNamesMap.get(model.name)}`;
68+
}
69+
}
70+
}
71+
5372
const outputPath = resolve(process.cwd(), output);
5473
const outputPathCore = resolve(outputPath, 'core');
5574
const outputPathModels = resolve(outputPath, 'models');

0 commit comments

Comments
 (0)