diff --git a/apps/protoc-gen-openapi/examples/google/example/library/v1/library.proto b/apps/protoc-gen-openapi/examples/google/example/library/v1/library.proto index 80912cf..87a13a1 100644 --- a/apps/protoc-gen-openapi/examples/google/example/library/v1/library.proto +++ b/apps/protoc-gen-openapi/examples/google/example/library/v1/library.proto @@ -22,6 +22,7 @@ import "google/api/client.proto"; import "google/api/field_behavior.proto"; import "google/api/resource.proto"; import "google/protobuf/empty.proto"; +import "google/protobuf/timestamp.proto"; option go_package = "google.golang.org/genproto/googleapis/example/library/v1;library"; option java_multiple_files = true; @@ -165,6 +166,14 @@ message Book { // Value indicating whether the book has been read. bool read = 4; + + // Creation timestamp. + google.protobuf.Timestamp create_time = 5 + [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Last update timestamp. + google.protobuf.Timestamp update_time = 6 + [(google.api.field_behavior) = OUTPUT_ONLY]; } // A Shelf contains a collection of books with a theme. @@ -183,6 +192,15 @@ message Shelf { // The theme of the shelf string theme = 2; + + // Creation timestamp. + google.protobuf.Timestamp create_time = 3 + [(google.api.field_behavior) = OUTPUT_ONLY]; + + // Last update timestamp. + google.protobuf.Timestamp update_time = 4 + [(google.api.field_behavior) = OUTPUT_ONLY]; + } // Request message for LibraryService.CreateShelf. diff --git a/apps/protoc-gen-openapi/examples/google/example/library/v1/openapi.yaml b/apps/protoc-gen-openapi/examples/google/example/library/v1/openapi.yaml index 3a47552..7bd08ea 100644 --- a/apps/protoc-gen-openapi/examples/google/example/library/v1/openapi.yaml +++ b/apps/protoc-gen-openapi/examples/google/example/library/v1/openapi.yaml @@ -282,6 +282,16 @@ components: read: type: boolean description: Value indicating whether the book has been read. + create_time: + readOnly: true + type: string + description: Creation timestamp. + format: RFC3339 + update_time: + readOnly: true + type: string + description: Last update timestamp. + format: RFC3339 description: A single book in the library. Empty: properties: {} @@ -334,4 +344,14 @@ components: theme: type: string description: The theme of the shelf + create_time: + readOnly: true + type: string + description: Creation timestamp. + format: RFC3339 + update_time: + readOnly: true + type: string + description: Last update timestamp. + format: RFC3339 description: A Shelf contains a collection of books with a theme. diff --git a/apps/protoc-gen-openapi/generator/openapi-v3.go b/apps/protoc-gen-openapi/generator/openapi-v3.go index 74757ef..03509d5 100644 --- a/apps/protoc-gen-openapi/generator/openapi-v3.go +++ b/apps/protoc-gen-openapi/generator/openapi-v3.go @@ -469,8 +469,15 @@ func (g *OpenAPIv3Generator) addSchemasToDocumentV3(d *v3.Document, file *protog k := field.Desc.Kind() switch k { case protoreflect.MessageKind: - // The field is described by a reference. - XRef = g.schemaReferenceForTypeName(fullMessageTypeName(field.Message)) + typeName := fullMessageTypeName(field.Message) + if typeName == ".google.protobuf.Timestamp" { + // Timestamps are serialized as strings + fieldSchema.Type = "string" + fieldSchema.Format = "RFC3339" + } else { + // The field is described by a reference. + XRef = g.schemaReferenceForTypeName(typeName) + } case protoreflect.StringKind: fieldSchema.Type = "string" case protoreflect.Int32Kind,