Skip to content

Commit

Permalink
Report all type name collision errors at the same time (#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhendrixMSFT committed Apr 22, 2022
1 parent 7fe48d1 commit 77395e0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/transform/namer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,19 @@ export async function namer(session: Session<CodeModel>) {
}

// fix stuttering type names
const collisions = new Array<string>();
for (const obj of values(model.schemas.objects)) {
const details = <Language>obj.language.go;
const originalName = details.name;
details.name = trimPackagePrefix(stutteringPrefix, originalName);
// if the type was renamed to remove stuttering, check if it collides with an existing type name
if (details.name !== originalName && structNames.has(details.name)) {
throw new Error(`type ${originalName} was renamed to ${details.name} which collides with an existing type name`);
collisions.push(`type ${originalName} was renamed to ${details.name} which collides with an existing type name`);
}
}
if (collisions.length > 0) {
throw new Error(collisions.join('\n'));
}

// fix property names and other bits
for (const obj of values(model.schemas.objects)) {
Expand Down

0 comments on commit 77395e0

Please sign in to comment.