@@ -433,8 +433,8 @@ func scalarFieldType(f *api.Field) string {
433433 return out
434434}
435435
436- func oneOfFieldType (f * api.Field , state * api.APIState , modulePath , sourceSpecificationPackageName string , packageMapping map [ string ] * packagez ) string {
437- baseType := baseFieldType (f , state , modulePath , sourceSpecificationPackageName , packageMapping )
436+ func ( c * codec ) oneOfFieldType (f * api.Field , state * api.APIState , sourceSpecificationPackageName string ) string {
437+ baseType := c . baseFieldType (f , state , sourceSpecificationPackageName )
438438 return oneOfFieldTypeFormatter (f , language .FieldIsMap (f , state ), baseType )
439439}
440440
@@ -454,13 +454,13 @@ func oneOfFieldTypeFormatter(f *api.Field, fieldIsMap bool, baseType string) str
454454 }
455455}
456456
457- func fieldType (f * api.Field , state * api.APIState , primitive bool , modulePath , sourceSpecificationPackageName string , packageMapping map [ string ] * packagez ) string {
458- baseType := baseFieldType (f , state , modulePath , sourceSpecificationPackageName , packageMapping )
457+ func ( c * codec ) fieldType (f * api.Field , state * api.APIState , primitive bool , sourceSpecificationPackageName string ) string {
458+ baseType := c . baseFieldType (f , state , sourceSpecificationPackageName )
459459 switch {
460460 case primitive :
461461 return baseType
462462 case f .IsOneOf :
463- return oneOfFieldType (f , state , modulePath , sourceSpecificationPackageName , packageMapping )
463+ return c . oneOfFieldType (f , state , sourceSpecificationPackageName )
464464 case f .Repeated :
465465 return fmt .Sprintf ("std::vec::Vec<%s>" , baseType )
466466 case f .Recursive :
@@ -479,31 +479,31 @@ func fieldType(f *api.Field, state *api.APIState, primitive bool, modulePath, so
479479 }
480480}
481481
482- func mapType (f * api.Field , state * api.APIState , modulePath , sourceSpecificationPackageName string , packageMapping map [ string ] * packagez ) string {
482+ func ( c * codec ) mapType (f * api.Field , state * api.APIState , sourceSpecificationPackageName string ) string {
483483 switch f .Typez {
484484 case api .MESSAGE_TYPE :
485485 m , ok := state .MessageByID [f .TypezID ]
486486 if ! ok {
487487 slog .Error ("unable to lookup type" , "id" , f .TypezID , "field" , f .ID )
488488 return ""
489489 }
490- return fullyQualifiedMessageName (m , modulePath , sourceSpecificationPackageName , packageMapping )
490+ return c . fullyQualifiedMessageName (m , sourceSpecificationPackageName )
491491
492492 case api .ENUM_TYPE :
493493 e , ok := state .EnumByID [f .TypezID ]
494494 if ! ok {
495495 slog .Error ("unable to lookup type" , "id" , f .TypezID , "field" , f .ID )
496496 return ""
497497 }
498- return fullyQualifiedEnumName (e , modulePath , sourceSpecificationPackageName , packageMapping )
498+ return c . fullyQualifiedEnumName (e , sourceSpecificationPackageName )
499499 default :
500500 return scalarFieldType (f )
501501 }
502502}
503503
504504// baseFieldType returns the field type, ignoring any repeated or optional
505505// attributes.
506- func baseFieldType (f * api.Field , state * api.APIState , modulePath , sourceSpecificationPackageName string , packageMapping map [ string ] * packagez ) string {
506+ func ( c * codec ) baseFieldType (f * api.Field , state * api.APIState , sourceSpecificationPackageName string ) string {
507507 switch f .Typez {
508508 case api .MESSAGE_TYPE :
509509 m , ok := state .MessageByID [f .TypezID ]
@@ -512,18 +512,18 @@ func baseFieldType(f *api.Field, state *api.APIState, modulePath, sourceSpecific
512512 return ""
513513 }
514514 if m .IsMap {
515- key := mapType (m .Fields [0 ], state , modulePath , sourceSpecificationPackageName , packageMapping )
516- val := mapType (m .Fields [1 ], state , modulePath , sourceSpecificationPackageName , packageMapping )
515+ key := c . mapType (m .Fields [0 ], state , sourceSpecificationPackageName )
516+ val := c . mapType (m .Fields [1 ], state , sourceSpecificationPackageName )
517517 return "std::collections::HashMap<" + key + "," + val + ">"
518518 }
519- return fullyQualifiedMessageName (m , modulePath , sourceSpecificationPackageName , packageMapping )
519+ return c . fullyQualifiedMessageName (m , sourceSpecificationPackageName )
520520 case api .ENUM_TYPE :
521521 e , ok := state .EnumByID [f .TypezID ]
522522 if ! ok {
523523 slog .Error ("unable to lookup type" , "id" , f .TypezID , "field" , f .ID )
524524 return ""
525525 }
526- return fullyQualifiedEnumName (e , modulePath , sourceSpecificationPackageName , packageMapping )
526+ return c . fullyQualifiedEnumName (e , sourceSpecificationPackageName )
527527 case api .GROUP_TYPE :
528528 return ""
529529 default :
@@ -586,16 +586,16 @@ func (c *codec) methodInOutTypeName(id string, state *api.APIState, sourceSpecif
586586 slog .Error ("unable to lookup type" , "id" , id )
587587 return ""
588588 }
589- return fullyQualifiedMessageName (m , c . modulePath , sourceSpecificationPackageName , c . packageMapping )
589+ return c . fullyQualifiedMessageName (m , sourceSpecificationPackageName )
590590}
591591
592592// modelModule maps a package name in the model format (e.g. "google.cloud.longrunning") to the
593593// module name containing the model (e.g. "google_cloud_longrunning::model").
594- func modelModule (packageName string , modulePath , sourceSpecificationPackageName string , packageMapping map [ string ] * packagez ) string {
594+ func ( c * codec ) modelModule (packageName , sourceSpecificationPackageName string ) string {
595595 if packageName == sourceSpecificationPackageName {
596- return modulePath
596+ return c . modulePath
597597 }
598- mapped , ok := packageMapping [packageName ]
598+ mapped , ok := c . packageMapping [packageName ]
599599 if ! ok {
600600 return packageNameToRootModule (packageName )
601601 }
@@ -606,9 +606,9 @@ func modelModule(packageName string, modulePath, sourceSpecificationPackageName
606606 return packageNameToRootModule (mapped .name ) + "::model"
607607}
608608
609- func messageScopeName (m * api.Message , childPackageName , modulePath , sourceSpecificationPackageName string , packageMapping map [ string ] * packagez ) string {
609+ func ( c * codec ) messageScopeName (m * api.Message , childPackageName , sourceSpecificationPackageName string ) string {
610610 rustPkg := func (packageName string ) string {
611- return modelModule (packageName , modulePath , sourceSpecificationPackageName , packageMapping )
611+ return c . modelModule (packageName , sourceSpecificationPackageName )
612612 }
613613
614614 if m == nil {
@@ -617,23 +617,23 @@ func messageScopeName(m *api.Message, childPackageName, modulePath, sourceSpecif
617617 if m .Parent == nil {
618618 return rustPkg (m .Package ) + "::" + toSnake (m .Name )
619619 }
620- return messageScopeName (m .Parent , m .Package , modulePath , sourceSpecificationPackageName , packageMapping ) + "::" + toSnake (m .Name )
620+ return c . messageScopeName (m .Parent , m .Package , sourceSpecificationPackageName ) + "::" + toSnake (m .Name )
621621}
622622
623- func enumScopeName (e * api.Enum , modulePath , sourceSpecificationPackageName string , packageMapping map [ string ] * packagez ) string {
624- return messageScopeName (e .Parent , e .Package , modulePath , sourceSpecificationPackageName , packageMapping )
623+ func ( c * codec ) enumScopeName (e * api.Enum , sourceSpecificationPackageName string ) string {
624+ return c . messageScopeName (e .Parent , e .Package , sourceSpecificationPackageName )
625625}
626626
627- func fullyQualifiedMessageName (m * api.Message , modulePath , sourceSpecificationPackageName string , packageMapping map [ string ] * packagez ) string {
628- return messageScopeName (m .Parent , m .Package , modulePath , sourceSpecificationPackageName , packageMapping ) + "::" + toPascal (m .Name )
627+ func ( c * codec ) fullyQualifiedMessageName (m * api.Message , sourceSpecificationPackageName string ) string {
628+ return c . messageScopeName (m .Parent , m .Package , sourceSpecificationPackageName ) + "::" + toPascal (m .Name )
629629}
630630
631631func enumName (e * api.Enum ) string {
632632 return toPascal (e .Name )
633633}
634634
635- func fullyQualifiedEnumName (e * api.Enum , modulePath , sourceSpecificationPackageName string , packageMapping map [ string ] * packagez ) string {
636- return messageScopeName (e .Parent , e .Package , modulePath , sourceSpecificationPackageName , packageMapping ) + "::" + toPascal (e .Name )
635+ func ( c * codec ) fullyQualifiedEnumName (e * api.Enum , sourceSpecificationPackageName string ) string {
636+ return c . messageScopeName (e .Parent , e .Package , sourceSpecificationPackageName ) + "::" + toPascal (e .Name )
637637}
638638
639639func enumValueName (e * api.EnumValue ) string {
@@ -698,8 +698,8 @@ func enumValueVariantName(e *api.EnumValue) string {
698698 return toPascal (e .Name )
699699}
700700
701- func fullyQualifiedEnumValueName (v * api.EnumValue , modulePath , sourceSpecificationPackageName string , packageMapping map [ string ] * packagez ) string {
702- return fmt .Sprintf ("%s::%s::%s" , enumScopeName (v .Parent , modulePath , sourceSpecificationPackageName , packageMapping ), enumName (v .Parent ), enumValueVariantName (v ))
701+ func ( c * codec ) fullyQualifiedEnumValueName (v * api.EnumValue , sourceSpecificationPackageName string ) string {
702+ return fmt .Sprintf ("%s::%s::%s" , c . enumScopeName (v .Parent , sourceSpecificationPackageName ), enumName (v .Parent ), enumValueVariantName (v ))
703703}
704704
705705func bodyAccessor (m * api.Method ) string {
@@ -1234,11 +1234,11 @@ func (c *codec) docLink(link string, state *api.APIState, scopes []string) strin
12341234func (c * codec ) tryDocLinkWithId (id string , state * api.APIState , scope string ) string {
12351235 m , ok := state .MessageByID [id ]
12361236 if ok {
1237- return fullyQualifiedMessageName (m , c . modulePath , scope , c . packageMapping )
1237+ return c . fullyQualifiedMessageName (m , scope )
12381238 }
12391239 e , ok := state .EnumByID [id ]
12401240 if ok {
1241- return fullyQualifiedEnumName (e , c . modulePath , scope , c . packageMapping )
1241+ return c . fullyQualifiedEnumName (e , scope )
12421242 }
12431243 me , ok := state .MethodByID [id ]
12441244 if ok {
@@ -1273,15 +1273,15 @@ func (c *codec) tryFieldRustdocLink(id string, state *api.APIState, scope string
12731273 for _ , f := range m .Fields {
12741274 if f .Name == fieldName {
12751275 if ! f .IsOneOf {
1276- return fmt .Sprintf ("%s::%s" , fullyQualifiedMessageName (m , c . modulePath , scope , c . packageMapping ), toSnakeNoMangling (f .Name ))
1276+ return fmt .Sprintf ("%s::%s" , c . fullyQualifiedMessageName (m , scope ), toSnakeNoMangling (f .Name ))
12771277 } else {
12781278 return c .tryOneOfRustdocLink (f , m , scope )
12791279 }
12801280 }
12811281 }
12821282 for _ , o := range m .OneOfs {
12831283 if o .Name == fieldName {
1284- return fmt .Sprintf ("%s::%s" , fullyQualifiedMessageName (m , c . modulePath , scope , c . packageMapping ), toSnakeNoMangling (o .Name ))
1284+ return fmt .Sprintf ("%s::%s" , c . fullyQualifiedMessageName (m , scope ), toSnakeNoMangling (o .Name ))
12851285 }
12861286 }
12871287 return ""
@@ -1291,7 +1291,7 @@ func (c *codec) tryOneOfRustdocLink(field *api.Field, message *api.Message, scop
12911291 for _ , o := range message .OneOfs {
12921292 for _ , f := range o .Fields {
12931293 if f .ID == field .ID {
1294- return fmt .Sprintf ("%s::%s" , fullyQualifiedMessageName (message , c . modulePath , scope , c . packageMapping ), toSnakeNoMangling (o .Name ))
1294+ return fmt .Sprintf ("%s::%s" , c . fullyQualifiedMessageName (message , scope ), toSnakeNoMangling (o .Name ))
12951295 }
12961296 }
12971297 }
@@ -1311,7 +1311,7 @@ func (c *codec) tryEnumValueRustdocLink(id string, state *api.APIState, scope st
13111311 }
13121312 for _ , v := range e .Values {
13131313 if v .Name == valueName {
1314- return fullyQualifiedEnumValueName (v , c . modulePath , scope , c . packageMapping )
1314+ return c . fullyQualifiedEnumValueName (v , scope )
13151315 }
13161316 }
13171317 return ""
0 commit comments