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).`))
|
||||
emitDefaults = flags.Bool("emit-defaults", false, prettify(`
|
||||
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(`
|
||||
The name of a file to be written that will contain a FileDescriptorSet
|
||||
proto. With the list and describe verbs, the listed or described
|
||||
|
|
@ -367,6 +369,9 @@ func main() {
|
|||
if *emitDefaults && *format != "json" {
|
||||
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()
|
||||
|
||||
|
|
@ -801,6 +806,7 @@ func main() {
|
|||
includeSeparators := verbosityLevel == 0
|
||||
options := grpcurl.FormatOptions{
|
||||
EmitJSONDefaultFields: *emitDefaults,
|
||||
OrigName: *keepProtoNames,
|
||||
IncludeTextSeparator: includeSeparators,
|
||||
AllowUnknownFields: *allowUnknownFields,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,10 +133,11 @@ type Formatter func(proto.Message) (string, error)
|
|||
// include empty/default values (instead of just omitted them) if emitDefaults
|
||||
// is true. The given resolver is used to assist with encoding of
|
||||
// google.protobuf.Any messages.
|
||||
func NewJSONFormatter(emitDefaults bool, resolver jsonpb.AnyResolver) Formatter {
|
||||
func NewJSONFormatter(emitDefaults, origName bool, resolver jsonpb.AnyResolver) Formatter {
|
||||
marshaler := jsonpb.Marshaler{
|
||||
EmitDefaults: emitDefaults,
|
||||
AnyResolver: resolver,
|
||||
OrigName: origName,
|
||||
}
|
||||
// Workaround for indentation issue in jsonpb with Any messages.
|
||||
// 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.
|
||||
// FormatText only flag.
|
||||
IncludeTextSeparator bool
|
||||
|
||||
// OrigName specifies whether to use the original protobuf name for fields.
|
||||
OrigName bool
|
||||
}
|
||||
|
||||
// RequestParserAndFormatter returns a request parser and formatter for the
|
||||
|
|
@ -409,7 +413,7 @@ func RequestParserAndFormatter(format Format, descSource DescriptorSource, in io
|
|||
case FormatJSON:
|
||||
resolver := AnyResolverFromDescriptorSource(descSource)
|
||||
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:
|
||||
return NewTextRequestParser(in), NewTextFormatter(opts.IncludeTextSeparator), nil
|
||||
default:
|
||||
|
|
|
|||
Loading…
Reference in New Issue