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

Commit

Permalink
Rendering google.protobuf.Struct as an OBJECT (#90)
Browse files Browse the repository at this point in the history
Co-authored-by: Chrusty <>
  • Loading branch information
chrusty authored Sep 29, 2021
1 parent 3469322 commit f8da8a9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/converter/testdata/proto/WellKnown.proto
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
}

4 changes: 4 additions & 0 deletions internal/converter/testdata/wellknown.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ const WellKnown = `{
"type": "string",
"description": "This is a duration:",
"format": "regex"
},
"struct": {
"additionalProperties": true,
"type": "object"
}
},
"additionalProperties": true,
Expand Down
3 changes: 3 additions & 0 deletions internal/converter/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
"BytesValue": true,
"Value": true,
"Duration": true,
"Struct": true,
}
)

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f8da8a9

Please sign in to comment.