Skip to content

Swift codegen is encoding a date-time field as a date field in JSON #3232

@dylan-colaco

Description

@dylan-colaco
Description

The swift swagger codegen is generating code that uses a date formatter "yyyy-MM-dd" when encoding to JSON, for a field which is of type date-time in the server yaml file.

Swagger-codegen version

latest, done from a website: https://locus.sh/docs/index.html

Swagger declaration file content or url
Command line used for generation
Steps to reproduce

generate a swift swagger client from https://locus.sh/docs/index.html
Trigget time needs to have the time as well as date, but the time is truncated

Related issues

Yes, #1616

Suggest a Fix

Change the date formatter from "yyyy-MM-dd" to "yyyy-MM-dd HH:mm:ss" or something more appropriate so that the time information is not truncated.

Currently, the relevant generated swift code is:

private let dateFormatter: NSDateFormatter = {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
return dateFormatter
}()

extension NSDate: JSONEncodable {
func encodeToJSON() -> AnyObject {
return dateFormatter.stringFromDate(self)
}
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions