gnostic
gnostic copied to clipboard
protoc-gen-openapi: google.protobuf.Duration not string
Why is the google.protobuf.Duration converted into OpenAPI as a custom object and not as a string (the JSON format)?
I would expect it to be represented by type: string
. Especially when the google.protobuf.Timestamp (which holds the same structure as google.protobuf.Duration) is converted into string (JSON format) as well.
For instance:
message Baz {
google.protobuf.Timestamp baz_time = 1;
google.protobuf.Duration baz_duration = 2;
}
// package google.protobuf
message Timestamp {
int64 seconds = 1;
int32 nanos = 2;
}
// package google.protobuf
message Duration {
int64 seconds = 1;
int32 nanos = 2;
}
is converted by protoc-gen-openapi into
openapi: 3.0.3
components:
schemas:
Baz:
properties:
bazTime:
type: string
format: date-time
barDuration:
$ref: '#/components/schemas/Duration'
Duration:
type: object
properties:
seconds:
type: integer
format: int64
nanos:
type: integer
format: int32
See google.protobuf.Duration JSON description and google.protobuf.Timestamp JSON description for more info.
That seems like an oversight. We probably just need to hook up something like this.
FYI: @timburks I took a stab at this in PR #401 and welcome any feedback you have.