File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ changeKind : fix
3+ packages :
4+ - " @azure-tools/typespec-go"
5+ ---
6+
7+ Fixed adapting ` Access.internal ` operations that return a polymorphic type.
Original file line number Diff line number Diff line change @@ -913,13 +913,28 @@ export class TypeAdapter {
913913
914914 private getLiteralValue ( constType : tcgc . SdkConstantType | tcgc . SdkEnumValueType ) : go . Literal {
915915 if ( constType . kind === "enumvalue" ) {
916- const valueName = `${ helpers . getEffectiveName ( constType . enumType ) } ${ helpers . getEffectiveName ( constType ) } ` ;
917- const keyName = `literal-${ valueName } ` ;
916+ const goConstType = this . getConstantType ( constType . enumType ) ;
917+ // find the matching enum value
918+ let goConstValue : go . ConstantValue | undefined ;
919+ for ( const value of goConstType . values ) {
920+ if ( value . value === constType . value ) {
921+ goConstValue = value ;
922+ break ;
923+ }
924+ }
925+ if ( ! goConstValue ) {
926+ throw new AdapterError (
927+ "InternalError" ,
928+ `failed to find const value for ${ constType . value } in const ${ goConstType . name } ` ,
929+ constType . __raw ?. node ,
930+ ) ;
931+ }
932+ const keyName = `literal-${ goConstValue . name } ` ;
918933 let literalConst = this . types . get ( keyName ) ;
919934 if ( literalConst ) {
920935 return < go . Literal > literalConst ;
921936 }
922- const constValue = this . constValues . get ( valueName ) ;
937+ const constValue = this . constValues . get ( goConstValue . name ) ;
923938 if ( ! constValue ) {
924939 throw new AdapterError (
925940 "InternalError" ,
Original file line number Diff line number Diff line change @@ -247,3 +247,30 @@ op payloadWithExplicitContentType(
247247 @ body
248248 thing : SomeModel ,
249249): void ;
250+
251+ union InboundCallerIdentityType {
252+ SystemAssigned : "SystemAssigned" ,
253+ UserAssigned : "UserAssigned" ,
254+ string ,
255+ }
256+
257+ @ discriminator ("type" )
258+ model InboundCallerIdentity {
259+ type : InboundCallerIdentityType ;
260+ }
261+
262+ model SystemAssignedInboundCallerIdentity extends InboundCallerIdentity {
263+ type : InboundCallerIdentityType .SystemAssigned ;
264+ }
265+
266+ model UserAssignedInboundCallerIdentity extends InboundCallerIdentity {
267+ type : InboundCallerIdentityType .UserAssigned ;
268+ userAssignedIdentity : string ;
269+ }
270+
271+ /**
272+ * gets a polymorphic type when the operation is internal (makes the dependent type graph internal)
273+ */
274+ @ access (Access .internal )
275+ @ route ("/get-caller-identity" )
276+ op getCallerIdentity (): InboundCallerIdentity ;
You can’t perform that action at this time.
0 commit comments