gnostic icon indicating copy to clipboard operation
gnostic copied to clipboard

protoc-gen-openapi: google.protobuf.Duration not string

Open jan-sykora opened this issue 2 years ago • 1 comments

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.

jan-sykora avatar Apr 27 '22 12:04 jan-sykora

That seems like an oversight. We probably just need to hook up something like this.

timburks avatar Apr 27 '22 17:04 timburks

FYI: @timburks I took a stab at this in PR #401 and welcome any feedback you have.

nightlyone avatar Aug 06 '23 15:08 nightlyone