diff --git a/go.mod b/go.mod index 7fdca8f95..e964606bc 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 github.com/golang/protobuf v1.5.3 github.com/gorilla/mux v1.8.0 - github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2 + github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.0 github.com/hashicorp/go-multierror v1.1.0 github.com/mackerelio/go-osstat v0.2.4 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 @@ -83,8 +83,8 @@ require ( golang.org/x/text v0.12.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect google.golang.org/grpc v1.57.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 93bc9683b..3153d365d 100644 --- a/go.sum +++ b/go.sum @@ -203,8 +203,8 @@ github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8 github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2 h1:dygLcbEBA+t/P7ck6a8AkXv6juQ4cK0RHBoh32jxhHM= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2/go.mod h1:Ap9RLCIJVtgQg1/BBgVEfypOAySvvlcpcVQkSzJCH4Y= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.0 h1:Rme6CE1aUTyV9WmrEPyGf1V+7W3iQzZ1DZkKnT6z9B0= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.0/go.mod h1:Hbb13e3/WtqQ8U5hLGkek9gJvBLasHuPFI0UEGfnQ10= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.0 h1:B9UzwGQJehnUY1yNrnwREHc3fGbC2xefo8g4TbElacI= @@ -658,10 +658,10 @@ google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6D google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 h1:L6iMMGrtzgHsWofoFcihmDEMYeDR9KN/ThbPWGrh++g= google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5/go.mod h1:oH/ZOT02u4kWEp7oYBGYFFkCdKS/uYR9Z7+0/xuuFp8= -google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 h1:nIgk/EEq3/YlnmVVXVnm14rC2oxgs1o0ong4sD/rd44= -google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5/go.mod h1:5DZzOUPCLYL3mNkQ0ms0F3EuUNZ7py1Bqeq6sxzI7/Q= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 h1:wukfNtZmZUurLN/atp2hiIeTKn7QJWIQdHzqmsOnAOk= -google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= +google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d h1:DoPTO70H+bcDXcd39vOqb2viZxgqeBeSGtZ55yZU4/Q= +google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d h1:uvYuEyMHKNt+lT4K3bN6fGswmK8qSvcreM3BwjDh+y4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= diff --git a/vendor/github.com/golang/protobuf/descriptor/descriptor.go b/vendor/github.com/golang/protobuf/descriptor/descriptor.go deleted file mode 100644 index ffde8a650..000000000 --- a/vendor/github.com/golang/protobuf/descriptor/descriptor.go +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// Package descriptor provides functions for obtaining the protocol buffer -// descriptors of generated Go types. -// -// Deprecated: See the "google.golang.org/protobuf/reflect/protoreflect" package -// for how to obtain an EnumDescriptor or MessageDescriptor in order to -// programatically interact with the protobuf type system. -package descriptor - -import ( - "bytes" - "compress/gzip" - "io/ioutil" - "sync" - - "github.com/golang/protobuf/proto" - "google.golang.org/protobuf/reflect/protodesc" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/runtime/protoimpl" - - descriptorpb "github.com/golang/protobuf/protoc-gen-go/descriptor" -) - -// Message is proto.Message with a method to return its descriptor. -// -// Deprecated: The Descriptor method may not be generated by future -// versions of protoc-gen-go, meaning that this interface may not -// be implemented by many concrete message types. -type Message interface { - proto.Message - Descriptor() ([]byte, []int) -} - -// ForMessage returns the file descriptor proto containing -// the message and the message descriptor proto for the message itself. -// The returned proto messages must not be mutated. -// -// Deprecated: Not all concrete message types satisfy the Message interface. -// Use MessageDescriptorProto instead. If possible, the calling code should -// be rewritten to use protobuf reflection instead. -// See package "google.golang.org/protobuf/reflect/protoreflect" for details. -func ForMessage(m Message) (*descriptorpb.FileDescriptorProto, *descriptorpb.DescriptorProto) { - return MessageDescriptorProto(m) -} - -type rawDesc struct { - fileDesc []byte - indexes []int -} - -var rawDescCache sync.Map // map[protoreflect.Descriptor]*rawDesc - -func deriveRawDescriptor(d protoreflect.Descriptor) ([]byte, []int) { - // Fast-path: check whether raw descriptors are already cached. - origDesc := d - if v, ok := rawDescCache.Load(origDesc); ok { - return v.(*rawDesc).fileDesc, v.(*rawDesc).indexes - } - - // Slow-path: derive the raw descriptor from the v2 descriptor. - - // Start with the leaf (a given enum or message declaration) and - // ascend upwards until we hit the parent file descriptor. - var idxs []int - for { - idxs = append(idxs, d.Index()) - d = d.Parent() - if d == nil { - // TODO: We could construct a FileDescriptor stub for standalone - // descriptors to satisfy the API. - return nil, nil - } - if _, ok := d.(protoreflect.FileDescriptor); ok { - break - } - } - - // Obtain the raw file descriptor. - fd := d.(protoreflect.FileDescriptor) - b, _ := proto.Marshal(protodesc.ToFileDescriptorProto(fd)) - file := protoimpl.X.CompressGZIP(b) - - // Reverse the indexes, since we populated it in reverse. - for i, j := 0, len(idxs)-1; i < j; i, j = i+1, j-1 { - idxs[i], idxs[j] = idxs[j], idxs[i] - } - - if v, ok := rawDescCache.LoadOrStore(origDesc, &rawDesc{file, idxs}); ok { - return v.(*rawDesc).fileDesc, v.(*rawDesc).indexes - } - return file, idxs -} - -// EnumRawDescriptor returns the GZIP'd raw file descriptor representing -// the enum and the index path to reach the enum declaration. -// The returned slices must not be mutated. -func EnumRawDescriptor(e proto.GeneratedEnum) ([]byte, []int) { - if ev, ok := e.(interface{ EnumDescriptor() ([]byte, []int) }); ok { - return ev.EnumDescriptor() - } - ed := protoimpl.X.EnumTypeOf(e) - return deriveRawDescriptor(ed.Descriptor()) -} - -// MessageRawDescriptor returns the GZIP'd raw file descriptor representing -// the message and the index path to reach the message declaration. -// The returned slices must not be mutated. -func MessageRawDescriptor(m proto.GeneratedMessage) ([]byte, []int) { - if mv, ok := m.(interface{ Descriptor() ([]byte, []int) }); ok { - return mv.Descriptor() - } - md := protoimpl.X.MessageTypeOf(m) - return deriveRawDescriptor(md.Descriptor()) -} - -var fileDescCache sync.Map // map[*byte]*descriptorpb.FileDescriptorProto - -func deriveFileDescriptor(rawDesc []byte) *descriptorpb.FileDescriptorProto { - // Fast-path: check whether descriptor protos are already cached. - if v, ok := fileDescCache.Load(&rawDesc[0]); ok { - return v.(*descriptorpb.FileDescriptorProto) - } - - // Slow-path: derive the descriptor proto from the GZIP'd message. - zr, err := gzip.NewReader(bytes.NewReader(rawDesc)) - if err != nil { - panic(err) - } - b, err := ioutil.ReadAll(zr) - if err != nil { - panic(err) - } - fd := new(descriptorpb.FileDescriptorProto) - if err := proto.Unmarshal(b, fd); err != nil { - panic(err) - } - if v, ok := fileDescCache.LoadOrStore(&rawDesc[0], fd); ok { - return v.(*descriptorpb.FileDescriptorProto) - } - return fd -} - -// EnumDescriptorProto returns the file descriptor proto representing -// the enum and the enum descriptor proto for the enum itself. -// The returned proto messages must not be mutated. -func EnumDescriptorProto(e proto.GeneratedEnum) (*descriptorpb.FileDescriptorProto, *descriptorpb.EnumDescriptorProto) { - rawDesc, idxs := EnumRawDescriptor(e) - if rawDesc == nil || idxs == nil { - return nil, nil - } - fd := deriveFileDescriptor(rawDesc) - if len(idxs) == 1 { - return fd, fd.EnumType[idxs[0]] - } - md := fd.MessageType[idxs[0]] - for _, i := range idxs[1 : len(idxs)-1] { - md = md.NestedType[i] - } - ed := md.EnumType[idxs[len(idxs)-1]] - return fd, ed -} - -// MessageDescriptorProto returns the file descriptor proto representing -// the message and the message descriptor proto for the message itself. -// The returned proto messages must not be mutated. -func MessageDescriptorProto(m proto.GeneratedMessage) (*descriptorpb.FileDescriptorProto, *descriptorpb.DescriptorProto) { - rawDesc, idxs := MessageRawDescriptor(m) - if rawDesc == nil || idxs == nil { - return nil, nil - } - fd := deriveFileDescriptor(rawDesc) - md := fd.MessageType[idxs[0]] - for _, i := range idxs[1:] { - md = md.NestedType[i] - } - return fd, md -} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor/registry.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor/registry.go index 9cd14cc7e..ecc950d21 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor/registry.go +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/internal/descriptor/registry.go @@ -146,6 +146,10 @@ type Registry struct { // allowPatchFeature determines whether to use PATCH feature involving update masks (using google.protobuf.FieldMask). allowPatchFeature bool + + // preserveRPCOrder, if true, will ensure the order of paths emitted in openapi swagger files mirror + // the order of RPC methods found in proto files. If false, emitted paths will be ordered alphabetically. + preserveRPCOrder bool } type repeatedFieldSeparator struct { @@ -811,3 +815,13 @@ func (r *Registry) SetAllowPatchFeature(allow bool) { func (r *Registry) GetAllowPatchFeature() bool { return r.allowPatchFeature } + +// SetPreserveRPCOrder sets preserveRPCOrder +func (r *Registry) SetPreserveRPCOrder(preserve bool) { + r.preserveRPCOrder = preserve +} + +// IsPreserveRPCOrder returns preserveRPCOrder +func (r *Registry) IsPreserveRPCOrder() bool { + return r.preserveRPCOrder +} diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/BUILD.bazel b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/BUILD.bazel index 30b2f4e95..6af63ffc8 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/BUILD.bazel +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/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/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/generator.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/generator.go index b2ed7bd34..b5d171387 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/generator.go +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/generator.go @@ -7,20 +7,20 @@ import ( "fmt" "path/filepath" "reflect" + "sort" "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" + "gopkg.in/yaml.v3" ) var errNoTargetService = errors.New("no target service defined in the file") @@ -61,12 +61,10 @@ func mergeTargetFile(targets []*wrapper, mergeFileName string) *wrapper { for k, v := range f.swagger.Definitions { mergedTarget.swagger.Definitions[k] = v } - for k, v := range f.swagger.Paths { - mergedTarget.swagger.Paths[k] = v - } for k, v := range f.swagger.SecurityDefinitions { mergedTarget.swagger.SecurityDefinitions[k] = v } + copy(mergedTarget.swagger.Paths, f.swagger.Paths) mergedTarget.swagger.Security = append(mergedTarget.swagger.Security, f.swagger.Security...) } } @@ -114,6 +112,58 @@ func (so openapiSwaggerObject) MarshalYAML() (interface{}, error) { }, nil } +// Custom json marshaller for openapiPathsObject. Ensures +// openapiPathsObject is marshalled into expected format in generated +// swagger.json. +func (po openapiPathsObject) MarshalJSON() ([]byte, error) { + var buf bytes.Buffer + + buf.WriteString("{") + for i, pd := range po { + if i != 0 { + buf.WriteString(",") + } + // marshal key + key, err := json.Marshal(pd.Path) + if err != nil { + return nil, err + } + buf.Write(key) + buf.WriteString(":") + // marshal value + val, err := json.Marshal(pd.PathItemObject) + if err != nil { + return nil, err + } + buf.Write(val) + } + + buf.WriteString("}") + return buf.Bytes(), nil +} + +// Custom yaml marshaller for openapiPathsObject. Ensures +// openapiPathsObject is marshalled into expected format in generated +// swagger.yaml. +func (po openapiPathsObject) MarshalYAML() (interface{}, error) { + var pathObjectNode yaml.Node + pathObjectNode.Kind = yaml.MappingNode + + for _, pathData := range po { + var pathNode, pathItemObjectNode yaml.Node + + pathNode.SetString(pathData.Path) + b, err := yaml.Marshal(pathData.PathItemObject) + if err != nil { + return nil, err + } + pathItemObjectNode.SetString(string(b)) + pathObjectNode.Content = append(pathObjectNode.Content, &pathNode, &pathItemObjectNode) + } + + return pathObjectNode, nil +} + func (so openapiInfoObject) MarshalJSON() ([]byte, error) { type alias openapiInfoObject return extensionMarshalJSON(alias(so), so.extensions) @@ -300,7 +350,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 } @@ -343,6 +393,9 @@ func (g *generator) Generate(targets []*descriptor.File) ([]*descriptor.Response if g.reg.IsAllowMerge() { targetOpenAPI := mergeTargetFile(openapis, g.reg.GetMergeFileName()) + if !g.reg.IsPreserveRPCOrder() { + targetOpenAPI.swagger.sortPathsAlphabetically() + } f, err := encodeOpenAPI(targetOpenAPI, g.format) if err != nil { return nil, fmt.Errorf("failed to encode OpenAPI for %s: %w", g.reg.GetMergeFileName(), err) @@ -353,6 +406,9 @@ func (g *generator) Generate(targets []*descriptor.File) ([]*descriptor.Response } } else { for _, file := range openapis { + if !g.reg.IsPreserveRPCOrder() { + file.swagger.sortPathsAlphabetically() + } f, err := encodeOpenAPI(file, g.format) if err != nil { return nil, fmt.Errorf("failed to encode OpenAPI for %s: %w", file.fileName, err) @@ -366,17 +422,18 @@ func (g *generator) Generate(targets []*descriptor.File) ([]*descriptor.Response return files, nil } +func (so openapiSwaggerObject) sortPathsAlphabetically() { + sort.Slice(so.Paths, func(i, j int) bool { + return so.Paths[i].Path < so.Paths[j].Path + }) +} + // AddErrorDefs Adds google.rpc.Status and google.protobuf.Any // 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, diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/template.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/template.go index 01ef460af..3515dedcb 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/template.go +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/template.go @@ -1109,7 +1109,7 @@ func renderServiceTags(services []*descriptor.Service, reg *descriptor.Registry) return tags } -func renderServices(services []*descriptor.Service, paths openapiPathsObject, reg *descriptor.Registry, requestResponseRefs, customRefs refMap, msgs []*descriptor.Message) error { +func renderServices(services []*descriptor.Service, paths *openapiPathsObject, reg *descriptor.Registry, requestResponseRefs, customRefs refMap, msgs []*descriptor.Message) error { // Correctness of svcIdx and methIdx depends on 'services' containing the services in the same order as the 'file.Service' array. svcBaseIdx := 0 var lastFile *descriptor.File = nil @@ -1330,7 +1330,9 @@ func renderServices(services []*descriptor.Service, paths openapiPathsObject, re parameters = append(parameters, queryParams...) path := partsToOpenAPIPath(parts, pathParamNames) - pathItemObject, ok := paths[path] + + pathItemObject, ok := getPathItemObject(*paths, path) + if !ok { pathItemObject = openapiPathItemObject{} } else { @@ -1362,14 +1364,15 @@ func renderServices(services []*descriptor.Service, paths openapiPathsObject, re newPathCount += 1 newPathElement = firstPathParameter.Name + pathParamUniqueSuffixDeliminator + strconv.Itoa(newPathCount) newPath = strings.ReplaceAll(path, "{"+firstPathParameter.Name+"}", "{"+newPathElement+"}") - if newPathItemObject, ok := paths[newPath]; ok { + + if newPathItemObject, ok := getPathItemObject(*paths, newPath); ok { existingOperationObject = operationFunc(&newPathItemObject) } else { existingOperationObject = nil } } // update the pathItemObject we are adding to with the new path - pathItemObject = paths[newPath] + pathItemObject, _ = getPathItemObject(*paths, newPath) firstPathParameter.Name = newPathElement path = newPath parameters[firstParamIndex] = *firstPathParameter @@ -1652,7 +1655,8 @@ func renderServices(services []*descriptor.Service, paths openapiPathsObject, re case "OPTIONS": pathItemObject.Options = operationObject } - paths[path] = pathItemObject + + updatePaths(paths, path, pathItemObject) } } } @@ -1661,6 +1665,33 @@ func renderServices(services []*descriptor.Service, paths openapiPathsObject, re return nil } +// Returns the openapiPathItemObject associated with a path. If path is not present, returns +// empty openapiPathItemObject and false. +func getPathItemObject(paths openapiPathsObject, path string) (openapiPathItemObject, bool) { + for _, pathData := range paths { + if pathData.Path == path { + return pathData.PathItemObject, true + } + } + + return openapiPathItemObject{}, false +} + +// If a path already exists in openapiPathsObject, updates that path's openapiPathItemObject. If not, +// appends a new path and openapiPathItemObject to the openapiPathsObject. +func updatePaths(paths *openapiPathsObject, path string, pathItemObject openapiPathItemObject) { + for i, p := range *paths { + if p.Path == path { + (*paths)[i].PathItemObject = pathItemObject + return + } + } + *paths = append(*paths, pathData{ + Path: path, + PathItemObject: pathItemObject, + }) +} + func mergeDescription(schema openapiSchemaObject) string { desc := schema.Description if schema.Title != "" { // join title because title of parameter object will be ignored @@ -1699,7 +1730,7 @@ func applyTemplate(p param) (*openapiSwaggerObject, error) { Swagger: "2.0", Consumes: []string{"application/json"}, Produces: []string{"application/json"}, - Paths: make(openapiPathsObject), + Paths: openapiPathsObject{}, Definitions: make(openapiDefinitionsObject), Info: openapiInfoObject{ Title: *p.File.Name, @@ -1711,7 +1742,7 @@ func applyTemplate(p param) (*openapiSwaggerObject, error) { // and create entries for all of them. // Also adds custom user specified references to second map. requestResponseRefs, customRefs := refMap{}, refMap{} - if err := renderServices(p.Services, s.Paths, p.reg, requestResponseRefs, customRefs, p.Messages); err != nil { + if err := renderServices(p.Services, &s.Paths, p.reg, requestResponseRefs, customRefs, p.Messages); err != nil { panic(err) } @@ -1920,20 +1951,20 @@ func applyTemplate(p param) (*openapiSwaggerObject, error) { if spb.Responses != nil { for _, verbs := range s.Paths { var maps []openapiResponsesObject - if verbs.Delete != nil { - maps = append(maps, verbs.Delete.Responses) + if verbs.PathItemObject.Delete != nil { + maps = append(maps, verbs.PathItemObject.Delete.Responses) } - if verbs.Get != nil { - maps = append(maps, verbs.Get.Responses) + if verbs.PathItemObject.Get != nil { + maps = append(maps, verbs.PathItemObject.Get.Responses) } - if verbs.Post != nil { - maps = append(maps, verbs.Post.Responses) + if verbs.PathItemObject.Post != nil { + maps = append(maps, verbs.PathItemObject.Post.Responses) } - if verbs.Put != nil { - maps = append(maps, verbs.Put.Responses) + if verbs.PathItemObject.Put != nil { + maps = append(maps, verbs.PathItemObject.Put.Responses) } - if verbs.Patch != nil { - maps = append(maps, verbs.Patch.Responses) + if verbs.PathItemObject.Patch != nil { + maps = append(maps, verbs.PathItemObject.Patch.Responses) } for k, v := range spb.Responses { diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/types.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/types.go index b73fcdfb1..c4eaa62e6 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/types.go +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/internal/genopenapi/types.go @@ -103,7 +103,12 @@ type openapiScopesObject map[string]string type openapiSecurityRequirementObject map[string][]string // http://swagger.io/specification/#pathsObject -type openapiPathsObject map[string]openapiPathItemObject +type openapiPathsObject []pathData + +type pathData struct { + Path string + PathItemObject openapiPathItemObject +} // http://swagger.io/specification/#pathItemObject type openapiPathItemObject struct { diff --git a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/main.go b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/main.go index e7fa7f74b..43f3d7fff 100644 --- a/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/main.go +++ b/vendor/github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2/main.go @@ -45,6 +45,7 @@ var ( disableDefaultResponses = flag.Bool("disable_default_responses", false, "if set, disables generation of default responses. Useful if you have to support custom response codes that are not 200.") useAllOfForRefs = flag.Bool("use_allof_for_refs", false, "if set, will use allOf as container for $ref to preserve same-level properties.") allowPatchFeature = flag.Bool("allow_patch_feature", true, "whether to hide update_mask fields in PATCH requests from the generated swagger file.") + preserveRPCOrder = flag.Bool("preserve_rpc_order", false, "if true, will ensure the order of paths emitted in openapi swagger files mirror the order of RPC methods found in proto files. If false, emitted paths will be ordered alphabetically.") ) // Variables set by goreleaser at build time @@ -143,6 +144,7 @@ func main() { reg.SetDisableDefaultResponses(*disableDefaultResponses) reg.SetUseAllOfForRefs(*useAllOfForRefs) reg.SetAllowPatchFeature(*allowPatchFeature) + reg.SetPreserveRPCOrder(*preserveRPCOrder) if err := reg.SetRepeatedPathParamSeparator(*repeatedPathParamSeparator); err != nil { emitError(err) return diff --git a/vendor/google.golang.org/genproto/googleapis/api/annotations/field_behavior.pb.go b/vendor/google.golang.org/genproto/googleapis/api/annotations/field_behavior.pb.go index dbe2e2d0c..6ce01ac9a 100644 --- a/vendor/google.golang.org/genproto/googleapis/api/annotations/field_behavior.pb.go +++ b/vendor/google.golang.org/genproto/googleapis/api/annotations/field_behavior.pb.go @@ -15,7 +15,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.26.0 -// protoc v3.21.9 +// protoc v3.21.12 // source: google/api/field_behavior.proto package annotations @@ -78,6 +78,19 @@ const ( // a non-empty value will be returned. The user will not be aware of what // non-empty value to expect. FieldBehavior_NON_EMPTY_DEFAULT FieldBehavior = 7 + // Denotes that the field in a resource (a message annotated with + // google.api.resource) is used in the resource name to uniquely identify the + // resource. For AIP-compliant APIs, this should only be applied to the + // `name` field on the resource. + // + // This behavior should not be applied to references to other resources within + // the message. + // + // The identifier field of resources often have different field behavior + // depending on the request it is embedded in (e.g. for Create methods name + // is optional and unused, while for Update methods it is required). Instead + // of method-specific annotations, only `IDENTIFIER` is required. + FieldBehavior_IDENTIFIER FieldBehavior = 8 ) // Enum value maps for FieldBehavior. @@ -91,6 +104,7 @@ var ( 5: "IMMUTABLE", 6: "UNORDERED_LIST", 7: "NON_EMPTY_DEFAULT", + 8: "IDENTIFIER", } FieldBehavior_value = map[string]int32{ "FIELD_BEHAVIOR_UNSPECIFIED": 0, @@ -101,6 +115,7 @@ var ( "IMMUTABLE": 5, "UNORDERED_LIST": 6, "NON_EMPTY_DEFAULT": 7, + "IDENTIFIER": 8, } ) @@ -169,7 +184,7 @@ var file_google_api_field_behavior_proto_rawDesc = []byte{ 0x6f, 0x12, 0x0a, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x61, 0x70, 0x69, 0x1a, 0x20, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2a, - 0xa6, 0x01, 0x0a, 0x0d, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x42, 0x65, 0x68, 0x61, 0x76, 0x69, 0x6f, + 0xb6, 0x01, 0x0a, 0x0d, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x42, 0x65, 0x68, 0x61, 0x76, 0x69, 0x6f, 0x72, 0x12, 0x1e, 0x0a, 0x1a, 0x46, 0x49, 0x45, 0x4c, 0x44, 0x5f, 0x42, 0x45, 0x48, 0x41, 0x56, 0x49, 0x4f, 0x52, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x4f, 0x50, 0x54, 0x49, 0x4f, 0x4e, 0x41, 0x4c, 0x10, 0x01, 0x12, @@ -179,7 +194,8 @@ var file_google_api_field_behavior_proto_rawDesc = []byte{ 0x0a, 0x09, 0x49, 0x4d, 0x4d, 0x55, 0x54, 0x41, 0x42, 0x4c, 0x45, 0x10, 0x05, 0x12, 0x12, 0x0a, 0x0e, 0x55, 0x4e, 0x4f, 0x52, 0x44, 0x45, 0x52, 0x45, 0x44, 0x5f, 0x4c, 0x49, 0x53, 0x54, 0x10, 0x06, 0x12, 0x15, 0x0a, 0x11, 0x4e, 0x4f, 0x4e, 0x5f, 0x45, 0x4d, 0x50, 0x54, 0x59, 0x5f, 0x44, - 0x45, 0x46, 0x41, 0x55, 0x4c, 0x54, 0x10, 0x07, 0x3a, 0x60, 0x0a, 0x0e, 0x66, 0x69, 0x65, 0x6c, + 0x45, 0x46, 0x41, 0x55, 0x4c, 0x54, 0x10, 0x07, 0x12, 0x0e, 0x0a, 0x0a, 0x49, 0x44, 0x45, 0x4e, + 0x54, 0x49, 0x46, 0x49, 0x45, 0x52, 0x10, 0x08, 0x3a, 0x60, 0x0a, 0x0e, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x62, 0x65, 0x68, 0x61, 0x76, 0x69, 0x6f, 0x72, 0x12, 0x1d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x9c, 0x08, 0x20, 0x03, 0x28, 0x0e, diff --git a/vendor/modules.txt b/vendor/modules.txt index 23e176f7e..5a03e65d7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -76,7 +76,6 @@ github.com/golang/glog/internal/stackdump github.com/golang/groupcache/lru # github.com/golang/protobuf v1.5.3 ## explicit; go 1.9 -github.com/golang/protobuf/descriptor github.com/golang/protobuf/internal/gengogrpc github.com/golang/protobuf/jsonpb github.com/golang/protobuf/proto @@ -128,7 +127,7 @@ github.com/googleapis/gax-go/v2/internal # github.com/gorilla/mux v1.8.0 ## explicit; go 1.12 github.com/gorilla/mux -# github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.2 +# github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.0 ## explicit; go 1.17 github.com/grpc-ecosystem/grpc-gateway/v2/internal/casing github.com/grpc-ecosystem/grpc-gateway/v2/internal/codegenerator @@ -405,12 +404,12 @@ google.golang.org/appengine/urlfetch # google.golang.org/genproto v0.0.0-20230803162519-f966b187b2e5 ## explicit; go 1.19 google.golang.org/genproto/internal -# google.golang.org/genproto/googleapis/api v0.0.0-20230803162519-f966b187b2e5 +# google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d ## explicit; go 1.19 google.golang.org/genproto/googleapis/api google.golang.org/genproto/googleapis/api/annotations google.golang.org/genproto/googleapis/api/visibility -# google.golang.org/genproto/googleapis/rpc v0.0.0-20230807174057-1744710a1577 +# google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d ## explicit; go 1.19 google.golang.org/genproto/googleapis/rpc/code google.golang.org/genproto/googleapis/rpc/errdetails