-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🦴 bones: Emit well-formed bones for well-known types (#26)
Render protobuf well-known types properly in JSON. Some well-known protobuf types have a JSON form different to how their proto representation would normally be rendered. For instance, timestamp and duration are rendered in JSON as a single string, but are in the proto file as a message. Boxed types are rendered as their value only and not nested in a message. Extend the test cases for all the well-known types by adding a new rpc and response message for the well-known cases. Slightly modify the test so the output is better when the golden file does not match. Add regenerated proto output files for `exemplar.proto`. This merges the following commits: * build: Fix proto find regex to exclude underscores * bones: Emit well-formed bones for well-known types Makefile | 2 +- bones/exemplar.go | 53 ++ bones/generate_test.go | 2 +- .../exemplar.Exemplar.WellKnown.jsonnet | 212 ++++++ pb/exemplar/exemplar.pb | Bin 1735 -> 9061 bytes pb/exemplar/exemplar.pb.go | 712 ++++++++++++++---- pb/exemplar/exemplar_grpc.pb.go | 36 + proto/exemplar/exemplar.proto | 42 ++ 8 files changed, 927 insertions(+), 132 deletions(-) Pull-Request: #26 Fixes: #23 Link: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf
- Loading branch information
Showing
8 changed files
with
927 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
212 changes: 212 additions & 0 deletions
212
bones/testdata/golden/exemplar/exemplar.Exemplar.WellKnown.jsonnet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
// exemplar.Exemplar.WellKnown (Unary) | ||
|
||
// Input: | ||
// { | ||
// request: { | ||
// name: "", // string | ||
// }, | ||
// } | ||
|
||
function(input) { | ||
response: { | ||
any: { // Any | ||
"@type": "type.googleapis.com/google.protobuf.Duration", | ||
value: "0s", | ||
}, | ||
api: { // Api | ||
name: "", // string | ||
methods: [ // repeated Method | ||
{ | ||
name: "", // string | ||
requestTypeUrl: "", // string | ||
requestStreaming: false, // bool | ||
responseTypeUrl: "", // string | ||
responseStreaming: false, // bool | ||
options: [ // repeated Option | ||
{ | ||
name: "", // string | ||
value: { // Any | ||
"@type": "type.googleapis.com/google.protobuf.Duration", | ||
value: "0s", | ||
}, | ||
} | ||
], | ||
syntax: "SYNTAX_PROTO3", // Syntax | ||
} | ||
], | ||
options: [ // repeated Option | ||
{ | ||
name: "", // string | ||
value: { // Any | ||
"@type": "type.googleapis.com/google.protobuf.Duration", | ||
value: "0s", | ||
}, | ||
} | ||
], | ||
version: "", // string | ||
sourceContext: { // SourceContext | ||
fileName: "", // string | ||
}, | ||
mixins: [ // repeated Mixin | ||
{ | ||
name: "", // string | ||
root: "", // string | ||
} | ||
], | ||
syntax: "SYNTAX_PROTO3", // Syntax | ||
}, | ||
boolValue: false, // BoolValue | ||
bytesValue: "", // BytesValue | ||
doubleValue: 0.0, // DoubleValue | ||
duration: "0s", // Duration | ||
empty: {}, // Empty | ||
anEnum: { // Enum | ||
name: "", // string | ||
enumvalue: [ // repeated EnumValue | ||
{ | ||
name: "", // string | ||
number: 0, // int32 | ||
options: [ // repeated Option | ||
{ | ||
name: "", // string | ||
value: { // Any | ||
"@type": "type.googleapis.com/google.protobuf.Duration", | ||
value: "0s", | ||
}, | ||
} | ||
], | ||
} | ||
], | ||
options: [ // repeated Option | ||
{ | ||
name: "", // string | ||
value: { // Any | ||
"@type": "type.googleapis.com/google.protobuf.Duration", | ||
value: "0s", | ||
}, | ||
} | ||
], | ||
sourceContext: { // SourceContext | ||
fileName: "", // string | ||
}, | ||
syntax: "SYNTAX_PROTO3", // Syntax | ||
}, | ||
enumValue: { // EnumValue | ||
name: "", // string | ||
number: 0, // int32 | ||
options: [ // repeated Option | ||
{ | ||
name: "", // string | ||
value: { // Any | ||
"@type": "type.googleapis.com/google.protobuf.Duration", | ||
value: "0s", | ||
}, | ||
} | ||
], | ||
}, | ||
field: { // Field | ||
kind: "TYPE_DOUBLE", // Kind | ||
cardinality: "CARDINALITY_OPTIONAL", // Cardinality | ||
number: 0, // int32 | ||
name: "", // string | ||
typeUrl: "", // string | ||
oneofIndex: 0, // int32 | ||
packed: false, // bool | ||
options: [ // repeated Option | ||
{ | ||
name: "", // string | ||
value: { // Any | ||
"@type": "type.googleapis.com/google.protobuf.Duration", | ||
value: "0s", | ||
}, | ||
} | ||
], | ||
jsonName: "", // string | ||
defaultValue: "", // string | ||
}, | ||
fieldMask: "field1.field2,field3", // FieldMask | ||
floatValue: 0.0, // FloatValue | ||
int32Value: 0, // Int32Value | ||
int64Value: 0, // Int64Value | ||
listValue: ["https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#value"], // ListValue | ||
method: { // Method | ||
name: "", // string | ||
requestTypeUrl: "", // string | ||
requestStreaming: false, // bool | ||
responseTypeUrl: "", // string | ||
responseStreaming: false, // bool | ||
options: [ // repeated Option | ||
{ | ||
name: "", // string | ||
value: { // Any | ||
"@type": "type.googleapis.com/google.protobuf.Duration", | ||
value: "0s", | ||
}, | ||
} | ||
], | ||
syntax: "SYNTAX_PROTO3", // Syntax | ||
}, | ||
mixin: { // Mixin | ||
name: "", // string | ||
root: "", // string | ||
}, | ||
nullValue: null, // NullValue | ||
anOption: { // Option | ||
name: "", // string | ||
value: { // Any | ||
"@type": "type.googleapis.com/google.protobuf.Duration", | ||
value: "0s", | ||
}, | ||
}, | ||
sourceContext: { // SourceContext | ||
fileName: "", // string | ||
}, | ||
stringValue: "", // StringValue | ||
struct: { // Struct | ||
structField: "https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#value", | ||
}, | ||
timestamp: "2006-01-02T15:04:05.999999999Z", // Timestamp | ||
type: { // Type | ||
name: "", // string | ||
fields: [ // repeated Field | ||
{ | ||
kind: "TYPE_DOUBLE", // Kind | ||
cardinality: "CARDINALITY_OPTIONAL", // Cardinality | ||
number: 0, // int32 | ||
name: "", // string | ||
typeUrl: "", // string | ||
oneofIndex: 0, // int32 | ||
packed: false, // bool | ||
options: [ // repeated Option | ||
{ | ||
name: "", // string | ||
value: { // Any | ||
"@type": "type.googleapis.com/google.protobuf.Duration", | ||
value: "0s", | ||
}, | ||
} | ||
], | ||
jsonName: "", // string | ||
defaultValue: "", // string | ||
} | ||
], | ||
oneofs: [""], // repeated string | ||
options: [ // repeated Option | ||
{ | ||
name: "", // string | ||
value: { // Any | ||
"@type": "type.googleapis.com/google.protobuf.Duration", | ||
value: "0s", | ||
}, | ||
} | ||
], | ||
sourceContext: { // SourceContext | ||
fileName: "", // string | ||
}, | ||
syntax: "SYNTAX_PROTO3", // Syntax | ||
}, | ||
uint32Value: 0, // UInt32Value | ||
uint64Value: 0, // UInt64Value | ||
value: "https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#value", // Value | ||
}, | ||
} |
Binary file not shown.
Oops, something went wrong.