Skip to content

Commit

Permalink
protoc-gen-{grpc-gateway,openapiv2}: add optional support
Browse files Browse the repository at this point in the history
Let `protoc` know that these generators support optional keywords. This
is by no means an implementation in `grpc-gateway` of the optional aware
generated code, it's just shielding of being considered as blockers in
code generation workflows.

Closes grpc-ecosystem#1278
  • Loading branch information
glerchundi committed Nov 23, 2020
1 parent 370d869 commit 7da15d6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions protoc-gen-grpc-gateway/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ go_library(
"//protoc-gen-grpc-gateway/internal/gengateway:go_default_library",
"@com_github_golang_glog//:go_default_library",
"@org_golang_google_protobuf//compiler/protogen:go_default_library",
"@org_golang_google_protobuf//types/pluginpb:go_default_library",
],
)

Expand Down
2 changes: 2 additions & 0 deletions protoc-gen-grpc-gateway/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor"
"github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway/internal/gengateway"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/types/pluginpb"
)

var (
Expand Down Expand Up @@ -54,6 +55,7 @@ func main() {
protogen.Options{
ParamFunc: flag.CommandLine.Set,
}.Run(func(gen *protogen.Plugin) error {
gen.SupportedFeatures = uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
reg := descriptor.NewRegistry()

err := applyFlags(reg)
Expand Down
3 changes: 2 additions & 1 deletion protoc-gen-openapiv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ func emitFiles(out []*descriptor.ResponseFile) {
for idx, item := range out {
files[idx] = item.CodeGeneratorResponse_File
}
emitResp(&pluginpb.CodeGeneratorResponse{File: files})
supportedFeatures := uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL)
emitResp(&pluginpb.CodeGeneratorResponse{SupportedFeatures: &supportedFeatures, File: files})
}

func emitError(err error) {
Expand Down

0 comments on commit 7da15d6

Please sign in to comment.