diff --git a/protoc-gen-grpc-gateway/descriptor/registry.go b/protoc-gen-grpc-gateway/descriptor/registry.go index b73c123c8f9..03cca5313d9 100644 --- a/protoc-gen-grpc-gateway/descriptor/registry.go +++ b/protoc-gen-grpc-gateway/descriptor/registry.go @@ -75,6 +75,9 @@ type Registry struct { // useGoTemplate determines whether you want to use GO templates // in your protofile comments useGoTemplate bool + + // omitPackageDoc, if false, causes a package comment to be included in the generated code. + omitPackageDoc bool } type repeatedFieldSeparator struct { @@ -460,6 +463,16 @@ func (r *Registry) GetUseGoTemplate() bool { return r.useGoTemplate } +// SetOmitPackageDoc controls whether the generated code contains a package comment (if set to false, it will contain one) +func (r *Registry) SetOmitPackageDoc(omit bool) { + r.omitPackageDoc = omit +} + +// GetOmitPackageDoc returns whether a package comment will be omitted from the generated code +func (r *Registry) GetOmitPackageDoc() bool { + return r.omitPackageDoc +} + // sanitizePackageName replaces unallowed character in package name // with allowed character. func sanitizePackageName(pkgName string) string { diff --git a/protoc-gen-grpc-gateway/gengateway/generator.go b/protoc-gen-grpc-gateway/gengateway/generator.go index 0b6bfbd2b93..32ef738cc13 100644 --- a/protoc-gen-grpc-gateway/gengateway/generator.go +++ b/protoc-gen-grpc-gateway/gengateway/generator.go @@ -147,6 +147,9 @@ func (g *generator) generate(file *descriptor.File) (string, error) { RegisterFuncSuffix: g.registerFuncSuffix, AllowPatchFeature: g.allowPatchFeature, } + if g.reg != nil { + params.OmitPackageDoc = g.reg.GetOmitPackageDoc() + } return applyTemplate(params, g.reg) } diff --git a/protoc-gen-grpc-gateway/gengateway/template.go b/protoc-gen-grpc-gateway/gengateway/template.go index 1d3d3ca8f19..abd3f177512 100644 --- a/protoc-gen-grpc-gateway/gengateway/template.go +++ b/protoc-gen-grpc-gateway/gengateway/template.go @@ -19,6 +19,7 @@ type param struct { UseRequestContext bool RegisterFuncSuffix string AllowPatchFeature bool + OmitPackageDoc bool } type binding struct { @@ -221,11 +222,11 @@ var ( // Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. // source: {{.GetName}} -/* +{{if not .OmitPackageDoc}}/* Package {{.GoPkg.Name}} is a reverse proxy. It translates gRPC into RESTful JSON APIs. -*/ +*/{{end}} package {{.GoPkg.Name}} import ( {{range $i := .Imports}}{{if $i.Standard}}{{$i | printf "%s\n"}}{{end}}{{end}} diff --git a/protoc-gen-grpc-gateway/main.go b/protoc-gen-grpc-gateway/main.go index 291ba7deb2f..78c4aca12da 100644 --- a/protoc-gen-grpc-gateway/main.go +++ b/protoc-gen-grpc-gateway/main.go @@ -34,6 +34,7 @@ var ( repeatedPathParamSeparator = flag.String("repeated_path_param_separator", "csv", "configures how repeated fields should be split. Allowed values are `csv`, `pipes`, `ssv` and `tsv`.") allowPatchFeature = flag.Bool("allow_patch_feature", true, "determines whether to use PATCH feature involving update masks (using google.protobuf.FieldMask).") allowColonFinalSegments = flag.Bool("allow_colon_final_segments", false, "determines whether colons are permitted in the final segment of a path") + omitPackageDoc = flag.Bool("omit_package_doc", false, "if true, no package comment will be included in the generated code") versionFlag = flag.Bool("version", false, "print the current verison") ) @@ -95,6 +96,7 @@ func main() { reg.SetAllowDeleteBody(*allowDeleteBody) reg.SetAllowRepeatedFieldsInBody(*allowRepeatedFieldsInBody) reg.SetAllowColonFinalSegments(*allowColonFinalSegments) + reg.SetOmitPackageDoc(*omitPackageDoc) if err := reg.SetRepeatedPathParamSeparator(*repeatedPathParamSeparator); err != nil { emitError(err) return