diff --git a/go.mod b/go.mod index 04920f6fbc3..b40716614f2 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.17 require ( github.com/antihax/optional v1.0.0 github.com/golang/glog v1.1.0 - github.com/golang/protobuf v1.5.3 github.com/google/go-cmp v0.5.9 github.com/rogpeppe/fastuuid v1.2.0 golang.org/x/oauth2 v0.11.0 @@ -18,6 +17,7 @@ require ( ) require ( + github.com/golang/protobuf v1.5.3 // indirect github.com/kr/pretty v0.3.1 // indirect golang.org/x/net v0.14.0 // indirect golang.org/x/sys v0.11.0 // indirect diff --git a/protoc-gen-openapiv2/internal/genopenapi/BUILD.bazel b/protoc-gen-openapiv2/internal/genopenapi/BUILD.bazel index 30b2f4e9549..6af63ffc8af 100644 --- a/protoc-gen-openapiv2/internal/genopenapi/BUILD.bazel +++ b/protoc-gen-openapiv2/internal/genopenapi/BUILD.bazel @@ -20,8 +20,6 @@ go_library( "//internal/descriptor", "//internal/generator", "//protoc-gen-openapiv2/options", - "@com_github_golang_protobuf//descriptor:go_default_library_gen", - "@com_github_golang_protobuf//ptypes/any", "@in_gopkg_yaml_v3//:yaml_v3", "@org_golang_google_genproto_googleapis_api//annotations", "@org_golang_google_genproto_googleapis_api//visibility", @@ -29,7 +27,9 @@ go_library( "@org_golang_google_grpc//grpclog", "@org_golang_google_protobuf//encoding/protojson", "@org_golang_google_protobuf//proto", + "@org_golang_google_protobuf//reflect/protodesc", "@org_golang_google_protobuf//types/descriptorpb", + "@org_golang_google_protobuf//types/known/anypb", "@org_golang_google_protobuf//types/known/structpb", "@org_golang_google_protobuf//types/pluginpb", "@org_golang_x_text//cases", diff --git a/protoc-gen-openapiv2/internal/genopenapi/generator.go b/protoc-gen-openapiv2/internal/genopenapi/generator.go index b2ed7bd34c0..3848be8c9d2 100644 --- a/protoc-gen-openapiv2/internal/genopenapi/generator.go +++ b/protoc-gen-openapiv2/internal/genopenapi/generator.go @@ -9,18 +9,16 @@ import ( "reflect" "strings" - anypb "github.com/golang/protobuf/ptypes/any" "github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor" gen "github.com/grpc-ecosystem/grpc-gateway/v2/internal/generator" - openapi_options "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options" + openapioptions "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/options" statuspb "google.golang.org/genproto/googleapis/rpc/status" "google.golang.org/grpc/grpclog" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protodesc" "google.golang.org/protobuf/types/descriptorpb" + "google.golang.org/protobuf/types/known/anypb" "google.golang.org/protobuf/types/pluginpb" - - //nolint:staticcheck // Known issue, will be replaced when possible - legacydescriptor "github.com/golang/protobuf/descriptor" ) var errNoTargetService = errors.New("no target service defined in the file") @@ -300,7 +298,7 @@ func (g *generator) Generate(targets []*descriptor.File) ([]*descriptor.Response var mergedTarget *descriptor.File // try to find proto leader for _, f := range targets { - if proto.HasExtension(f.Options, openapi_options.E_Openapiv2Swagger) { + if proto.HasExtension(f.Options, openapioptions.E_Openapiv2Swagger) { mergedTarget = f break } @@ -370,13 +368,8 @@ func (g *generator) Generate(targets []*descriptor.File) ([]*descriptor.Response // to registry (used for error-related API responses) func AddErrorDefs(reg *descriptor.Registry) error { // load internal protos - any, _ := legacydescriptor.MessageDescriptorProto(&anypb.Any{}) - any.SourceCodeInfo = new(descriptorpb.SourceCodeInfo) - status, _ := legacydescriptor.MessageDescriptorProto(&statuspb.Status{}) - status.SourceCodeInfo = new(descriptorpb.SourceCodeInfo) - // TODO(johanbrandhorst): Use new conversion later when possible - // any := protodesc.ToFileDescriptorProto((&anypb.Any{}).ProtoReflect().Descriptor().ParentFile()) - // status := protodesc.ToFileDescriptorProto((&statuspb.Status{}).ProtoReflect().Descriptor().ParentFile()) + any := protodesc.ToFileDescriptorProto((&anypb.Any{}).ProtoReflect().Descriptor().ParentFile()) + status := protodesc.ToFileDescriptorProto((&statuspb.Status{}).ProtoReflect().Descriptor().ParentFile()) return reg.Load(&pluginpb.CodeGeneratorRequest{ ProtoFile: []*descriptorpb.FileDescriptorProto{ any,