diff --git a/go.mod b/go.mod index 5e04698fae7..5c0e943e8b2 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/protoc-gen-grpc-gateway/descriptor/registry.go b/protoc-gen-grpc-gateway/descriptor/registry.go index 28637a4dab8..bbf93395988 100644 --- a/protoc-gen-grpc-gateway/descriptor/registry.go +++ b/protoc-gen-grpc-gateway/descriptor/registry.go @@ -2,6 +2,7 @@ package descriptor import ( "fmt" + "io/ioutil" "path" "path/filepath" "strings" @@ -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. @@ -97,6 +99,9 @@ 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 { @@ -104,6 +109,11 @@ type repeatedFieldSeparator struct { 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{ @@ -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 +} diff --git a/protoc-gen-swagger/main.go b/protoc-gen-swagger/main.go index ffdfcd853af..bfb27e36995 100644 --- a/protoc-gen-swagger/main.go +++ b/protoc-gen-swagger/main.go @@ -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 @@ -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