diff --git a/cmd/protoc-gen-go-aip/internal/genaip/resourcename.go b/cmd/protoc-gen-go-aip/internal/genaip/resourcename.go index 147cd81054..f7a45600e5 100644 --- a/cmd/protoc-gen-go-aip/internal/genaip/resourcename.go +++ b/cmd/protoc-gen-go-aip/internal/genaip/resourcename.go @@ -329,6 +329,9 @@ func (r resourceNameCodeGenerator) generateUnmarshalStringMethod( }) g.P() g.P("func (n *", typeName, ") UnmarshalString(name string) error {") + g.P("if err := n.Validate(); err != nil {") + g.P("return err") + g.P("}") g.P("return ", resourcenameSscan, "(") g.P("name,") g.P(strconv.Quote(pattern), ",") diff --git a/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/multipattern/testdata_aip.go b/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/multipattern/testdata_aip.go index aa5f429c88..64f6c43d6a 100644 --- a/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/multipattern/testdata_aip.go +++ b/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/multipattern/testdata_aip.go @@ -82,6 +82,9 @@ func (n ShelvesBookResourceName) MarshalString() (string, error) { } func (n *ShelvesBookResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "shelves/{shelf}/books/{book}", @@ -137,6 +140,9 @@ func (n PublishersBookResourceName) MarshalString() (string, error) { } func (n *PublishersBookResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "publishers/{publisher}/books/{book}", @@ -200,6 +206,9 @@ func (n ShelfResourceName) MarshalString() (string, error) { } func (n *ShelfResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "shelves/{shelf}", @@ -248,6 +257,9 @@ func (n LibrariesShelfResourceName) MarshalString() (string, error) { } func (n *LibrariesShelfResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "libraries/{library}/shelves/{shelf}", @@ -297,6 +309,9 @@ func (n RoomsShelfResourceName) MarshalString() (string, error) { } func (n *RoomsShelfResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "rooms/{room}/shelves/{shelf}", diff --git a/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/originallysinglepattern/testdata_aip.go b/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/originallysinglepattern/testdata_aip.go index 7f750cd4a7..222829c528 100644 --- a/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/originallysinglepattern/testdata_aip.go +++ b/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/originallysinglepattern/testdata_aip.go @@ -82,6 +82,9 @@ func (n BookResourceName) MarshalString() (string, error) { } func (n *BookResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "shelves/{shelf}/books/{book}", @@ -146,6 +149,9 @@ func (n ShelvesBookResourceName) MarshalString() (string, error) { } func (n *ShelvesBookResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "shelves/{shelf}/books/{book}", @@ -201,6 +207,9 @@ func (n PublishersBookResourceName) MarshalString() (string, error) { } func (n *PublishersBookResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "publishers/{publisher}/books/{book}", @@ -264,6 +273,9 @@ func (n ShelfResourceName) MarshalString() (string, error) { } func (n *ShelfResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "shelves/{shelf}", @@ -312,6 +324,9 @@ func (n LibrariesShelfResourceName) MarshalString() (string, error) { } func (n *LibrariesShelfResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "libraries/{library}/shelves/{shelf}", @@ -361,6 +376,9 @@ func (n RoomsShelfResourceName) MarshalString() (string, error) { } func (n *RoomsShelfResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "rooms/{room}/shelves/{shelf}", diff --git a/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/single/testdata_aip.go b/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/single/testdata_aip.go index 0b5519272a..b73e9cee46 100644 --- a/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/single/testdata_aip.go +++ b/cmd/protoc-gen-go-aip/internal/genaip/testdata/test/single/testdata_aip.go @@ -46,6 +46,9 @@ func (n ShelfResourceName) MarshalString() (string, error) { } func (n *ShelfResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "shelves/{shelf}", @@ -103,6 +106,9 @@ func (n BookResourceName) MarshalString() (string, error) { } func (n *BookResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "shelves/{shelf}/books/{book}", diff --git a/proto/gen/einride/example/freight/v1/shipment_aip.go b/proto/gen/einride/example/freight/v1/shipment_aip.go index b0a9e784f0..bbb0e50d04 100644 --- a/proto/gen/einride/example/freight/v1/shipment_aip.go +++ b/proto/gen/einride/example/freight/v1/shipment_aip.go @@ -63,6 +63,9 @@ func (n ShipmentResourceName) MarshalString() (string, error) { } func (n *ShipmentResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "shippers/{shipper}/shipments/{shipment}", diff --git a/proto/gen/einride/example/freight/v1/shipper_aip.go b/proto/gen/einride/example/freight/v1/shipper_aip.go index 0098f6bd00..bca80de23a 100644 --- a/proto/gen/einride/example/freight/v1/shipper_aip.go +++ b/proto/gen/einride/example/freight/v1/shipper_aip.go @@ -46,6 +46,9 @@ func (n ShipperResourceName) MarshalString() (string, error) { } func (n *ShipperResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "shippers/{shipper}", diff --git a/proto/gen/einride/example/freight/v1/site_aip.go b/proto/gen/einride/example/freight/v1/site_aip.go index 408b8fb9fa..25bd4038f3 100644 --- a/proto/gen/einride/example/freight/v1/site_aip.go +++ b/proto/gen/einride/example/freight/v1/site_aip.go @@ -63,6 +63,9 @@ func (n SiteResourceName) MarshalString() (string, error) { } func (n *SiteResourceName) UnmarshalString(name string) error { + if err := n.Validate(); err != nil { + return err + } return resourcename.Sscan( name, "shippers/{shipper}/sites/{site}",