-
-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
I have a Content object that includes a date, that I encode as an ISO 8601 string on output:
struct Info: Content {
let id: UUID
let createdDate: Date
static var openAPISchema: SchemaObject {
.object(
properties: [
"id": .string(format: .uuid, description: "Unique identifier"),
"createdDate": .string(format: .dateTime, description: "ISO 8601 date-time"),
],
required: ["id", "createdDate"]
)
}
enum CodingKeys: String, CodingKey {
case id
case createdDate
}
func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.id, forKey: .id)
let formatter = ISO8601DateFormatter()
formatter.timeZone = TimeZone(secondsFromGMT: 0)
let createdDateString = formatter.string(from: self.createdDate)
try container.encodeIfPresent(createdDateString, forKey: .createdDate)
}
}
No matter what I do, however, the OpenAPI docs report createdDate as integer($int64) and seems to completely ignore the openAPISchema object I've defined. How can I override the type of createdDate to ensure that OpenAPI reports it as an ISO 8601 formatted string?
Metadata
Metadata
Assignees
Labels
No labels