Skip to content

Commit

Permalink
pgs: support proto3 presence & bump go.mod (bufbuild#431)
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Gupta <signed@sarthak.sh>
  • Loading branch information
snqk committed May 22, 2021
1 parent ff16dc3 commit 1291366
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ require (
golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375
google.golang.org/protobuf v1.26.0
)

replace github.com/lyft/protoc-gen-star => github.com/sarthak40/protoc-gen-star v0.5.3-0.20210511152005-e0bab4844e07
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/iancoleman/strcase v0.0.0-20180726023541-3605ed457bf7 h1:ux/56T2xqZO/3cP1I2F86qpeoYPCOzk+KF/UH/Ar+lk=
github.com/iancoleman/strcase v0.0.0-20180726023541-3605ed457bf7/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/lyft/protoc-gen-star v0.5.3 h1:zSGLzsUew8RT+ZKPHc3jnf8XLaVyHzTcAFBzHtCNR20=
github.com/lyft/protoc-gen-star v0.5.3/go.mod h1:V0xaHgaf5oCCqmcxYcWiDfTiKsZsRc87/1qhoTACD8w=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sarthak40/protoc-gen-star v0.5.3-0.20210511152005-e0bab4844e07 h1:00CZIGVwFdjvWZQ0wetxmE0THBGUURgVYF7Uc+T8Slw=
github.com/sarthak40/protoc-gen-star v0.5.3-0.20210511152005-e0bab4844e07/go.mod h1:TGAoBVkt8w7MPG72TrKIu85MIdXwDuzJYeZuUPFPNwA=
github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY520V4=
github.com/spf13/afero v1.3.4 h1:8q6vk3hthlpb2SouZcnBVKboxWQWMDNF38bwholZrJc=
github.com/spf13/afero v1.3.4/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func main() {
pgs.
Init(pgs.DebugEnv("DEBUG_PGV")).
Init(pgs.DebugEnv("DEBUG_PGV"), pgs.SupportProto3Optional()).
RegisterModule(module.Validator()).
RegisterPostProcessor(pgsgo.GoFmt()).
Render()
Expand Down
2 changes: 1 addition & 1 deletion templates/cc/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool Validate(const {{ class . }}& m, pgv::ValidationMsg* err) {
{{ range .NonOneOfFields }}
{{- render (context .) -}}
{{ end -}}
{{ range .OneOfs }}
{{ range .RealOneOfs }}
switch (m.{{ .Name }}_case()) {
{{ range .Fields -}}
case {{ oneof . }}:
Expand Down
9 changes: 8 additions & 1 deletion templates/goshared/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (m {{ (msgTyp .).Pointer }}) validate(all bool) error {
{{ render (context .) }}
{{ end }}
{{ range .OneOfs }}
{{ range .RealOneOfs }}
switch m.{{ name . }}.(type) {
{{ range .Fields }}
case {{ oneof . }}:
Expand All @@ -51,9 +51,16 @@ func (m {{ (msgTyp .).Pointer }}) validate(all bool) error {
}
{{ end }}
{{ range .SyntheticOneOfFields }}
if m.{{ name . }} != nil {
{{ render (context .) }}
}
{{ end }}
if len(errors) > 0 {
return {{ multierrname . }}(errors)
}
return nil
{{ end -}}
}
Expand Down
4 changes: 2 additions & 2 deletions templates/java/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const msgInnerTpl = `
{{- range .NonOneOfFields }}
{{ renderConstants (context .) }}
{{ end }}
{{ range .OneOfs }}
{{ range .RealOneOfs }}
{{ template "oneOfConst" . }}
{{ end }}
Expand All @@ -27,7 +27,7 @@ const msgInnerTpl = `
{{ range .NonOneOfFields -}}
{{ render (context .) }}
{{ end -}}
{{ range .OneOfs }}
{{ range .RealOneOfs }}
{{ template "oneOf" . }}
{{- end -}}
{{- end }}
Expand Down

0 comments on commit 1291366

Please sign in to comment.