fix swagger api

pull/961/head
longXboy 4 years ago
parent 839aef1ae2
commit b32e7d6e70
  1. 33
      api/metadata/server.go

@ -13,6 +13,8 @@ import (
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/reflect/protoregistry"
descriptorpb "google.golang.org/protobuf/types/descriptorpb" descriptorpb "google.golang.org/protobuf/types/descriptorpb"
) )
@ -38,9 +40,10 @@ func NewServer(srv *grpc.Server) *Server {
} }
func (s *Server) load() error { func (s *Server) load() error {
if len(s.services) == len(s.srv.GetServiceInfo()) { if len(s.services) > 0 {
return nil return nil
} }
if s.srv != nil {
for name, info := range s.srv.GetServiceInfo() { for name, info := range s.srv.GetServiceInfo() {
fdenc, ok := parseMetadata(info.Metadata) fdenc, ok := parseMetadata(info.Metadata)
if !ok { if !ok {
@ -60,6 +63,34 @@ func (s *Server) load() error {
} }
} }
return nil return nil
}
var err error
protoregistry.GlobalFiles.RangeFiles(func(fd protoreflect.FileDescriptor) bool {
if fd.Services() != nil {
for i := 0; i < fd.Services().Len(); i++ {
svc := fd.Services().Get(i)
fdp, e := fileDescriptorProto(fd.Path())
if e != nil {
err = e
return false
}
fdps, e := allDependency(fdp)
if e != nil {
err = e
return false
}
s.services[string(svc.FullName())] = &dpb.FileDescriptorSet{File: fdps}
if svc.Methods() != nil {
for j := 0; j < svc.Methods().Len(); j++ {
method := svc.Methods().Get(j)
s.methods[string(svc.FullName())] = append(s.methods[string(svc.FullName())], string(method.Name()))
}
}
}
}
return true
})
return err
} }
// ListServices return all services // ListServices return all services

Loading…
Cancel
Save