@@ -53,11 +53,12 @@ export function createModel(sdkContext: CSharpEmitterContext): [CodeModel, reado
5353
5454 const models : InputModelType [ ] = [ ] ;
5555 const enums : InputEnumType [ ] = [ ] ;
56- const existingModelNames = new Set < string > ( ) ;
56+ const existingModelKeys = new Set < string > ( ) ;
5757 for ( const type of typesBeforeClients ) {
5858 if ( type . kind === "model" ) {
59- models . push ( type as InputModelType ) ;
60- existingModelNames . add ( ( type as InputModelType ) . name ) ;
59+ const model = type as InputModelType ;
60+ models . push ( model ) ;
61+ existingModelKeys . add ( `${ model . namespace } .${ model . name } ` ) ;
6162 } else if ( type . kind === "enum" ) {
6263 enums . push ( type as InputEnumType ) ;
6364 }
@@ -66,21 +67,23 @@ export function createModel(sdkContext: CSharpEmitterContext): [CodeModel, reado
6667 // response models for protocol-only paging operations where TCGC does not include the
6768 // response model in sdkPackage.models, or enums only reachable through nested property
6869 // types of such models). See https://github.com/microsoft/typespec/issues/9391. Dedupe
69- // models by name to avoid duplicates when TCGC produces a different reference for the
70- // same model .
71- const existingEnumNames = new Set ( enums . map ( ( e ) => e . name ) ) ;
70+ // by namespace + name to avoid duplicates when TCGC produces a different reference for
71+ // the same type, while still allowing distinct types that share a name across namespaces .
72+ const existingEnumKeys = new Set ( enums . map ( ( e ) => ` ${ e . namespace } . ${ e . name } ` ) ) ;
7273 for ( const type of sdkContext . __typeCache . types . values ( ) ) {
7374 if ( typesBeforeClients . has ( type ) ) continue ;
7475 if ( type . kind === "model" ) {
7576 const model = type as InputModelType ;
76- if ( existingModelNames . has ( model . name ) ) continue ;
77+ const key = `${ model . namespace } .${ model . name } ` ;
78+ if ( existingModelKeys . has ( key ) ) continue ;
7779 models . push ( model ) ;
78- existingModelNames . add ( model . name ) ;
80+ existingModelKeys . add ( key ) ;
7981 } else if ( type . kind === "enum" ) {
8082 const enumType = type as InputEnumType ;
81- if ( existingEnumNames . has ( enumType . name ) ) continue ;
83+ const key = `${ enumType . namespace } .${ enumType . name } ` ;
84+ if ( existingEnumKeys . has ( key ) ) continue ;
8285 enums . push ( enumType ) ;
83- existingEnumNames . add ( enumType . name ) ;
86+ existingEnumKeys . add ( key ) ;
8487 }
8588 }
8689
0 commit comments