-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support generating values of type URL from JSON Schema #514
Comments
If correctly specified in created_at:
type: string
format: date-time The generated Swift code will use the proper /// - Remark: Generated from `#/components/schemas/MyType/created_at`.
package var created_at: Foundation.Date I'm guessing you might be missing |
What @MahdiBM said is right, URL is not, and that's because a "URL" format is not officially supported in OpenAPI 3.0, but is kind of be supported in OpenAPI 3.1 through JSON Schema 2020-12: https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-7.3.5 OpenAPI 3.1: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#data-types I'll repurpose this issue to track adding "URL" format support. |
How can I specify the date format here? For example, I have a date value in the response
In the past, I use a custom JSONDecoder here. extension DateFormatter {
public static var discourse: DateFormatter {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
formatter.timeZone = .gmt
return formatter
}
}
extension JSONDecoder {
public static var discourse: JSONDecoder {
let decoder = JSONDecoder()
decoder.dateDecodingStrategy = .formatted(.discourse)
return decoder
}
} I guess now I need to config it via |
Yes. We provided a new date transcoder in the latest release of the runtime library that handles ISO8601 with fractional seconds, which, looking at your JSON snippet, looks to be what you might need here. |
Thanks. I'll give it a try. |
Motivation
For the above json data. The currently valid
openapi.yml
will usestring
to represent "time" and "url".I'm hoping to somehow add support for URL and Date types directly on swift-openapi-generator.
Proposed solution
Add a variant for OpenAPI 3.1 to allow "url" and "date" for type. (Not recommended)
...
Alternatives considered
None
Additional information
No response
The text was updated successfully, but these errors were encountered: