diff --git a/generator/internal/language/golang/golang.go b/generator/internal/language/golang.go similarity index 76% rename from generator/internal/language/golang/golang.go rename to generator/internal/language/golang.go index fefbcdf79..a1554a516 100644 --- a/generator/internal/language/golang/golang.go +++ b/generator/internal/language/golang.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package golang +package language import ( "fmt" @@ -25,11 +25,11 @@ import ( "github.com/iancoleman/strcase" ) -func NewCodec(copts *genclient.CodecOptions) (*Codec, error) { +func NewGoCodec(copts *genclient.CodecOptions) (*GoCodec, error) { year, _, _ := time.Now().Date() - codec := &Codec{ + codec := &GoCodec{ GenerationYear: fmt.Sprintf("%04d", year), - ImportMap: map[string]*Import{}, + ImportMap: map[string]*GoImport{}, } for key, definition := range copts.Options { switch { @@ -46,7 +46,7 @@ func NewCodec(copts *genclient.CodecOptions) (*Codec, error) { if len(defs) != 2 { return nil, fmt.Errorf("%s should be in the format path;name, got=%q", definition, keys[1]) } - codec.ImportMap[keys[1]] = &Import{ + codec.ImportMap[keys[1]] = &GoImport{ Path: defs[0], Name: defs[1], } @@ -55,7 +55,7 @@ func NewCodec(copts *genclient.CodecOptions) (*Codec, error) { return codec, nil } -type Codec struct { +type GoCodec struct { // The source package name (e.g. google.iam.v1 in Protobuf). The codec can // generate code for one source package at a time. SourceSpecificationPackageName string @@ -66,15 +66,15 @@ type Codec struct { // The package name to generate code into GoPackageName string // A map containing package id to import path information - ImportMap map[string]*Import + ImportMap map[string]*GoImport } -type Import struct { +type GoImport struct { Path string Name string } -func (c *Codec) LoadWellKnownTypes(s *genclient.APIState) { +func (c *GoCodec) LoadWellKnownTypes(s *genclient.APIState) { timestamp := &genclient.Message{ ID: ".google.protobuf.Timestamp", Name: "Time", @@ -89,11 +89,11 @@ func (c *Codec) LoadWellKnownTypes(s *genclient.APIState) { s.MessageByID[duration.ID] = duration } -func (*Codec) FieldAttributes(*genclient.Field, *genclient.APIState) []string { +func (*GoCodec) FieldAttributes(*genclient.Field, *genclient.APIState) []string { return []string{} } -func (c *Codec) FieldType(f *genclient.Field, state *genclient.APIState) string { +func (c *GoCodec) FieldType(f *genclient.Field, state *genclient.APIState) string { var out string switch f.Typez { case genclient.STRING_TYPE: @@ -132,15 +132,15 @@ func (c *Codec) FieldType(f *genclient.Field, state *genclient.APIState) string return out } -func (c *Codec) AsQueryParameter(f *genclient.Field, state *genclient.APIState) string { +func (c *GoCodec) AsQueryParameter(f *genclient.Field, state *genclient.APIState) string { return fmt.Sprintf("req.%s.to_str()", c.ToCamel(f.Name)) } -func (c *Codec) TemplateDir() string { +func (c *GoCodec) TemplateDir() string { return "go" } -func (c *Codec) MethodInOutTypeName(id string, s *genclient.APIState) string { +func (c *GoCodec) MethodInOutTypeName(id string, s *genclient.APIState) string { if id == "" { return "" } @@ -152,11 +152,11 @@ func (c *Codec) MethodInOutTypeName(id string, s *genclient.APIState) string { return strcase.ToCamel(m.Name) } -func (*Codec) MessageAttributes(*genclient.Message, *genclient.APIState) []string { +func (*GoCodec) MessageAttributes(*genclient.Message, *genclient.APIState) []string { return []string{} } -func (c *Codec) MessageName(m *genclient.Message, state *genclient.APIState) string { +func (c *GoCodec) MessageName(m *genclient.Message, state *genclient.APIState) string { if m.Parent != nil { return c.MessageName(m.Parent, state) + "_" + strcase.ToCamel(m.Name) } @@ -166,37 +166,37 @@ func (c *Codec) MessageName(m *genclient.Message, state *genclient.APIState) str return c.ToPascal(m.Name) } -func (c *Codec) FQMessageName(m *genclient.Message, state *genclient.APIState) string { +func (c *GoCodec) FQMessageName(m *genclient.Message, state *genclient.APIState) string { return c.MessageName(m, state) } -func (c *Codec) EnumName(e *genclient.Enum, state *genclient.APIState) string { +func (c *GoCodec) EnumName(e *genclient.Enum, state *genclient.APIState) string { if e.Parent != nil { return c.MessageName(e.Parent, state) + "_" + strcase.ToCamel(e.Name) } return strcase.ToCamel(e.Name) } -func (c *Codec) FQEnumName(e *genclient.Enum, state *genclient.APIState) string { +func (c *GoCodec) FQEnumName(e *genclient.Enum, state *genclient.APIState) string { return c.EnumName(e, state) } -func (c *Codec) EnumValueName(e *genclient.EnumValue, state *genclient.APIState) string { +func (c *GoCodec) EnumValueName(e *genclient.EnumValue, state *genclient.APIState) string { if e.Parent.Parent != nil { return c.MessageName(e.Parent.Parent, state) + "_" + strings.ToUpper(e.Name) } return strings.ToUpper(e.Name) } -func (c *Codec) FQEnumValueName(v *genclient.EnumValue, state *genclient.APIState) string { +func (c *GoCodec) FQEnumValueName(v *genclient.EnumValue, state *genclient.APIState) string { return c.EnumValueName(v, state) } -func (c *Codec) OneOfType(o *genclient.OneOf, _ *genclient.APIState) string { +func (c *GoCodec) OneOfType(o *genclient.OneOf, _ *genclient.APIState) string { panic("not needed for Go") } -func (c *Codec) BodyAccessor(m *genclient.Method, state *genclient.APIState) string { +func (c *GoCodec) BodyAccessor(m *genclient.Method, state *genclient.APIState) string { if m.PathInfo.BodyFieldPath == "*" { // no accessor needed, use the whole request return "" @@ -204,7 +204,7 @@ func (c *Codec) BodyAccessor(m *genclient.Method, state *genclient.APIState) str return "." + strcase.ToCamel(m.PathInfo.BodyFieldPath) } -func (c *Codec) HTTPPathFmt(m *genclient.PathInfo, state *genclient.APIState) string { +func (c *GoCodec) HTTPPathFmt(m *genclient.PathInfo, state *genclient.APIState) string { fmt := "" for _, segment := range m.PathTemplate { if segment.Literal != nil { @@ -218,7 +218,7 @@ func (c *Codec) HTTPPathFmt(m *genclient.PathInfo, state *genclient.APIState) st return fmt } -func (c *Codec) HTTPPathArgs(h *genclient.PathInfo, state *genclient.APIState) []string { +func (c *GoCodec) HTTPPathArgs(h *genclient.PathInfo, state *genclient.APIState) []string { var args []string // TODO(codyoss): https://github.com/googleapis/google-cloud-rust/issues/34 for _, segment := range h.PathTemplate { @@ -230,7 +230,7 @@ func (c *Codec) HTTPPathArgs(h *genclient.PathInfo, state *genclient.APIState) [ return args } -func (c *Codec) QueryParams(m *genclient.Method, state *genclient.APIState) []*genclient.Field { +func (c *GoCodec) QueryParams(m *genclient.Method, state *genclient.APIState) []*genclient.Field { msg, ok := state.MessageByID[m.InputTypeID] if !ok { slog.Error("unable to lookup type", "id", m.InputTypeID) @@ -247,26 +247,26 @@ func (c *Codec) QueryParams(m *genclient.Method, state *genclient.APIState) []*g return queryParams } -func (c *Codec) ToSnake(symbol string) string { - return EscapeKeyword(c.ToSnakeNoMangling(symbol)) +func (c *GoCodec) ToSnake(symbol string) string { + return goEscapeKeyword(c.ToSnakeNoMangling(symbol)) } -func (*Codec) ToSnakeNoMangling(symbol string) string { +func (*GoCodec) ToSnakeNoMangling(symbol string) string { if strings.ToLower(symbol) == symbol { - return EscapeKeyword(symbol) + return goEscapeKeyword(symbol) } - return EscapeKeyword(strcase.ToSnake(symbol)) + return goEscapeKeyword(strcase.ToSnake(symbol)) } -func (*Codec) ToPascal(symbol string) string { - return EscapeKeyword(strcase.ToCamel(symbol)) +func (*GoCodec) ToPascal(symbol string) string { + return goEscapeKeyword(strcase.ToCamel(symbol)) } -func (*Codec) ToCamel(symbol string) string { +func (*GoCodec) ToCamel(symbol string) string { return strcase.ToLowerCamel(symbol) } -func (*Codec) FormatDocComments(documentation string) []string { +func (*GoCodec) FormatDocComments(documentation string) []string { ss := strings.Split(documentation, "\n") for i := range ss { ss[i] = strings.TrimRightFunc(ss[i], unicode.IsSpace) @@ -274,22 +274,22 @@ func (*Codec) FormatDocComments(documentation string) []string { return ss } -func (*Codec) RequiredPackages() []string { +func (*GoCodec) RequiredPackages() []string { return []string{} } -func (c *Codec) CopyrightYear() string { +func (c *GoCodec) CopyrightYear() string { return c.GenerationYear } -func (c *Codec) PackageName(api *genclient.API) string { +func (c *GoCodec) PackageName(api *genclient.API) string { if len(c.PackageNameOverride) > 0 { return c.PackageNameOverride } return api.Name } -func (c *Codec) validatePackageName(newPackage, elementName string) error { +func (c *GoCodec) validatePackageName(newPackage, elementName string) error { if c.SourceSpecificationPackageName == newPackage { return nil } @@ -306,7 +306,7 @@ func (c *Codec) validatePackageName(newPackage, elementName string) error { c.SourceSpecificationPackageName, newPackage, elementName) } -func (c *Codec) Validate(api *genclient.API) error { +func (c *GoCodec) Validate(api *genclient.API) error { // Set the source package. We should always take the first service registered // as the source package. Services with mixes will register those after the // source package. @@ -337,13 +337,13 @@ type GoContext struct { GoPackage string } -func (c *Codec) AdditionalContext() any { +func (c *GoCodec) AdditionalContext() any { return GoContext{ GoPackage: c.GoPackageName, } } -func (c *Codec) Imports() []string { +func (c *GoCodec) Imports() []string { var imports []string for _, imp := range c.ImportMap { imports = append(imports, fmt.Sprintf("%q", imp.Path)) @@ -354,7 +354,7 @@ func (c *Codec) Imports() []string { // The list of Golang keywords and reserved words can be found at: // // https://go.dev/ref/spec#Keywords -func EscapeKeyword(symbol string) string { +func goEscapeKeyword(symbol string) string { keywords := map[string]bool{ "break": true, "default": true, diff --git a/generator/internal/language/golang/golang_test.go b/generator/internal/language/golang_test.go similarity index 90% rename from generator/internal/language/golang/golang_test.go rename to generator/internal/language/golang_test.go index b3c00a67d..2e8bdd4e7 100644 --- a/generator/internal/language/golang/golang_test.go +++ b/generator/internal/language/golang_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package golang +package language import ( "testing" @@ -21,14 +21,14 @@ import ( "github.com/googleapis/google-cloud-rust/generator/internal/genclient" ) -type CaseConvertTest struct { +type goCaseConvertTest struct { Input string Expected string } -func TestToSnake(t *testing.T) { - c := &Codec{} - var snakeConvertTests = []CaseConvertTest{ +func TestGo_ToSnake(t *testing.T) { + c := &GoCodec{} + var snakeConvertTests = []goCaseConvertTest{ {"FooBar", "foo_bar"}, {"foo_bar", "foo_bar"}, {"data_crc32c", "data_crc32c"}, @@ -42,9 +42,9 @@ func TestToSnake(t *testing.T) { } } -func TestToPascal(t *testing.T) { - c := &Codec{} - var pascalConvertTests = []CaseConvertTest{ +func TestGo_ToPascal(t *testing.T) { + c := &GoCodec{} + var pascalConvertTests = []goCaseConvertTest{ {"foo_bar", "FooBar"}, {"FooBar", "FooBar"}, {"True", "True"}, @@ -57,7 +57,7 @@ func TestToPascal(t *testing.T) { } } -func TestMessageNames(t *testing.T) { +func TestGo_MessageNames(t *testing.T) { message := &genclient.Message{ Name: "Replication", ID: "..Replication", @@ -78,7 +78,7 @@ func TestMessageNames(t *testing.T) { api := genclient.NewTestAPI([]*genclient.Message{message, nested}, []*genclient.Enum{}, []*genclient.Service{}) - c := &Codec{} + c := &GoCodec{} if got := c.MessageName(message, api.State); got != "Replication" { t.Errorf("mismatched message name, want=Replication, got=%s", got) } @@ -94,7 +94,7 @@ func TestMessageNames(t *testing.T) { } } -func TestEnumNames(t *testing.T) { +func TestGo_EnumNames(t *testing.T) { message := &genclient.Message{ Name: "SecretVersion", ID: "..SecretVersion", @@ -115,7 +115,7 @@ func TestEnumNames(t *testing.T) { api := genclient.NewTestAPI([]*genclient.Message{message}, []*genclient.Enum{nested}, []*genclient.Service{}) - c := &Codec{} + c := &GoCodec{} if got := c.EnumName(nested, api.State); got != "SecretVersion_State" { t.Errorf("mismatched message name, want=SecretVersion_Automatic, got=%s", got) } @@ -124,11 +124,11 @@ func TestEnumNames(t *testing.T) { } } -func TestFormatDocComments(t *testing.T) { +func TestGo_FormatDocComments(t *testing.T) { input := `Some comments describing the thing. The next line has some extra trailing whitespace: - + We want to respect whitespace at the beginning, because it important in Markdown: - A thing - A nested thing @@ -162,19 +162,19 @@ Maybe they wanted to show some JSON: "}", "```", } - c := &Codec{} + c := &GoCodec{} got := c.FormatDocComments(input) if diff := cmp.Diff(want, got); diff != "" { t.Errorf("mismatch in FormatDocComments (-want, +got)\n:%s", diff) } } -func TestValidate(t *testing.T) { +func TestGo_Validate(t *testing.T) { api := genclient.NewTestAPI( []*genclient.Message{{Name: "m1", Package: "p1"}}, []*genclient.Enum{{Name: "e1", Package: "p1"}}, []*genclient.Service{{Name: "s1", Package: "p1"}}) - c := &Codec{} + c := &GoCodec{} if err := c.Validate(api); err != nil { t.Errorf("unexpected error in API validation %q", err) } @@ -183,12 +183,12 @@ func TestValidate(t *testing.T) { } } -func TestValidateMessageMismatch(t *testing.T) { +func TestGo_ValidateMessageMismatch(t *testing.T) { api := genclient.NewTestAPI( []*genclient.Message{{Name: "m1", Package: "p1"}, {Name: "m2", Package: "p2"}}, []*genclient.Enum{{Name: "e1", Package: "p1"}}, []*genclient.Service{{Name: "s1", Package: "p1"}}) - c := &Codec{} + c := &GoCodec{} if err := c.Validate(api); err == nil { t.Errorf("expected an error in API validation got=%s", c.SourceSpecificationPackageName) } @@ -197,7 +197,7 @@ func TestValidateMessageMismatch(t *testing.T) { []*genclient.Message{{Name: "m1", Package: "p1"}}, []*genclient.Enum{{Name: "e1", Package: "p1"}, {Name: "e2", Package: "p2"}}, []*genclient.Service{{Name: "s1", Package: "p1"}}) - c = &Codec{} + c = &GoCodec{} if err := c.Validate(api); err == nil { t.Errorf("expected an error in API validation got=%s", c.SourceSpecificationPackageName) } @@ -206,7 +206,7 @@ func TestValidateMessageMismatch(t *testing.T) { []*genclient.Message{{Name: "m1", Package: "p1"}}, []*genclient.Enum{{Name: "e1", Package: "p1"}}, []*genclient.Service{{Name: "s1", Package: "p1"}, {Name: "s2", Package: "p2"}}) - c = &Codec{} + c = &GoCodec{} if err := c.Validate(api); err == nil { t.Errorf("expected an error in API validation got=%s", c.SourceSpecificationPackageName) } diff --git a/generator/internal/language/rust/rust.go b/generator/internal/language/rust.go similarity index 86% rename from generator/internal/language/rust/rust.go rename to generator/internal/language/rust.go index 63f50b3e7..b8e1564f3 100644 --- a/generator/internal/language/rust/rust.go +++ b/generator/internal/language/rust.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rust +package language import ( "fmt" @@ -28,9 +28,9 @@ import ( "github.com/iancoleman/strcase" ) -func NewCodec(copts *genclient.CodecOptions) (*Codec, error) { +func NewRustCodec(copts *genclient.CodecOptions) (*RustCodec, error) { year, _, _ := time.Now().Date() - codec := &Codec{ + codec := &RustCodec{ GenerationYear: fmt.Sprintf("%04d", year), OutputDirectory: copts.OutDir, ModulePath: "model", @@ -107,7 +107,7 @@ func NewCodec(copts *genclient.CodecOptions) (*Codec, error) { return codec, nil } -type Codec struct { +type RustCodec struct { // The output directory relative to the project root. OutputDirectory string // Package name override. If not empty, overrides the default package name. @@ -154,7 +154,7 @@ type RustPackage struct { Features []string } -func (c *Codec) LoadWellKnownTypes(s *genclient.APIState) { +func (c *RustCodec) LoadWellKnownTypes(s *genclient.APIState) { // TODO(#77) - replace these placeholders with real types wellKnown := []*genclient.Message{ { @@ -229,7 +229,7 @@ func ScalarFieldType(f *genclient.Field) string { return out } -func (c *Codec) fieldFormatter(typez genclient.Typez) string { +func (c *RustCodec) fieldFormatter(typez genclient.Typez) string { switch typez { case genclient.INT64_TYPE, genclient.UINT64_TYPE, @@ -244,7 +244,7 @@ func (c *Codec) fieldFormatter(typez genclient.Typez) string { } } -func (c *Codec) fieldBaseAttributes(f *genclient.Field) []string { +func (c *RustCodec) fieldBaseAttributes(f *genclient.Field) []string { if f.Synthetic { return []string{`#[serde(skip)]`} } @@ -254,7 +254,7 @@ func (c *Codec) fieldBaseAttributes(f *genclient.Field) []string { return []string{} } -func (c *Codec) wrapperFieldAttributes(f *genclient.Field, defaultAttributes []string) []string { +func (c *RustCodec) wrapperFieldAttributes(f *genclient.Field, defaultAttributes []string) []string { var formatter string switch f.TypezID { case ".google.protobuf.BytesValue": @@ -269,7 +269,7 @@ func (c *Codec) wrapperFieldAttributes(f *genclient.Field, defaultAttributes []s return []string{fmt.Sprintf(`#[serde_as(as = "Option<%s>")]`, formatter)} } -func (c *Codec) FieldAttributes(f *genclient.Field, state *genclient.APIState) []string { +func (c *RustCodec) FieldAttributes(f *genclient.Field, state *genclient.APIState) []string { attributes := c.fieldBaseAttributes(f) switch f.Typez { case genclient.DOUBLE_TYPE, @@ -332,7 +332,7 @@ func (c *Codec) FieldAttributes(f *genclient.Field, state *genclient.APIState) [ } } -func (c *Codec) FieldType(f *genclient.Field, state *genclient.APIState) string { +func (c *RustCodec) FieldType(f *genclient.Field, state *genclient.APIState) string { if f.IsOneOf { return c.wrapOneOfField(f, c.baseFieldType(f, state)) } @@ -346,7 +346,7 @@ func (c *Codec) FieldType(f *genclient.Field, state *genclient.APIState) string } // Returns the field type, ignoring any repeated or optional attributes. -func (c *Codec) baseFieldType(f *genclient.Field, state *genclient.APIState) string { +func (c *RustCodec) baseFieldType(f *genclient.Field, state *genclient.APIState) string { if f.Typez == genclient.MESSAGE_TYPE { m, ok := state.MessageByID[f.TypezID] if !ok { @@ -374,14 +374,14 @@ func (c *Codec) baseFieldType(f *genclient.Field, state *genclient.APIState) str } -func (c *Codec) wrapOneOfField(f *genclient.Field, value string) string { +func (c *RustCodec) wrapOneOfField(f *genclient.Field, value string) string { if f.Typez == genclient.MESSAGE_TYPE { return fmt.Sprintf("(%s)", value) } return fmt.Sprintf("{ %s: %s }", c.ToSnake(f.Name), value) } -func (c *Codec) AsQueryParameter(f *genclient.Field, state *genclient.APIState) string { +func (c *RustCodec) AsQueryParameter(f *genclient.Field, state *genclient.APIState) string { if f.Typez == genclient.MESSAGE_TYPE { // Query parameters in nested messages are first converted to a // `serde_json::Value`` and then recursively merged into the request @@ -393,14 +393,14 @@ func (c *Codec) AsQueryParameter(f *genclient.Field, state *genclient.APIState) return fmt.Sprintf("&req.%s", c.ToSnake(f.Name)) } -func (c *Codec) TemplateDir() string { +func (c *RustCodec) TemplateDir() string { if c.GenerateModule { return "rust/mod" } return "rust/crate" } -func (c *Codec) MethodInOutTypeName(id string, state *genclient.APIState) string { +func (c *RustCodec) MethodInOutTypeName(id string, state *genclient.APIState) string { if id == "" { return "" } @@ -412,7 +412,7 @@ func (c *Codec) MethodInOutTypeName(id string, state *genclient.APIState) string return c.FQMessageName(m, state) } -func (c *Codec) rustPackage(packageName string) string { +func (c *RustCodec) rustPackage(packageName string) string { if packageName == c.SourceSpecificationPackageName { return "crate::" + c.ModulePath } @@ -428,7 +428,7 @@ func (c *Codec) rustPackage(packageName string) string { return mapped.Name + "::model" } -func (c *Codec) MessageAttributes(*genclient.Message, *genclient.APIState) []string { +func (c *RustCodec) MessageAttributes(*genclient.Message, *genclient.APIState) []string { serde := `#[serde(default, rename_all = "camelCase")]` if !c.DeserializeWithdDefaults { serde = `#[serde(rename_all = "camelCase")]` @@ -441,11 +441,11 @@ func (c *Codec) MessageAttributes(*genclient.Message, *genclient.APIState) []str } } -func (c *Codec) MessageName(m *genclient.Message, state *genclient.APIState) string { +func (c *RustCodec) MessageName(m *genclient.Message, state *genclient.APIState) string { return c.ToPascal(m.Name) } -func (c *Codec) messageScopeName(m *genclient.Message, childPackageName string) string { +func (c *RustCodec) messageScopeName(m *genclient.Message, childPackageName string) string { if m == nil { return c.rustPackage(childPackageName) } @@ -455,37 +455,37 @@ func (c *Codec) messageScopeName(m *genclient.Message, childPackageName string) return c.messageScopeName(m.Parent, m.Package) + "::" + c.ToSnake(m.Name) } -func (c *Codec) enumScopeName(e *genclient.Enum) string { +func (c *RustCodec) enumScopeName(e *genclient.Enum) string { return c.messageScopeName(e.Parent, "") } -func (c *Codec) FQMessageName(m *genclient.Message, _ *genclient.APIState) string { +func (c *RustCodec) FQMessageName(m *genclient.Message, _ *genclient.APIState) string { return c.messageScopeName(m.Parent, m.Package) + "::" + c.ToPascal(m.Name) } -func (c *Codec) EnumName(e *genclient.Enum, state *genclient.APIState) string { +func (c *RustCodec) EnumName(e *genclient.Enum, state *genclient.APIState) string { return c.ToPascal(e.Name) } -func (c *Codec) FQEnumName(e *genclient.Enum, _ *genclient.APIState) string { +func (c *RustCodec) FQEnumName(e *genclient.Enum, _ *genclient.APIState) string { return c.messageScopeName(e.Parent, "") + "::" + c.ToPascal(e.Name) } -func (c *Codec) EnumValueName(e *genclient.EnumValue, _ *genclient.APIState) string { +func (c *RustCodec) EnumValueName(e *genclient.EnumValue, _ *genclient.APIState) string { // The Protobuf naming convention is to use SCREAMING_SNAKE_CASE, we do not // need to change anything for Rust - return EscapeKeyword(e.Name) + return rustEscapeKeyword(e.Name) } -func (c *Codec) FQEnumValueName(v *genclient.EnumValue, state *genclient.APIState) string { +func (c *RustCodec) FQEnumValueName(v *genclient.EnumValue, state *genclient.APIState) string { return fmt.Sprintf("%s::%s::%s", c.enumScopeName(v.Parent), c.ToSnake(v.Parent.Name), c.EnumValueName(v, state)) } -func (c *Codec) OneOfType(o *genclient.OneOf, _ *genclient.APIState) string { +func (c *RustCodec) OneOfType(o *genclient.OneOf, _ *genclient.APIState) string { return c.messageScopeName(o.Parent, "") + "::" + c.ToPascal(o.Name) } -func (c *Codec) BodyAccessor(m *genclient.Method, state *genclient.APIState) string { +func (c *RustCodec) BodyAccessor(m *genclient.Method, state *genclient.APIState) string { if m.PathInfo.BodyFieldPath == "*" { // no accessor needed, use the whole request return "" @@ -493,7 +493,7 @@ func (c *Codec) BodyAccessor(m *genclient.Method, state *genclient.APIState) str return "." + c.ToSnake(m.PathInfo.BodyFieldPath) } -func (c *Codec) HTTPPathFmt(m *genclient.PathInfo, state *genclient.APIState) string { +func (c *RustCodec) HTTPPathFmt(m *genclient.PathInfo, state *genclient.APIState) string { fmt := "" for _, segment := range m.PathTemplate { if segment.Literal != nil { @@ -535,7 +535,7 @@ func (c *Codec) HTTPPathFmt(m *genclient.PathInfo, state *genclient.APIState) st // ``` // // and so on. -func (c *Codec) unwrapFieldPath(components []string, requestAccess string) (string, string) { +func (c *RustCodec) unwrapFieldPath(components []string, requestAccess string) (string, string) { if len(components) == 1 { return requestAccess + "." + c.ToSnake(components[0]), components[0] } @@ -544,13 +544,13 @@ func (c *Codec) unwrapFieldPath(components []string, requestAccess string) (stri return fmt.Sprintf("gax::path_parameter::PathParameter::required(%s, \"%s\").map_err(Error::other)?.%s", unwrap, name, last), "" } -func (c *Codec) derefFieldPath(fieldPath string) string { +func (c *RustCodec) derefFieldPath(fieldPath string) string { components := strings.Split(fieldPath, ".") unwrap, _ := c.unwrapFieldPath(components, "req") return unwrap } -func (c *Codec) HTTPPathArgs(h *genclient.PathInfo, state *genclient.APIState) []string { +func (c *RustCodec) HTTPPathArgs(h *genclient.PathInfo, state *genclient.APIState) []string { var args []string for _, arg := range h.PathTemplate { if arg.FieldPath != nil { @@ -560,7 +560,7 @@ func (c *Codec) HTTPPathArgs(h *genclient.PathInfo, state *genclient.APIState) [ return args } -func (c *Codec) QueryParams(m *genclient.Method, state *genclient.APIState) []*genclient.Field { +func (c *RustCodec) QueryParams(m *genclient.Method, state *genclient.APIState) []*genclient.Field { msg, ok := state.MessageByID[m.InputTypeID] if !ok { slog.Error("unable to lookup request type", "id", m.InputTypeID) @@ -583,11 +583,11 @@ func (c *Codec) QueryParams(m *genclient.Method, state *genclient.APIState) []*g // This type of conversion can easily introduce keywords. Consider // // `ToSnake("True") -> "true"` -func (c *Codec) ToSnake(symbol string) string { - return EscapeKeyword(c.ToSnakeNoMangling(symbol)) +func (c *RustCodec) ToSnake(symbol string) string { + return rustEscapeKeyword(c.ToSnakeNoMangling(symbol)) } -func (*Codec) ToSnakeNoMangling(symbol string) string { +func (*RustCodec) ToSnakeNoMangling(symbol string) string { if strings.ToLower(symbol) == symbol { return symbol } @@ -601,15 +601,15 @@ func (*Codec) ToSnakeNoMangling(symbol string) string { // This type of conversion rarely introduces keywords. The one example is // // `ToPascal("self") -> "Self"` -func (*Codec) ToPascal(symbol string) string { - return EscapeKeyword(strcase.ToCamel(symbol)) +func (*RustCodec) ToPascal(symbol string) string { + return rustEscapeKeyword(strcase.ToCamel(symbol)) } -func (*Codec) ToCamel(symbol string) string { - return EscapeKeyword(strcase.ToLowerCamel(symbol)) +func (*RustCodec) ToCamel(symbol string) string { + return rustEscapeKeyword(strcase.ToLowerCamel(symbol)) } -func (*Codec) FormatDocComments(documentation string) []string { +func (*RustCodec) FormatDocComments(documentation string) []string { inBlockQuote := false ss := strings.Split(documentation, "\n") for i := range ss { @@ -626,7 +626,7 @@ func (*Codec) FormatDocComments(documentation string) []string { return ss } -func (c *Codec) projectRoot() string { +func (c *RustCodec) projectRoot() string { if c.OutputDirectory == "" { return "" } @@ -637,7 +637,7 @@ func (c *Codec) projectRoot() string { return rel } -func (c *Codec) RequiredPackages() []string { +func (c *RustCodec) RequiredPackages() []string { lines := []string{} for _, pkg := range c.ExtraPackages { if pkg.Ignore { @@ -663,11 +663,11 @@ func (c *Codec) RequiredPackages() []string { return lines } -func (c *Codec) CopyrightYear() string { +func (c *RustCodec) CopyrightYear() string { return c.GenerationYear } -func (c *Codec) PackageName(api *genclient.API) string { +func (c *RustCodec) PackageName(api *genclient.API) string { if len(c.PackageNameOverride) > 0 { return c.PackageNameOverride } @@ -680,7 +680,7 @@ func (c *Codec) PackageName(api *genclient.API) string { return "gcp-sdk-" + name } -func (c *Codec) validatePackageName(newPackage, elementName string) error { +func (c *RustCodec) validatePackageName(newPackage, elementName string) error { if c.SourceSpecificationPackageName == newPackage { return nil } @@ -694,7 +694,7 @@ func (c *Codec) validatePackageName(newPackage, elementName string) error { c.SourceSpecificationPackageName, newPackage, elementName) } -func (c *Codec) Validate(api *genclient.API) error { +func (c *RustCodec) Validate(api *genclient.API) error { // Set the source package. We should always take the first service registered // as the source package. Services with mixins will register those after the // source package. @@ -721,18 +721,18 @@ func (c *Codec) Validate(api *genclient.API) error { return nil } -func (c *Codec) AdditionalContext() any { +func (c *RustCodec) AdditionalContext() any { return nil } -func (c *Codec) Imports() []string { +func (c *RustCodec) Imports() []string { return nil } // The list of Rust keywords and reserved words can be found at: // // https://doc.rust-lang.org/reference/keywords.html -func EscapeKeyword(symbol string) string { +func rustEscapeKeyword(symbol string) string { keywords := map[string]bool{ "as": true, "break": true, diff --git a/generator/internal/language/rust/rust_test.go b/generator/internal/language/rust_test.go similarity index 91% rename from generator/internal/language/rust/rust_test.go rename to generator/internal/language/rust_test.go index 5901be2e7..9e5003edd 100644 --- a/generator/internal/language/rust/rust_test.go +++ b/generator/internal/language/rust_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rust +package language import ( "fmt" @@ -24,14 +24,14 @@ import ( "github.com/googleapis/google-cloud-rust/generator/internal/genclient" ) -func testCodec() *Codec { +func createRustCodec() *RustCodec { wkt := &RustPackage{ Name: "gax_wkt", Package: "types", Path: "../../types", } - return &Codec{ + return &RustCodec{ ModulePath: "model", ExtraPackages: []*RustPackage{wkt}, PackageMapping: map[string]*RustPackage{ @@ -40,7 +40,7 @@ func testCodec() *Codec { } } -func TestParseOptions(t *testing.T) { +func TestRust_ParseOptions(t *testing.T) { copts := &genclient.CodecOptions{ Options: map[string]string{ "package-name-override": "test-only", @@ -50,7 +50,7 @@ func TestParseOptions(t *testing.T) { "package:gax": "package=gax,path=src/gax,feature=sdk_client", }, } - codec, err := NewCodec(copts) + codec, err := NewRustCodec(copts) if err != nil { t.Fatal(err) } @@ -59,7 +59,7 @@ func TestParseOptions(t *testing.T) { Package: "types", Path: "src/wkt", } - want := &Codec{ + want := &RustCodec{ PackageNameOverride: "test-only", GenerationYear: "2035", ModulePath: "alternative::generated", @@ -80,16 +80,16 @@ func TestParseOptions(t *testing.T) { "test-only": gp, }, } - if diff := cmp.Diff(want, codec, cmpopts.IgnoreFields(Codec{}, "ExtraPackages", "PackageMapping")); diff != "" { + if diff := cmp.Diff(want, codec, cmpopts.IgnoreFields(RustCodec{}, "ExtraPackages", "PackageMapping")); diff != "" { t.Errorf("codec mismatch (-want, +got):\n%s", diff) } if want.PackageNameOverride != codec.PackageNameOverride { t.Errorf("mismatched in packageNameOverride, want=%s, got=%s", want.PackageNameOverride, codec.PackageNameOverride) } - checkPackages(t, codec, want) + checkRustPackages(t, codec, want) } -func TestRequiredPackages(t *testing.T) { +func TestRust_RequiredPackages(t *testing.T) { copts := &genclient.CodecOptions{ OutDir: "src/generated/newlib", Options: map[string]string{ @@ -98,7 +98,7 @@ func TestRequiredPackages(t *testing.T) { "package:auth": "ignore=true", }, } - codec, err := NewCodec(copts) + codec, err := NewRustCodec(copts) if err != nil { t.Fatal(err) } @@ -113,7 +113,7 @@ func TestRequiredPackages(t *testing.T) { } } -func TestRequiredPackagesLocal(t *testing.T) { +func TestRust_RequiredPackagesLocal(t *testing.T) { // This is not a thing we expect to do in the Rust repository, but the // behavior is consistent. copts := &genclient.CodecOptions{ @@ -122,7 +122,7 @@ func TestRequiredPackagesLocal(t *testing.T) { "package:gtype": "package=types,path=src/generated/type,source=google.type,source=test-only", }, } - codec, err := NewCodec(copts) + codec, err := NewRustCodec(copts) if err != nil { t.Fatal(err) } @@ -136,8 +136,8 @@ func TestRequiredPackagesLocal(t *testing.T) { } } -func TestPackageName(t *testing.T) { - packageNameImpl(t, "test-only-overridden", &genclient.CodecOptions{ +func TestRust_PackageName(t *testing.T) { + rustPackageNameImpl(t, "test-only-overridden", &genclient.CodecOptions{ Options: map[string]string{ "package-name-override": "test-only-overridden", }, @@ -145,19 +145,19 @@ func TestPackageName(t *testing.T) { Name: "test-only-name", PackageName: "google.cloud.service.v3", }) - packageNameImpl(t, "gcp-sdk-service-v3", &genclient.CodecOptions{}, &genclient.API{ + rustPackageNameImpl(t, "gcp-sdk-service-v3", &genclient.CodecOptions{}, &genclient.API{ Name: "test-only-name", PackageName: "google.cloud.service.v3", }) - packageNameImpl(t, "gcp-sdk-type", &genclient.CodecOptions{}, &genclient.API{ + rustPackageNameImpl(t, "gcp-sdk-type", &genclient.CodecOptions{}, &genclient.API{ Name: "type", PackageName: "", }) } -func packageNameImpl(t *testing.T, want string, copts *genclient.CodecOptions, api *genclient.API) { +func rustPackageNameImpl(t *testing.T, want string, copts *genclient.CodecOptions, api *genclient.API) { t.Helper() - codec, err := NewCodec(copts) + codec, err := NewRustCodec(copts) if err != nil { t.Fatal(err) } @@ -168,7 +168,7 @@ func packageNameImpl(t *testing.T, want string, copts *genclient.CodecOptions, a } -func checkPackages(t *testing.T, got *Codec, want *Codec) { +func checkRustPackages(t *testing.T, got *RustCodec, want *RustCodec) { t.Helper() less := func(a, b *RustPackage) bool { return a.Name < b.Name } if diff := cmp.Diff(want.ExtraPackages, got.ExtraPackages, cmpopts.SortSlices(less)); diff != "" { @@ -176,12 +176,12 @@ func checkPackages(t *testing.T, got *Codec, want *Codec) { } } -func TestValidate(t *testing.T) { +func TestRust_Validate(t *testing.T) { api := genclient.NewTestAPI( []*genclient.Message{{Name: "m1", Package: "p1"}}, []*genclient.Enum{{Name: "e1", Package: "p1"}}, []*genclient.Service{{Name: "s1", Package: "p1"}}) - c := &Codec{} + c := &RustCodec{} if err := c.Validate(api); err != nil { t.Errorf("unexpected error in API validation %q", err) } @@ -190,12 +190,12 @@ func TestValidate(t *testing.T) { } } -func TestValidateMessageMismatch(t *testing.T) { +func TestRust_ValidateMessageMismatch(t *testing.T) { api := genclient.NewTestAPI( []*genclient.Message{{Name: "m1", Package: "p1"}, {Name: "m2", Package: "p2"}}, []*genclient.Enum{{Name: "e1", Package: "p1"}}, []*genclient.Service{{Name: "s1", Package: "p1"}}) - c := &Codec{} + c := &RustCodec{} if err := c.Validate(api); err == nil { t.Errorf("expected an error in API validation got=%s", c.SourceSpecificationPackageName) } @@ -204,7 +204,7 @@ func TestValidateMessageMismatch(t *testing.T) { []*genclient.Message{{Name: "m1", Package: "p1"}}, []*genclient.Enum{{Name: "e1", Package: "p1"}, {Name: "e2", Package: "p2"}}, []*genclient.Service{{Name: "s1", Package: "p1"}}) - c = &Codec{} + c = &RustCodec{} if err := c.Validate(api); err == nil { t.Errorf("expected an error in API validation got=%s", c.SourceSpecificationPackageName) } @@ -213,7 +213,7 @@ func TestValidateMessageMismatch(t *testing.T) { []*genclient.Message{{Name: "m1", Package: "p1"}}, []*genclient.Enum{{Name: "e1", Package: "p1"}}, []*genclient.Service{{Name: "s1", Package: "p1"}, {Name: "s2", Package: "p2"}}) - c = &Codec{} + c = &RustCodec{} if err := c.Validate(api); err == nil { t.Errorf("expected an error in API validation got=%s", c.SourceSpecificationPackageName) } @@ -221,7 +221,7 @@ func TestValidateMessageMismatch(t *testing.T) { func TestWellKnownTypesExist(t *testing.T) { api := genclient.NewTestAPI([]*genclient.Message{}, []*genclient.Enum{}, []*genclient.Service{}) - c := &Codec{} + c := &RustCodec{} c.LoadWellKnownTypes(api.State) for _, name := range []string{"Any", "Duration", "Empty", "FieldMask", "Timestamp"} { if _, ok := api.State.MessageByID[fmt.Sprintf(".google.protobuf.%s", name)]; !ok { @@ -230,9 +230,9 @@ func TestWellKnownTypesExist(t *testing.T) { } } -func TestWellKnownTypesAsMethod(t *testing.T) { +func TestRust_WellKnownTypesAsMethod(t *testing.T) { api := genclient.NewTestAPI([]*genclient.Message{}, []*genclient.Enum{}, []*genclient.Service{}) - c := testCodec() + c := createRustCodec() c.LoadWellKnownTypes(api.State) want := "gax_wkt::Empty" @@ -242,7 +242,7 @@ func TestWellKnownTypesAsMethod(t *testing.T) { } } -func TestMethodInOut(t *testing.T) { +func TestRust_MethodInOut(t *testing.T) { message := &genclient.Message{ Name: "Target", ID: "..Target", @@ -253,7 +253,7 @@ func TestMethodInOut(t *testing.T) { Parent: message, } api := genclient.NewTestAPI([]*genclient.Message{message, nested}, []*genclient.Enum{}, []*genclient.Service{}) - c := testCodec() + c := createRustCodec() c.LoadWellKnownTypes(api.State) want := "crate::model::Target" @@ -269,7 +269,7 @@ func TestMethodInOut(t *testing.T) { } } -func TestFieldAttributes(t *testing.T) { +func TestRust_FieldAttributes(t *testing.T) { message := &genclient.Message{ Name: "Fake", ID: "..Fake", @@ -356,7 +356,7 @@ func TestFieldAttributes(t *testing.T) { "f_string_optional": ``, "f_string_repeated": ``, } - c := testCodec() + c := createRustCodec() c.LoadWellKnownTypes(api.State) for _, field := range message.Fields { want, ok := expectedAttributes[field.Name] @@ -370,7 +370,7 @@ func TestFieldAttributes(t *testing.T) { } } -func TestMapFieldAttributes(t *testing.T) { +func TestRust_MapFieldAttributes(t *testing.T) { target := &genclient.Message{ Name: "Target", ID: "..Target", @@ -484,7 +484,7 @@ func TestMapFieldAttributes(t *testing.T) { "map_i64_key": `#[serde(skip_serializing_if = "std::collections::HashMap::is_empty")]` + "\n" + `#[serde_as(as = "std::collections::HashMap")]`, "map_bytes": `#[serde(skip_serializing_if = "std::collections::HashMap::is_empty")]` + "\n" + `#[serde_as(as = "std::collections::HashMap<_, serde_with::base64::Base64>")]`, } - c := testCodec() + c := createRustCodec() c.LoadWellKnownTypes(api.State) for _, field := range message.Fields { want, ok := expectedAttributes[field.Name] @@ -498,7 +498,7 @@ func TestMapFieldAttributes(t *testing.T) { } } -func TestWktFieldAttributes(t *testing.T) { +func TestRust_WktFieldAttributes(t *testing.T) { message := &genclient.Message{ Name: "Fake", ID: "..Fake", @@ -541,7 +541,7 @@ func TestWktFieldAttributes(t *testing.T) { "f_bytes": `#[serde_as(as = "Option")]`, "f_string": ``, } - c := testCodec() + c := createRustCodec() c.LoadWellKnownTypes(api.State) for _, field := range message.Fields { want, ok := expectedAttributes[field.Name] @@ -555,7 +555,7 @@ func TestWktFieldAttributes(t *testing.T) { } } -func TestFieldLossyName(t *testing.T) { +func TestRust_FieldLossyName(t *testing.T) { message := &genclient.Message{ Name: "SecretPayload", ID: "..SecretPayload", @@ -584,7 +584,7 @@ func TestFieldLossyName(t *testing.T) { "data": `#[serde_as(as = "serde_with::base64::Base64")]`, "dataCrc32c": `#[serde(rename = "dataCrc32c")]` + "\n" + `#[serde_as(as = "Option")]`, } - c := testCodec() + c := createRustCodec() c.LoadWellKnownTypes(api.State) for _, field := range message.Fields { want, ok := expectedAttributes[field.Name] @@ -598,7 +598,7 @@ func TestFieldLossyName(t *testing.T) { } } -func TestSyntheticField(t *testing.T) { +func TestRust_SyntheticField(t *testing.T) { message := &genclient.Message{ Name: "Unused", ID: "..Unused", @@ -633,7 +633,7 @@ func TestSyntheticField(t *testing.T) { "project": `#[serde(skip)]`, "data_crc32c": `#[serde(skip)]`, } - c := testCodec() + c := createRustCodec() c.LoadWellKnownTypes(api.State) for _, field := range message.Fields { want, ok := expectedAttributes[field.Name] @@ -647,7 +647,7 @@ func TestSyntheticField(t *testing.T) { } } -func TestFieldType(t *testing.T) { +func TestRust_FieldType(t *testing.T) { target := &genclient.Message{ Name: "Target", ID: "..Target", @@ -715,7 +715,7 @@ func TestFieldType(t *testing.T) { "f_timestamp": "Option", "f_timestamp_repeated": "Vec", } - c := testCodec() + c := createRustCodec() c.LoadWellKnownTypes(api.State) for _, field := range message.Fields { want, ok := expectedTypes[field.Name] @@ -729,7 +729,7 @@ func TestFieldType(t *testing.T) { } } -func TestQueryParams(t *testing.T) { +func TestRust_QueryParams(t *testing.T) { options := &genclient.Message{ Name: "Options", ID: "..Options", @@ -780,7 +780,7 @@ func TestQueryParams(t *testing.T) { Methods: []*genclient.Method{method}, }, }) - c := testCodec() + c := createRustCodec() c.LoadWellKnownTypes(api.State) got := c.QueryParams(method, api.State) @@ -791,7 +791,7 @@ func TestQueryParams(t *testing.T) { } } -func TestAsQueryParameter(t *testing.T) { +func TestRust_AsQueryParameter(t *testing.T) { options := &genclient.Message{ Name: "Options", ID: "..Options", @@ -818,7 +818,7 @@ func TestAsQueryParameter(t *testing.T) { []*genclient.Message{options, request}, []*genclient.Enum{}, []*genclient.Service{}) - c := testCodec() + c := createRustCodec() c.LoadWellKnownTypes(api.State) want := "&serde_json::to_value(&req.options_field).map_err(Error::serde)?" @@ -835,14 +835,14 @@ func TestAsQueryParameter(t *testing.T) { } -type CaseConvertTest struct { +type rustCaseConvertTest struct { Input string Expected string } -func TestToSnake(t *testing.T) { - c := &Codec{} - var snakeConvertTests = []CaseConvertTest{ +func TestRust_ToSnake(t *testing.T) { + c := &RustCodec{} + var snakeConvertTests = []rustCaseConvertTest{ {"FooBar", "foo_bar"}, {"foo_bar", "foo_bar"}, {"data_crc32c", "data_crc32c"}, @@ -860,9 +860,9 @@ func TestToSnake(t *testing.T) { } } -func TestToPascal(t *testing.T) { - c := &Codec{} - var pascalConvertTests = []CaseConvertTest{ +func TestRust_ToPascal(t *testing.T) { + c := &RustCodec{} + var pascalConvertTests = []rustCaseConvertTest{ {"foo_bar", "FooBar"}, {"FooBar", "FooBar"}, {"True", "True"}, @@ -877,7 +877,7 @@ func TestToPascal(t *testing.T) { } } -func TestFormatDocComments(t *testing.T) { +func TestRust_FormatDocComments(t *testing.T) { input := `Some comments describing the thing. The next line has some extra trailing whitespace:` + " " + ` @@ -916,14 +916,14 @@ Maybe they wanted to show some JSON: "/// ```", } - c := &Codec{} + c := &RustCodec{} got := c.FormatDocComments(input) if diff := cmp.Diff(want, got); diff != "" { t.Errorf("mismatch in FormatDocComments (-want, +got)\n:%s", diff) } } -func TestFormatDocCommentsBullets(t *testing.T) { +func TestRust_FormatDocCommentsBullets(t *testing.T) { input := `In this example, in proto field could take one of the following values: * full_name for a violation in the full_name value @@ -941,14 +941,14 @@ func TestFormatDocCommentsBullets(t *testing.T) { "/// value in the third email_addresses message.)", } - c := testCodec() + c := createRustCodec() got := c.FormatDocComments(input) if diff := cmp.Diff(want, got); diff != "" { t.Errorf("mismatch in FormatDocComments (-want, +got)\n:%s", diff) } } -func TestMessageNames(t *testing.T) { +func TestRust_MessageNames(t *testing.T) { message := &genclient.Message{ Name: "Replication", ID: "..Replication", @@ -970,7 +970,7 @@ func TestMessageNames(t *testing.T) { api := genclient.NewTestAPI([]*genclient.Message{message, nested}, []*genclient.Enum{}, []*genclient.Service{}) - c := testCodec() + c := createRustCodec() if got := c.MessageName(message, api.State); got != "Replication" { t.Errorf("mismatched message name, got=%s, want=Replication", got) } @@ -986,7 +986,7 @@ func TestMessageNames(t *testing.T) { } } -func TestEnumNames(t *testing.T) { +func TestRust_EnumNames(t *testing.T) { message := &genclient.Message{ Name: "SecretVersion", ID: "..SecretVersion", @@ -1008,7 +1008,7 @@ func TestEnumNames(t *testing.T) { api := genclient.NewTestAPI([]*genclient.Message{message}, []*genclient.Enum{nested}, []*genclient.Service{}) - c := testCodec() + c := createRustCodec() if got := c.EnumName(nested, api.State); got != "State" { t.Errorf("mismatched message name, got=%s, want=Automatic", got) } diff --git a/generator/internal/sidekick/refresh.go b/generator/internal/sidekick/refresh.go index 565f66657..4151feadf 100644 --- a/generator/internal/sidekick/refresh.go +++ b/generator/internal/sidekick/refresh.go @@ -19,8 +19,7 @@ import ( "path" "github.com/googleapis/google-cloud-rust/generator/internal/genclient" - "github.com/googleapis/google-cloud-rust/generator/internal/language/golang" - "github.com/googleapis/google-cloud-rust/generator/internal/language/rust" + "github.com/googleapis/google-cloud-rust/generator/internal/language" "github.com/googleapis/google-cloud-rust/generator/internal/parser/openapi" "github.com/googleapis/google-cloud-rust/generator/internal/parser/protobuf" ) @@ -68,9 +67,9 @@ func refresh(rootConfig *Config, cmdLine *CommandLine, output string) error { ) switch config.General.Language { case "rust": - codec, err = rust.NewCodec(copts) + codec, err = language.NewRustCodec(copts) case "go": - codec, err = golang.NewCodec(copts) + codec, err = language.NewGoCodec(copts) default: return fmt.Errorf("unknown language: %s", config.General.Language) }