Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid code generation for top-level singletons #310

Open
vallahaye opened this issue Sep 8, 2024 · 0 comments · May be fixed by #311
Open

Invalid code generation for top-level singletons #310

vallahaye opened this issue Sep 8, 2024 · 0 comments · May be fixed by #311

Comments

@vallahaye
Copy link

vallahaye commented Sep 8, 2024

It seems that the code generated for top-level singletons with protoc-gen-aip-go@v0.68.0 is invalid. Specifically, the fmt and strings packages are imported but not used, resulting in compilation errors.

For example, the following proto:

message Config {
  option (google.api.resource) = {
    type: "test1.testdata/Config"
    singular: "config"
    plural: "configs"
    pattern: "config"
  };

  // The resource name of the config.
  string name = 1;
}

generates the following code:

// Code generated by protoc-gen-go-aip. DO NOT EDIT.
//
// versions:
// 	protoc-gen-go-aip development
// 	protoc (unknown)
// source: test/toplevelsingleton/testdata.proto

package toplevelsingleton

import (
	fmt "fmt"
	resourcename "go.einride.tech/aip/resourcename"
	strings "strings
)

type ConfigResourceName struct {
}

func (n ConfigResourceName) Validate() error {
	return nil
}

func (n ConfigResourceName) ContainsWildcard() bool {
	return false
}

func (n ConfigResourceName) String() string {
	return resourcename.Sprint(
		"config",
	)
}

func (n ConfigResourceName) MarshalString() (string, error) {
	if err := n.Validate(); err != nil {
		return "", err
	}
	return n.String(), nil
}

func (n *ConfigResourceName) UnmarshalString(name string) error {
	err := resourcename.Sscan(
		name,
		"config",
	)
	if err != nil {
		return err
	}
	return n.Validate()
}

which, when compiled, produces the following errors:

test/toplevelsingleton/testdata_aip.go:11:2: "fmt" imported and not used
test/toplevelsingleton/testdata_aip.go:13:2: "strings" imported and not used
vallahaye added a commit to vallahaye/aip-go that referenced this issue Sep 8, 2024
The `fmt` and `strings` packages are imported but not used, resulting in compilation errors.

Closes einride#310
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant