From f8da8a9811481b56c3d4fa5201bfa7ba6ca39d7d Mon Sep 17 00:00:00 2001 From: Prawn Date: Thu, 30 Sep 2021 12:38:22 +1300 Subject: [PATCH] Rendering google.protobuf.Struct as an OBJECT (#90) Co-authored-by: Chrusty <> --- internal/converter/testdata/proto/WellKnown.proto | 2 ++ internal/converter/testdata/wellknown.go | 4 ++++ internal/converter/types.go | 3 +++ 3 files changed, 9 insertions(+) diff --git a/internal/converter/testdata/proto/WellKnown.proto b/internal/converter/testdata/proto/WellKnown.proto index f55006e3..827c2c4d 100644 --- a/internal/converter/testdata/proto/WellKnown.proto +++ b/internal/converter/testdata/proto/WellKnown.proto @@ -1,6 +1,7 @@ syntax = "proto3"; package samples; import "google/protobuf/duration.proto"; +import "google/protobuf/struct.proto"; import "google/protobuf/wrappers.proto"; message WellKnown { @@ -10,5 +11,6 @@ message WellKnown { repeated google.protobuf.Int32Value list_of_integers = 4; // This is a duration: google.protobuf.Duration duration = 5; + google.protobuf.Struct struct = 6; } diff --git a/internal/converter/testdata/wellknown.go b/internal/converter/testdata/wellknown.go index 9bd8ea60..9fe05c22 100644 --- a/internal/converter/testdata/wellknown.go +++ b/internal/converter/testdata/wellknown.go @@ -35,6 +35,10 @@ const WellKnown = `{ "type": "string", "description": "This is a duration:", "format": "regex" + }, + "struct": { + "additionalProperties": true, + "type": "object" } }, "additionalProperties": true, diff --git a/internal/converter/types.go b/internal/converter/types.go index 8812a14e..b4da193a 100644 --- a/internal/converter/types.go +++ b/internal/converter/types.go @@ -28,6 +28,7 @@ var ( "BytesValue": true, "Value": true, "Duration": true, + "Struct": true, } ) @@ -439,6 +440,8 @@ func (c *Converter) recursiveConvertMessageType(curPkg *ProtoPackage, msg *descr } case "Duration": jsonSchemaType.Type = gojsonschema.TYPE_STRING + case "Struct": + jsonSchemaType.Type = gojsonschema.TYPE_OBJECT } // If we're allowing nulls then prepare a OneOf: