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

Commit

Permalink
Add google.protobuf.Duration well-known type (#64)
Browse files Browse the repository at this point in the history
* feat: add well known type duration

Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>

* ci: remove unrelated files

Signed-off-by: Grant Timmerman <timmerman+devrel@google.com>
  • Loading branch information
grant authored Jul 11, 2021
1 parent dc9f108 commit 0f15c52
Show file tree
Hide file tree
Showing 4 changed files with 13 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,11 +1,13 @@
syntax = "proto3";
package samples;
import "google/protobuf/duration.proto";
import "google/protobuf/wrappers.proto";

message WellKnown {
google.protobuf.StringValue string_value = 1;
map<int32, google.protobuf.Int32Value> map_of_integers = 2;
map<int32, int32> map_of_scalar_integers = 3;
repeated google.protobuf.Int32Value list_of_integers = 4;
google.protobuf.Duration duration = 5;
}

4 changes: 4 additions & 0 deletions internal/converter/testdata/wellknown.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const WellKnown = `{
"type": "integer"
},
"type": "array"
},
"duration": {
"additionalProperties": true,
"type": "string"
}
},
"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 @@ -26,6 +26,7 @@ var (
"StringValue": true,
"BytesValue": true,
"Value": true,
"Duration": true,
}
)

Expand Down Expand Up @@ -435,6 +436,8 @@ func (c *Converter) recursiveConvertMessageType(curPkg *ProtoPackage, msg *descr
{Type: gojsonschema.TYPE_OBJECT},
{Type: gojsonschema.TYPE_STRING},
}
case "Duration":
wellKnownSchema.Type = gojsonschema.TYPE_STRING
}

// If we're allowing nulls then prepare a OneOf:
Expand Down
4 changes: 4 additions & 0 deletions jsonschemas/WellKnown.jsonschema
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"type": "integer"
},
"type": "array"
},
"duration": {
"additionalProperties": true,
"type": "string"
}
},
"additionalProperties": true,
Expand Down

0 comments on commit 0f15c52

Please sign in to comment.