Skip to content
This repository was archived by the owner on Jun 20, 2024. It is now read-only.

Commit 997d0a0

Browse files
chrustyPrawn
andauthored
Treating google.protobuf.ListValue as an array (#145)
* Treating google.protobuf.ListValue as an array * Adding ListValue to our list of well-known types --------- Co-authored-by: Prawn <Prawn@Prawn>
1 parent f7db60f commit 997d0a0

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

internal/converter/testdata/google_value.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ const GoogleValue = `{
2626
],
2727
"title": "Value",
2828
"description": "` + "`Value`" + ` represents a dynamically typed value which can be either null, a number, a string, a boolean, a recursive struct value, or a list of values. A producer of value is expected to set one of these variants. Absence of any variant indicates an error. The JSON representation for ` + "`Value`" + ` is JSON value."
29+
},
30+
"some_list": {
31+
"additionalProperties": true,
32+
"type": "array"
2933
}
3034
},
3135
"additionalProperties": true,
3236
"type": "object",
3337
"title": "Google Value"
3438
}
3539
}
36-
}`
40+
}
41+
`
3742

38-
const GoogleValueFail = `{"arg": null}`
43+
const GoogleValueFail = `{"arg": null, "some_list": 4}`
3944

40-
const GoogleValuePass = `{"arg": 12345}`
45+
const GoogleValuePass = `{"arg": 12345, "some_list": [1,2,3,4]}`

internal/converter/testdata/proto/GoogleValue.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ import "google/protobuf/struct.proto";
55

66
message GoogleValue {
77
google.protobuf.Value arg = 1;
8+
google.protobuf.ListValue some_list = 2;
89
}

internal/converter/types.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ var (
1919
globalPkg = newProtoPackage(nil, "")
2020

2121
wellKnownTypes = map[string]bool{
22+
"BoolValue": true,
23+
"BytesValue": true,
2224
"DoubleValue": true,
25+
"Duration": true,
2326
"FloatValue": true,
24-
"Int64Value": true,
25-
"UInt64Value": true,
2627
"Int32Value": true,
27-
"UInt32Value": true,
28-
"BoolValue": true,
28+
"Int64Value": true,
29+
"ListValue": true,
2930
"StringValue": true,
30-
"BytesValue": true,
31-
"Value": true,
32-
"Duration": true,
3331
"Struct": true,
32+
"UInt32Value": true,
33+
"UInt64Value": true,
34+
"Value": true,
3435
}
3536
)
3637

@@ -541,6 +542,8 @@ func (c *Converter) recursiveConvertMessageType(curPkg *ProtoPackage, msgDesc *d
541542
jsonSchemaType.Type = gojsonschema.TYPE_STRING
542543
case "Struct":
543544
jsonSchemaType.Type = gojsonschema.TYPE_OBJECT
545+
case "ListValue":
546+
jsonSchemaType.Type = gojsonschema.TYPE_ARRAY
544547
}
545548

546549
// If we're allowing nulls then prepare a OneOf:

0 commit comments

Comments
 (0)