Merge 9cf84405c1 into c54eac28fd
This commit is contained in:
commit
dae2c35c67
|
|
@ -145,6 +145,8 @@ var (
|
||||||
will accept. If not specified, defaults to 4,194,304 (4 megabytes).`))
|
will accept. If not specified, defaults to 4,194,304 (4 megabytes).`))
|
||||||
emitDefaults = flags.Bool("emit-defaults", false, prettify(`
|
emitDefaults = flags.Bool("emit-defaults", false, prettify(`
|
||||||
Emit default values for JSON-encoded responses.`))
|
Emit default values for JSON-encoded responses.`))
|
||||||
|
keepProtoNames = flags.Bool("keep-proto-names", false, prettify(`
|
||||||
|
Use the original protobuf name for fields instead of lowerCamelCase, for JSON-encoded responses.`))
|
||||||
protosetOut = flags.String("protoset-out", "", prettify(`
|
protosetOut = flags.String("protoset-out", "", prettify(`
|
||||||
The name of a file to be written that will contain a FileDescriptorSet
|
The name of a file to be written that will contain a FileDescriptorSet
|
||||||
proto. With the list and describe verbs, the listed or described
|
proto. With the list and describe verbs, the listed or described
|
||||||
|
|
@ -367,6 +369,9 @@ func main() {
|
||||||
if *emitDefaults && *format != "json" {
|
if *emitDefaults && *format != "json" {
|
||||||
warn("The -emit-defaults is only used when using json format.")
|
warn("The -emit-defaults is only used when using json format.")
|
||||||
}
|
}
|
||||||
|
if *keepProtoNames && *format != "json" {
|
||||||
|
warn("The -keep-proto-names is only used when using json format.")
|
||||||
|
}
|
||||||
|
|
||||||
args := flags.Args()
|
args := flags.Args()
|
||||||
|
|
||||||
|
|
@ -801,6 +806,7 @@ func main() {
|
||||||
includeSeparators := verbosityLevel == 0
|
includeSeparators := verbosityLevel == 0
|
||||||
options := grpcurl.FormatOptions{
|
options := grpcurl.FormatOptions{
|
||||||
EmitJSONDefaultFields: *emitDefaults,
|
EmitJSONDefaultFields: *emitDefaults,
|
||||||
|
OrigName: *keepProtoNames,
|
||||||
IncludeTextSeparator: includeSeparators,
|
IncludeTextSeparator: includeSeparators,
|
||||||
AllowUnknownFields: *allowUnknownFields,
|
AllowUnknownFields: *allowUnknownFields,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -133,10 +133,11 @@ type Formatter func(proto.Message) (string, error)
|
||||||
// include empty/default values (instead of just omitted them) if emitDefaults
|
// include empty/default values (instead of just omitted them) if emitDefaults
|
||||||
// is true. The given resolver is used to assist with encoding of
|
// is true. The given resolver is used to assist with encoding of
|
||||||
// google.protobuf.Any messages.
|
// google.protobuf.Any messages.
|
||||||
func NewJSONFormatter(emitDefaults bool, resolver jsonpb.AnyResolver) Formatter {
|
func NewJSONFormatter(emitDefaults, origName bool, resolver jsonpb.AnyResolver) Formatter {
|
||||||
marshaler := jsonpb.Marshaler{
|
marshaler := jsonpb.Marshaler{
|
||||||
EmitDefaults: emitDefaults,
|
EmitDefaults: emitDefaults,
|
||||||
AnyResolver: resolver,
|
AnyResolver: resolver,
|
||||||
|
OrigName: origName,
|
||||||
}
|
}
|
||||||
// Workaround for indentation issue in jsonpb with Any messages.
|
// Workaround for indentation issue in jsonpb with Any messages.
|
||||||
// Bug was originally fixed in https://github.com/golang/protobuf/pull/834
|
// Bug was originally fixed in https://github.com/golang/protobuf/pull/834
|
||||||
|
|
@ -395,6 +396,9 @@ type FormatOptions struct {
|
||||||
// It might be useful when the output is piped to another grpcurl process.
|
// It might be useful when the output is piped to another grpcurl process.
|
||||||
// FormatText only flag.
|
// FormatText only flag.
|
||||||
IncludeTextSeparator bool
|
IncludeTextSeparator bool
|
||||||
|
|
||||||
|
// OrigName specifies whether to use the original protobuf name for fields.
|
||||||
|
OrigName bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// RequestParserAndFormatter returns a request parser and formatter for the
|
// RequestParserAndFormatter returns a request parser and formatter for the
|
||||||
|
|
@ -409,7 +413,7 @@ func RequestParserAndFormatter(format Format, descSource DescriptorSource, in io
|
||||||
case FormatJSON:
|
case FormatJSON:
|
||||||
resolver := AnyResolverFromDescriptorSource(descSource)
|
resolver := AnyResolverFromDescriptorSource(descSource)
|
||||||
unmarshaler := jsonpb.Unmarshaler{AnyResolver: resolver, AllowUnknownFields: opts.AllowUnknownFields}
|
unmarshaler := jsonpb.Unmarshaler{AnyResolver: resolver, AllowUnknownFields: opts.AllowUnknownFields}
|
||||||
return NewJSONRequestParserWithUnmarshaler(in, unmarshaler), NewJSONFormatter(opts.EmitJSONDefaultFields, anyResolverWithFallback{AnyResolver: resolver}), nil
|
return NewJSONRequestParserWithUnmarshaler(in, unmarshaler), NewJSONFormatter(opts.EmitJSONDefaultFields, opts.OrigName, anyResolverWithFallback{AnyResolver: resolver}), nil
|
||||||
case FormatText:
|
case FormatText:
|
||||||
return NewTextRequestParser(in), NewTextFormatter(opts.IncludeTextSeparator), nil
|
return NewTextRequestParser(in), NewTextFormatter(opts.IncludeTextSeparator), nil
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue