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 22, 2020
1 parent 370d869 commit a0d6dae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
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
5 changes: 4 additions & 1 deletion protoc-gen-openapiv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ func emitFiles(out []*descriptor.ResponseFile) {
for idx, item := range out {
files[idx] = item.CodeGeneratorResponse_File
}
emitResp(&pluginpb.CodeGeneratorResponse{File: files})
emitResp(&pluginpb.CodeGeneratorResponse{
SupportedFeatures: uint64(pluginpb.CodeGeneratorResponse_FEATURE_PROTO3_OPTIONAL),
File: files,
})
}

func emitError(err error) {
Expand Down

0 comments on commit a0d6dae

Please sign in to comment.