Skip to content

Commit

Permalink
porting changes from mobiledgex/grpc-gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
levshvarts committed Nov 16, 2023
1 parent 26318a5 commit ededb4f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ require (
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884
google.golang.org/grpc v1.33.1
gopkg.in/yaml.v2 v2.2.3 // indirect
gopkg.in/yaml.v2 v2.2.3
)
25 changes: 25 additions & 0 deletions protoc-gen-grpc-gateway/descriptor/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package descriptor

import (
"fmt"
"io/ioutil"
"path"
"path/filepath"
"strings"
Expand All @@ -10,6 +11,7 @@ import (
descriptor "github.com/golang/protobuf/protoc-gen-go/descriptor"
plugin "github.com/golang/protobuf/protoc-gen-go/plugin"
"google.golang.org/genproto/googleapis/api/annotations"
"gopkg.in/yaml.v2"
)

// Registry is a registry of information extracted from plugin.CodeGeneratorRequest.
Expand Down Expand Up @@ -97,13 +99,21 @@ type Registry struct {

// omitPackageDoc, if false, causes a package comment to be included in the generated code.
omitPackageDoc bool

// Custom configuration
config Config
}

type repeatedFieldSeparator struct {
name string
sep rune
}

type Config struct {
SkipMethods map[string]string
SkipFields map[string]map[string]string
}

// NewRegistry returns a new Registry.
func NewRegistry() *Registry {
return &Registry{
Expand Down Expand Up @@ -605,3 +615,18 @@ func (r *Registry) packageIdentityName(f *descriptor.FileDescriptorProto) string
}
return f.GetPackage()
}

func (r *Registry) ParseConfigFile(filename string) error {
if filename == "" {
return nil
}
dat, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
return yaml.Unmarshal(dat, &r.config)
}

func (r *Registry) GetConfig() *Config {
return &r.config
}
5 changes: 5 additions & 0 deletions protoc-gen-swagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
enumsAsInts = flag.Bool("enums_as_ints", false, "whether to render enum values as integers, as opposed to string values")
simpleOperationIDs = flag.Bool("simple_operation_ids", false, "whether to remove the service prefix in the operationID generation. Can introduce duplicate operationIDs, use with caution.")
generateUnboundMethods = flag.Bool("generate_unbound_methods", false, "generate swagger metadata even for RPC methods that have no HttpRule annotation")
configFile = flag.String("config_file", "", "configuration file")
)

// Variables set by goreleaser at build time
Expand Down Expand Up @@ -88,6 +89,10 @@ func main() {
reg.SetDisableDefaultErrors(*disableDefaultErrors)
reg.SetSimpleOperationIDs(*simpleOperationIDs)
reg.SetGenerateUnboundMethods(*generateUnboundMethods)
if err := reg.ParseConfigFile(*configFile); err != nil {
emitError(err)
return
}
if err := reg.SetRepeatedPathParamSeparator(*repeatedPathParamSeparator); err != nil {
emitError(err)
return
Expand Down

0 comments on commit ededb4f

Please sign in to comment.