@@ -38,6 +38,7 @@ import {
3838 InputPrimitiveType ,
3939 InputType ,
4040 InputUnionType ,
41+ ExternalTypeInfo ,
4142} from "../type/input-type.js" ;
4243import { isReadOnly } from "./utils.js" ;
4344
@@ -81,36 +82,39 @@ export function fromSdkType<T extends SdkType>(
8182 return retVar as any ;
8283 }
8384
84- // Check if this type references an external type
85- if ( ( sdkType as any ) . external ) {
86- retVar = fromSdkExternalType ( sdkContext , sdkType ) ;
87- sdkContext . __typeCache . updateSdkTypeReferences ( sdkType , retVar ) ;
88- return retVar as any ;
89- }
85+ // Extract external type information if present
86+ const externalInfo = ( sdkType as any ) . external
87+ ? {
88+ identity : ( sdkType as any ) . external . identity ,
89+ package : ( sdkType as any ) . external . package ,
90+ minVersion : ( sdkType as any ) . external . minVersion ,
91+ }
92+ : undefined ;
9093
9194 switch ( sdkType . kind ) {
9295 case "nullable" :
9396 const nullableType : InputNullableType = {
9497 kind : "nullable" ,
9598 type : fromSdkType ( sdkContext , sdkType . type , sdkProperty , namespace ) ,
9699 namespace : sdkType . namespace ,
100+ external : externalInfo ,
97101 } ;
98102 retVar = nullableType ;
99103 break ;
100104 case "model" :
101- retVar = fromSdkModelType ( sdkContext , sdkType ) ;
105+ retVar = fromSdkModelType ( sdkContext , sdkType , externalInfo ) ;
102106 break ;
103107 case "enum" :
104- retVar = fromSdkEnumType ( sdkContext , sdkType ) ;
108+ retVar = fromSdkEnumType ( sdkContext , sdkType , externalInfo ) ;
105109 break ;
106110 case "enumvalue" :
107111 retVar = fromSdkEnumValueType ( sdkContext , sdkType ) ;
108112 break ;
109113 case "dict" :
110- retVar = fromSdkDictionaryType ( sdkContext , sdkType ) ;
114+ retVar = fromSdkDictionaryType ( sdkContext , sdkType , externalInfo ) ;
111115 break ;
112116 case "array" :
113- retVar = fromSdkArrayType ( sdkContext , sdkType ) ;
117+ retVar = fromSdkArrayType ( sdkContext , sdkType , externalInfo ) ;
114118 break ;
115119 case "constant" :
116120 if (
@@ -120,20 +124,20 @@ export function fromSdkType<T extends SdkType>(
120124 sdkType . valueType . kind !== "boolean"
121125 ) {
122126 // turn the constant into an extensible enum
123- retVar = createEnumType ( sdkContext , sdkType , namespace ! ) ;
127+ retVar = createEnumType ( sdkContext , sdkType , namespace ! , externalInfo ) ;
124128 } else {
125129 retVar = fromSdkConstantType ( sdkContext , sdkType ) ;
126130 }
127131 break ;
128132 case "union" :
129- retVar = fromUnionType ( sdkContext , sdkType ) ;
133+ retVar = fromUnionType ( sdkContext , sdkType , externalInfo ) ;
130134 break ;
131135 case "utcDateTime" :
132136 case "offsetDateTime" :
133- retVar = fromSdkDateTimeType ( sdkContext , sdkType ) ;
137+ retVar = fromSdkDateTimeType ( sdkContext , sdkType , externalInfo ) ;
134138 break ;
135139 case "duration" :
136- retVar = fromSdkDurationType ( sdkContext , sdkType ) ;
140+ retVar = fromSdkDurationType ( sdkContext , sdkType , externalInfo ) ;
137141 break ;
138142 case "tuple" :
139143 sdkContext . logger . reportDiagnostic ( {
@@ -146,6 +150,7 @@ export function fromSdkType<T extends SdkType>(
146150 name : "tuple" ,
147151 crossLanguageDefinitionId : "" ,
148152 decorators : sdkType . decorators ,
153+ external : externalInfo ,
149154 } ;
150155 retVar = tupleType ;
151156 break ;
@@ -165,11 +170,12 @@ export function fromSdkType<T extends SdkType>(
165170 name : "credential" ,
166171 crossLanguageDefinitionId : "" ,
167172 decorators : sdkType . decorators ,
173+ external : externalInfo ,
168174 } ;
169175 retVar = credentialType ;
170176 break ;
171177 default :
172- retVar = fromSdkBuiltInType ( sdkContext , sdkType ) ;
178+ retVar = fromSdkBuiltInType ( sdkContext , sdkType , externalInfo ) ;
173179 break ;
174180 }
175181
@@ -181,6 +187,7 @@ export function fromSdkType<T extends SdkType>(
181187function fromSdkModelType (
182188 sdkContext : CSharpEmitterContext ,
183189 modelType : SdkModelType ,
190+ externalInfo ?: ExternalTypeInfo ,
184191) : InputModelType {
185192 // get all unique decorators for the model type from the namespace level and the model level
186193 let decorators : DecoratorInfo [ ] = modelType . decorators ;
@@ -200,6 +207,7 @@ function fromSdkModelType(
200207 summary : modelType . summary ,
201208 discriminatorValue : modelType . discriminatorValue ,
202209 decorators : decorators ,
210+ external : externalInfo ,
203211 } as InputModelType ;
204212
205213 sdkContext . __typeCache . updateSdkTypeReferences ( modelType , inputModelType ) ;
@@ -281,14 +289,15 @@ function fromSdkModelProperty(
281289 return property ;
282290}
283291
284- function fromSdkEnumType ( sdkContext : CSharpEmitterContext , enumType : SdkEnumType ) : InputEnumType {
285- return createEnumType ( sdkContext , enumType , enumType . namespace ) ;
292+ function fromSdkEnumType ( sdkContext : CSharpEmitterContext , enumType : SdkEnumType , externalInfo ?: ExternalTypeInfo ) : InputEnumType {
293+ return createEnumType ( sdkContext , enumType , enumType . namespace , externalInfo ) ;
286294}
287295
288296function createEnumType (
289297 sdkContext : CSharpEmitterContext ,
290298 sdkType : SdkConstantType | SdkEnumType ,
291299 namespace : string ,
300+ externalInfo ?: ExternalTypeInfo ,
292301) : InputEnumType {
293302 const values : InputEnumValueType [ ] = [ ] ;
294303
@@ -313,6 +322,7 @@ function createEnumType(
313322 // constantType.usage, TODO - constant type now does not have usage. TCGC will add it later
314323 usage : sdkType . kind === "enum" ? sdkType . usage : UsageFlags . None ,
315324 decorators : sdkType . decorators ,
325+ external : externalInfo ,
316326 } ;
317327
318328 sdkContext . __typeCache . updateSdkTypeReferences ( sdkType , inputEnumType ) ;
@@ -331,6 +341,7 @@ function createEnumType(
331341function fromSdkDateTimeType (
332342 sdkContext : CSharpEmitterContext ,
333343 dateTimeType : SdkDateTimeType ,
344+ externalInfo ?: ExternalTypeInfo ,
334345) : InputDateTimeType {
335346 return {
336347 kind : dateTimeType . kind ,
@@ -340,12 +351,14 @@ function fromSdkDateTimeType(
340351 crossLanguageDefinitionId : dateTimeType . crossLanguageDefinitionId ,
341352 baseType : dateTimeType . baseType ? fromSdkType ( sdkContext , dateTimeType . baseType ) : undefined ,
342353 decorators : dateTimeType . decorators ,
354+ external : externalInfo ,
343355 } ;
344356}
345357
346358function fromSdkDurationType (
347359 sdkContext : CSharpEmitterContext ,
348360 durationType : SdkDurationType ,
361+ externalInfo ?: ExternalTypeInfo ,
349362) : InputDurationType {
350363 return {
351364 kind : durationType . kind ,
@@ -355,12 +368,14 @@ function fromSdkDurationType(
355368 crossLanguageDefinitionId : durationType . crossLanguageDefinitionId ,
356369 baseType : durationType . baseType ? fromSdkType ( sdkContext , durationType . baseType ) : undefined ,
357370 decorators : durationType . decorators ,
371+ external : externalInfo ,
358372 } ;
359373}
360374
361375function fromSdkBuiltInType (
362376 sdkContext : CSharpEmitterContext ,
363377 builtInType : SdkBuiltInType ,
378+ externalInfo ?: ExternalTypeInfo ,
364379) : InputPrimitiveType {
365380 return {
366381 kind : builtInType . kind ,
@@ -369,10 +384,11 @@ function fromSdkBuiltInType(
369384 crossLanguageDefinitionId : builtInType . crossLanguageDefinitionId ,
370385 baseType : builtInType . baseType ? fromSdkType ( sdkContext , builtInType . baseType ) : undefined ,
371386 decorators : builtInType . decorators ,
387+ external : externalInfo ,
372388 } ;
373389}
374390
375- function fromUnionType ( sdkContext : CSharpEmitterContext , union : SdkUnionType ) : InputUnionType {
391+ function fromUnionType ( sdkContext : CSharpEmitterContext , union : SdkUnionType , externalInfo ?: ExternalTypeInfo ) : InputUnionType {
376392 const variantTypes : InputType [ ] = [ ] ;
377393 for ( const value of union . variantTypes ) {
378394 const variantType = fromSdkType ( sdkContext , value ) ;
@@ -385,6 +401,7 @@ function fromUnionType(sdkContext: CSharpEmitterContext, union: SdkUnionType): I
385401 variantTypes : variantTypes ,
386402 namespace : union . namespace ,
387403 decorators : union . decorators ,
404+ external : externalInfo ,
388405 } ;
389406}
390407
@@ -441,25 +458,29 @@ function createEnumValueType(
441458function fromSdkDictionaryType (
442459 sdkContext : CSharpEmitterContext ,
443460 dictionaryType : SdkDictionaryType ,
461+ externalInfo ?: ExternalTypeInfo ,
444462) : InputDictionaryType {
445463 return {
446464 kind : "dict" ,
447465 keyType : fromSdkType ( sdkContext , dictionaryType . keyType ) ,
448466 valueType : fromSdkType ( sdkContext , dictionaryType . valueType ) ,
449467 decorators : dictionaryType . decorators ,
468+ external : externalInfo ,
450469 } ;
451470}
452471
453472function fromSdkArrayType (
454473 sdkContext : CSharpEmitterContext ,
455474 arrayType : SdkArrayType ,
475+ externalInfo ?: ExternalTypeInfo ,
456476) : InputArrayType {
457477 return {
458478 kind : "array" ,
459479 name : arrayType . name ,
460480 valueType : fromSdkType ( sdkContext , arrayType . valueType ) ,
461481 crossLanguageDefinitionId : arrayType . crossLanguageDefinitionId ,
462482 decorators : arrayType . decorators ,
483+ external : externalInfo ,
463484 } ;
464485}
465486
@@ -471,20 +492,6 @@ function fromSdkEndpointType(): InputPrimitiveType {
471492 } ;
472493}
473494
474- function fromSdkExternalType (
475- sdkContext : CSharpEmitterContext ,
476- sdkType : SdkType ,
477- ) : InputExternalType {
478- const external = ( sdkType as any ) . external ;
479- return {
480- kind : "external" ,
481- identity : external . identity ,
482- package : external . package ,
483- minVersion : external . minVersion ,
484- decorators : sdkType . decorators ,
485- } ;
486- }
487-
488495/**
489496 * @beta
490497 */
0 commit comments