diff --git a/docs/generators/swift5.md b/docs/generators/swift5.md index 92d3265b1bc0426723d3b2f4c08d5ec324c8e464..4c9658e8d9341a1759f254e3ebaa64db63b5b84c 100644 --- a/docs/generators/swift5.md +++ b/docs/generators/swift5.md @@ -77,6 +77,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl <li>Character</li> <li>Data</li> <li>Date</li> +<li>DateWithoutTime</li> <li>Decimal</li> <li>Double</li> <li>Float</li> diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java index 4c0b8326a452065f36fb06c2682724f777e7b41f..6e5be7bb4927d3a2004ea8665ce613f347d5578e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/Swift5ClientCodegen.java @@ -134,6 +134,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig "String", "Data", "Date", + "DateWithoutTime", "Character", "UUID", "URL", @@ -221,7 +222,7 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig typeMapping.put("array", "Array"); typeMapping.put("map", "Dictionary"); typeMapping.put("set", "Set"); - typeMapping.put("date", "Date"); + typeMapping.put("date", "DateWithoutTime"); typeMapping.put("Date", "Date"); typeMapping.put("DateTime", "Date"); typeMapping.put("boolean", "Bool"); @@ -538,9 +539,6 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig supportingFiles.add(new SupportingFile("CodableHelper.mustache", sourceFolder, "CodableHelper.swift")); - supportingFiles.add(new SupportingFile("OpenISO8601DateFormatter.mustache", - sourceFolder, - "OpenISO8601DateFormatter.swift")); supportingFiles.add(new SupportingFile("JSONDataEncoding.mustache", sourceFolder, "JSONDataEncoding.swift")); @@ -572,6 +570,12 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig supportingFiles.add(new SupportingFile("Extensions.mustache", sourceFolder, "Extensions.swift")); + supportingFiles.add(new SupportingFile("OpenISO8601DateFormatter.mustache", + sourceFolder, + "OpenISO8601DateFormatter.swift")); + supportingFiles.add(new SupportingFile("DateWithoutTime.mustache", + sourceFolder, + "DateWithoutTime.swift")); supportingFiles.add(new SupportingFile("APIs.mustache", sourceFolder, "APIs.swift")); diff --git a/modules/openapi-generator/src/main/resources/swift5/DateWithoutTime.mustache b/modules/openapi-generator/src/main/resources/swift5/DateWithoutTime.mustache new file mode 100644 index 0000000000000000000000000000000000000000..dc472f0318110a99606d135eae75b8e40157b0a0 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/swift5/DateWithoutTime.mustache @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct DateWithoutTime: Codable, Hashable, Equatable { + {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let wrappedDate: Date + {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let timezone: TimeZone + + {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/swift5/Extensions.mustache b/modules/openapi-generator/src/main/resources/swift5/Extensions.mustache index b18821ae14b189baa1c2cf82a4498f6dd79a3385..c7343cdeddfa2efe62d54f30be21e1d65ad71408 100644 --- a/modules/openapi-generator/src/main/resources/swift5/Extensions.mustache +++ b/modules/openapi-generator/src/main/resources/swift5/Extensions.mustache @@ -93,6 +93,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/modules/openapi-generator/src/main/resources/swift5/OpenISO8601DateFormatter.mustache b/modules/openapi-generator/src/main/resources/swift5/OpenISO8601DateFormatter.mustache index 29c28dac3ffb13668ac383df89e0d67b209cc6db..dd451062fb04803f4f90c9ef98be6704a790c856 100644 --- a/modules/openapi-generator/src/main/resources/swift5/OpenISO8601DateFormatter.mustache +++ b/modules/openapi-generator/src/main/resources/swift5/OpenISO8601DateFormatter.mustache @@ -18,6 +18,15 @@ import Foundation return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ import Foundation override {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift5/Swift5ClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift5/Swift5ClientCodegenTest.java index 0f7e12737165f59425386d0dc7b89804a1583d15..6a3ebf766a24845450b20fa896bfbce9d170ad59 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift5/Swift5ClientCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift5/Swift5ClientCodegenTest.java @@ -131,8 +131,8 @@ public class Swift5ClientCodegenTest { final Operation p = openAPI.getPaths().get(path).getPost(); final CodegenOperation op = codegen.fromOperation(path, "post", p, null); - Assert.assertEquals(op.returnType, "Date"); - Assert.assertEquals(op.bodyParam.dataType, "Date"); + Assert.assertEquals(op.returnType, "DateWithoutTime"); + Assert.assertEquals(op.bodyParam.dataType, "DateWithoutTime"); } @Test(enabled = true) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift5/Swift5ModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift5/Swift5ModelTest.java index 895bb1703bc1da5ab4327880b2d31a6c016c820e..1f1415d68e4e17da363f3c7f99f5ee3b5a3ad54a 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift5/Swift5ModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/swift5/Swift5ModelTest.java @@ -114,10 +114,10 @@ public class Swift5ModelTest { final CodegenProperty property7 = cm.vars.get(6); Assert.assertEquals(property7.baseName, "dateOfBirth"); - Assert.assertEquals(property7.dataType, "Date"); + Assert.assertEquals(property7.dataType, "DateWithoutTime"); Assert.assertEquals(property7.name, "dateOfBirth"); Assert.assertNull(property7.defaultValue); - Assert.assertEquals(property7.baseType, "Date"); + Assert.assertEquals(property7.baseType, "DateWithoutTime"); Assert.assertFalse(property7.required); Assert.assertFalse(property7.isContainer); } diff --git a/samples/client/petstore/swift5/alamofireLibrary/.openapi-generator/FILES b/samples/client/petstore/swift5/alamofireLibrary/.openapi-generator/FILES index 5a7c78dd6a5733e3e9d99490b9efedc3d86c0e61..6433346732914073e646f9c90635f0774d3800b4 100644 --- a/samples/client/petstore/swift5/alamofireLibrary/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/alamofireLibrary/.openapi-generator/FILES @@ -13,6 +13,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index d980142c6ab2517d69c9df99ea69fd8d32a5e95c..0c2a9f639d6af624b5a8173279238527b33292cc 100644 --- a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -333,7 +333,7 @@ open class FakeAPI { - parameter completion: completion handler to receive the data and the error objects */ @discardableResult - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { return testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute(apiResponseQueue) { result in switch result { case .success: @@ -367,7 +367,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 0b17438a7c874ff681653a0aa6f08922a3fc2ef2..5fceb90be830934a27b826e6b1e95ed74cdc05a8 100644 --- a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift index 0a329955482409ea55eb044a727588c27e0f98ad..3d0be76a9b5caf0f1d946d7d096ee3bf391c8110 100644 --- a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift @@ -21,12 +21,12 @@ public struct FormatTest: Codable, JSONEncodable, Hashable { public var string: String? public var byte: Data public var binary: URL? - public var date: Date + public var date: DateWithoutTime public var dateTime: Date? public var uuid: UUID? public var password: String - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/alamofireLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/alamofireLibrary/docs/FakeAPI.md b/samples/client/petstore/swift5/alamofireLibrary/docs/FakeAPI.md index 69b1faa2b9918b39c1f0b873bc6670cd49ace31a..ce9c02f74b50d2a5e7336ac316092b1f4f96c339 100644 --- a/samples/client/petstore/swift5/alamofireLibrary/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/alamofireLibrary/docs/FakeAPI.md @@ -364,7 +364,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -386,7 +386,7 @@ let int64 = 987 // Int64 | None (optional) let float = 987 // Float | None (optional) let string = "string_example" // String | None (optional) let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -418,7 +418,7 @@ Name | Type | Description | Notes **float** | **Float** | None | [optional] **string** | **String** | None | [optional] **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/alamofireLibrary/docs/FormatTest.md b/samples/client/petstore/swift5/alamofireLibrary/docs/FormatTest.md index f74d94f6c46a8260abe3a68e30578118f76ae69c..18e421e514f18c1922531a72f18ecfd43d65cac6 100644 --- a/samples/client/petstore/swift5/alamofireLibrary/docs/FormatTest.md +++ b/samples/client/petstore/swift5/alamofireLibrary/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/asyncAwaitLibrary/.openapi-generator/FILES b/samples/client/petstore/swift5/asyncAwaitLibrary/.openapi-generator/FILES index c81943baf2afa14915ffbb3a1f05ddd21b2ee457..8da82f82679772a323bdc9bcf444c7424a1300f8 100644 --- a/samples/client/petstore/swift5/asyncAwaitLibrary/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/asyncAwaitLibrary/.openapi-generator/FILES @@ -12,6 +12,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index e953c1a2696e8aecc9da58f81dea13019adeb6b5..c69fa4512b52b8d348e29b889afe7a8438d1457e 100644 --- a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -416,7 +416,7 @@ open class FakeAPI { - returns: Void */ @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) async throws { + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) async throws { var requestTask: RequestTask? return try await withTaskCancellationHandler { try Task.checkCancellation() @@ -463,7 +463,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 0b17438a7c874ff681653a0aa6f08922a3fc2ef2..5fceb90be830934a27b826e6b1e95ed74cdc05a8 100644 --- a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift index 0a329955482409ea55eb044a727588c27e0f98ad..3d0be76a9b5caf0f1d946d7d096ee3bf391c8110 100644 --- a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift @@ -21,12 +21,12 @@ public struct FormatTest: Codable, JSONEncodable, Hashable { public var string: String? public var byte: Data public var binary: URL? - public var date: Date + public var date: DateWithoutTime public var dateTime: Date? public var uuid: UUID? public var password: String - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/asyncAwaitLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/asyncAwaitLibrary/docs/FakeAPI.md b/samples/client/petstore/swift5/asyncAwaitLibrary/docs/FakeAPI.md index 69b1faa2b9918b39c1f0b873bc6670cd49ace31a..ce9c02f74b50d2a5e7336ac316092b1f4f96c339 100644 --- a/samples/client/petstore/swift5/asyncAwaitLibrary/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/asyncAwaitLibrary/docs/FakeAPI.md @@ -364,7 +364,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -386,7 +386,7 @@ let int64 = 987 // Int64 | None (optional) let float = 987 // Float | None (optional) let string = "string_example" // String | None (optional) let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -418,7 +418,7 @@ Name | Type | Description | Notes **float** | **Float** | None | [optional] **string** | **String** | None | [optional] **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/asyncAwaitLibrary/docs/FormatTest.md b/samples/client/petstore/swift5/asyncAwaitLibrary/docs/FormatTest.md index f74d94f6c46a8260abe3a68e30578118f76ae69c..18e421e514f18c1922531a72f18ecfd43d65cac6 100644 --- a/samples/client/petstore/swift5/asyncAwaitLibrary/docs/FormatTest.md +++ b/samples/client/petstore/swift5/asyncAwaitLibrary/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/combineLibrary/.openapi-generator/FILES b/samples/client/petstore/swift5/combineLibrary/.openapi-generator/FILES index c81943baf2afa14915ffbb3a1f05ddd21b2ee457..8da82f82679772a323bdc9bcf444c7424a1300f8 100644 --- a/samples/client/petstore/swift5/combineLibrary/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/combineLibrary/.openapi-generator/FILES @@ -12,6 +12,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index 6920a9c53b1a5014eff2111b715208376de4f1a7..d6c3b00173ed082fcdf821c0cbc6298408d5a78d 100644 --- a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -392,7 +392,7 @@ open class FakeAPI { */ #if canImport(Combine) @available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> AnyPublisher<Void, Error> { + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> AnyPublisher<Void, Error> { var requestTask: RequestTask? return Future<Void, Error> { promise in requestTask = testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute { result in @@ -434,7 +434,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 0b17438a7c874ff681653a0aa6f08922a3fc2ef2..5fceb90be830934a27b826e6b1e95ed74cdc05a8 100644 --- a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift index 0a329955482409ea55eb044a727588c27e0f98ad..3d0be76a9b5caf0f1d946d7d096ee3bf391c8110 100644 --- a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift @@ -21,12 +21,12 @@ public struct FormatTest: Codable, JSONEncodable, Hashable { public var string: String? public var byte: Data public var binary: URL? - public var date: Date + public var date: DateWithoutTime public var dateTime: Date? public var uuid: UUID? public var password: String - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/combineLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/combineLibrary/docs/FakeAPI.md b/samples/client/petstore/swift5/combineLibrary/docs/FakeAPI.md index 69b1faa2b9918b39c1f0b873bc6670cd49ace31a..ce9c02f74b50d2a5e7336ac316092b1f4f96c339 100644 --- a/samples/client/petstore/swift5/combineLibrary/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/combineLibrary/docs/FakeAPI.md @@ -364,7 +364,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -386,7 +386,7 @@ let int64 = 987 // Int64 | None (optional) let float = 987 // Float | None (optional) let string = "string_example" // String | None (optional) let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -418,7 +418,7 @@ Name | Type | Description | Notes **float** | **Float** | None | [optional] **string** | **String** | None | [optional] **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/combineLibrary/docs/FormatTest.md b/samples/client/petstore/swift5/combineLibrary/docs/FormatTest.md index f74d94f6c46a8260abe3a68e30578118f76ae69c..18e421e514f18c1922531a72f18ecfd43d65cac6 100644 --- a/samples/client/petstore/swift5/combineLibrary/docs/FormatTest.md +++ b/samples/client/petstore/swift5/combineLibrary/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/default/.openapi-generator/FILES b/samples/client/petstore/swift5/default/.openapi-generator/FILES index 205dadc060a149fbff13f26dcbfee48133bfb0de..5616f2516de1fe8fb4fe596a7f1aaf425c413b38 100644 --- a/samples/client/petstore/swift5/default/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/default/.openapi-generator/FILES @@ -12,6 +12,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index 78c64f76f11762a06cd3e6704bf0a26dade441d4..371a54bfcae69a171dd78e50e8d75565e7a4bc78 100644 --- a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -377,7 +377,7 @@ open class FakeAPI { - parameter completion: completion handler to receive the data and the error objects */ @discardableResult - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { return testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute(apiResponseQueue) { result in switch result { case .success: @@ -411,7 +411,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 0b17438a7c874ff681653a0aa6f08922a3fc2ef2..5fceb90be830934a27b826e6b1e95ed74cdc05a8 100644 --- a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift index 2892d53a3b6ccb83ccf259fae7f3dd1ac05e539b..c46975bdf6df5f54280a9132db8c4c7d46789cdd 100644 --- a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift @@ -21,13 +21,13 @@ public struct FormatTest: Codable, JSONEncodable, Hashable { public var string: String? public var byte: Data public var binary: URL? - public var date: Date + public var date: DateWithoutTime public var dateTime: Date? public var uuid: UUID? public var password: String public var bigDecimal: Decimal? - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String, bigDecimal: Decimal? = nil) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String, bigDecimal: Decimal? = nil) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/default/docs/FakeAPI.md b/samples/client/petstore/swift5/default/docs/FakeAPI.md index 5004221689ee1de618dd9033ae199fdde3742df3..4ad460377dd1e10fbbb59cfd66a138e7b585b26e 100644 --- a/samples/client/petstore/swift5/default/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/default/docs/FakeAPI.md @@ -416,7 +416,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -438,7 +438,7 @@ let int64 = 987 // Int64 | None (optional) let float = 987 // Float | None (optional) let string = "string_example" // String | None (optional) let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -470,7 +470,7 @@ Name | Type | Description | Notes **float** | **Float** | None | [optional] **string** | **String** | None | [optional] **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/default/docs/FormatTest.md b/samples/client/petstore/swift5/default/docs/FormatTest.md index 55de2e05ecd9f3e2a28ff55ccae39f0c817f99fe..138bf4881cc4f1b2e702911ba4944df316c369b0 100644 --- a/samples/client/petstore/swift5/default/docs/FormatTest.md +++ b/samples/client/petstore/swift5/default/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/deprecated/.openapi-generator/FILES b/samples/client/petstore/swift5/deprecated/.openapi-generator/FILES index b78ea60c11234f7bafa49ca258e76d1b56a42c01..d146cfb2afba9ab9980c652543b7cdc7a33218b9 100644 --- a/samples/client/petstore/swift5/deprecated/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/deprecated/.openapi-generator/FILES @@ -9,6 +9,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 0b17438a7c874ff681653a0aa6f08922a3fc2ef2..5fceb90be830934a27b826e6b1e95ed74cdc05a8 100644 --- a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/deprecated/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/frozenEnums/.openapi-generator/FILES b/samples/client/petstore/swift5/frozenEnums/.openapi-generator/FILES index c81943baf2afa14915ffbb3a1f05ddd21b2ee457..8da82f82679772a323bdc9bcf444c7424a1300f8 100644 --- a/samples/client/petstore/swift5/frozenEnums/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/frozenEnums/.openapi-generator/FILES @@ -12,6 +12,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index eac6aeb1a3ce053e186f6286e2ba8e7aa61e5b45..c75124266eaf148c24ac2250c69544a29e454228 100644 --- a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -333,7 +333,7 @@ open class FakeAPI { - parameter completion: completion handler to receive the data and the error objects */ @discardableResult - open class func testEndpointParameters(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double, string: String? = nil, patternWithoutDelimiter: String, byte: Data, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { + open class func testEndpointParameters(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double, string: String? = nil, patternWithoutDelimiter: String, byte: Data, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { return testEndpointParametersWithRequestBuilder(integer: integer, int32: int32, int64: int64, number: number, float: float, double: double, string: string, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute(apiResponseQueue) { result in switch result { case .success: @@ -367,7 +367,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - open class func testEndpointParametersWithRequestBuilder(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double, string: String? = nil, patternWithoutDelimiter: String, byte: Data, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + open class func testEndpointParametersWithRequestBuilder(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double, string: String? = nil, patternWithoutDelimiter: String, byte: Data, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 0b17438a7c874ff681653a0aa6f08922a3fc2ef2..5fceb90be830934a27b826e6b1e95ed74cdc05a8 100644 --- a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift index 0a329955482409ea55eb044a727588c27e0f98ad..3d0be76a9b5caf0f1d946d7d096ee3bf391c8110 100644 --- a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift @@ -21,12 +21,12 @@ public struct FormatTest: Codable, JSONEncodable, Hashable { public var string: String? public var byte: Data public var binary: URL? - public var date: Date + public var date: DateWithoutTime public var dateTime: Date? public var uuid: UUID? public var password: String - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/frozenEnums/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/frozenEnums/docs/FakeAPI.md b/samples/client/petstore/swift5/frozenEnums/docs/FakeAPI.md index e33bd2d35fbcf22f8e42c7b10ef2c91ec93a757a..931c2bd9a05480bd6def4433fa3236aa4fff705c 100644 --- a/samples/client/petstore/swift5/frozenEnums/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/frozenEnums/docs/FakeAPI.md @@ -364,7 +364,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double, string: String? = nil, patternWithoutDelimiter: String, byte: Data, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) + open class func testEndpointParameters(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double, string: String? = nil, patternWithoutDelimiter: String, byte: Data, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -386,7 +386,7 @@ let string = "string_example" // String | None (optional) let patternWithoutDelimiter = "patternWithoutDelimiter_example" // String | None let byte = Data([9, 8, 7]) // Data | None let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -418,7 +418,7 @@ Name | Type | Description | Notes **patternWithoutDelimiter** | **String** | None | **byte** | **Data** | None | **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/frozenEnums/docs/FormatTest.md b/samples/client/petstore/swift5/frozenEnums/docs/FormatTest.md index f74d94f6c46a8260abe3a68e30578118f76ae69c..18e421e514f18c1922531a72f18ecfd43d65cac6 100644 --- a/samples/client/petstore/swift5/frozenEnums/docs/FormatTest.md +++ b/samples/client/petstore/swift5/frozenEnums/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/nonPublicApi/.openapi-generator/FILES b/samples/client/petstore/swift5/nonPublicApi/.openapi-generator/FILES index c81943baf2afa14915ffbb3a1f05ddd21b2ee457..8da82f82679772a323bdc9bcf444c7424a1300f8 100644 --- a/samples/client/petstore/swift5/nonPublicApi/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/nonPublicApi/.openapi-generator/FILES @@ -12,6 +12,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index 344309b20bce5b75650ba05f0de75942d883cf4d..6f8a28fab6ae1a2187ac094e110ebd9c7f2e9b49 100644 --- a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -333,7 +333,7 @@ internal class FakeAPI { - parameter completion: completion handler to receive the data and the error objects */ @discardableResult - internal class func testEndpointParameters(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double, string: String? = nil, patternWithoutDelimiter: String, byte: Data, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { + internal class func testEndpointParameters(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double, string: String? = nil, patternWithoutDelimiter: String, byte: Data, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { return testEndpointParametersWithRequestBuilder(integer: integer, int32: int32, int64: int64, number: number, float: float, double: double, string: string, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute(apiResponseQueue) { result in switch result { case .success: @@ -367,7 +367,7 @@ internal class FakeAPI { - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - internal class func testEndpointParametersWithRequestBuilder(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double, string: String? = nil, patternWithoutDelimiter: String, byte: Data, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + internal class func testEndpointParametersWithRequestBuilder(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double, string: String? = nil, patternWithoutDelimiter: String, byte: Data, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..cb3c73aa0e5075357978e4bbb7b8b44560ed4f1d --- /dev/null +++ b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +internal struct DateWithoutTime: Codable, Hashable, Equatable { + internal let wrappedDate: Date + internal let timezone: TimeZone + + internal enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + internal init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + internal init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + internal init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + internal func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Extensions.swift index c7e2df56bc9db81a3f0f8e3f7c65bc7beab16e6d..c51a3bef5eb47725d424a4299ce4bfa127cbcadf 100644 --- a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift index 87dd9fb1c4d27f5cee2b17ac3c6e5f366e4f960f..0be6eedcbab15e38430eea23e079d92e2ec07a65 100644 --- a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift @@ -21,12 +21,12 @@ internal struct FormatTest: Codable, JSONEncodable, Hashable { internal var string: String? internal var byte: Data internal var binary: URL? - internal var date: Date + internal var date: DateWithoutTime internal var dateTime: Date? internal var uuid: UUID? internal var password: String - internal init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { + internal init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index cc04b4e3a498de519a07f244e80c8b5a437dd660..ff0d9d08eb9d13a37db57fd8e310220fbaa7c7ac 100644 --- a/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/nonPublicApi/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ internal class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ internal class OpenISO8601DateFormatter: DateFormatter { override internal func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/nonPublicApi/docs/FakeAPI.md b/samples/client/petstore/swift5/nonPublicApi/docs/FakeAPI.md index 1cc75c5aab2cfd7c0ad4bd04597a57a95425d042..f903b639267214b91fb673355483ca22d37e9d3c 100644 --- a/samples/client/petstore/swift5/nonPublicApi/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/nonPublicApi/docs/FakeAPI.md @@ -364,7 +364,7 @@ No authorization required # **testEndpointParameters** ```swift - internal class func testEndpointParameters(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double, string: String? = nil, patternWithoutDelimiter: String, byte: Data, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) + internal class func testEndpointParameters(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double, string: String? = nil, patternWithoutDelimiter: String, byte: Data, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -386,7 +386,7 @@ let string = "string_example" // String | None (optional) let patternWithoutDelimiter = "patternWithoutDelimiter_example" // String | None let byte = Data([9, 8, 7]) // Data | None let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -418,7 +418,7 @@ Name | Type | Description | Notes **patternWithoutDelimiter** | **String** | None | **byte** | **Data** | None | **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/nonPublicApi/docs/FormatTest.md b/samples/client/petstore/swift5/nonPublicApi/docs/FormatTest.md index f74d94f6c46a8260abe3a68e30578118f76ae69c..18e421e514f18c1922531a72f18ecfd43d65cac6 100644 --- a/samples/client/petstore/swift5/nonPublicApi/docs/FormatTest.md +++ b/samples/client/petstore/swift5/nonPublicApi/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/objcCompatible/.openapi-generator/FILES b/samples/client/petstore/swift5/objcCompatible/.openapi-generator/FILES index c81943baf2afa14915ffbb3a1f05ddd21b2ee457..8da82f82679772a323bdc9bcf444c7424a1300f8 100644 --- a/samples/client/petstore/swift5/objcCompatible/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/objcCompatible/.openapi-generator/FILES @@ -12,6 +12,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index 3211e37fe6d6cbb7e0dc2e1c7bebbe87038ccffc..355b4d15349fe7cf6d3e35165e38c356053dc7f0 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -333,7 +333,7 @@ import AnyCodable - parameter completion: completion handler to receive the data and the error objects */ @discardableResult - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { return testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute(apiResponseQueue) { result in switch result { case .success: @@ -367,7 +367,7 @@ import AnyCodable - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 0b17438a7c874ff681653a0aa6f08922a3fc2ef2..5fceb90be830934a27b826e6b1e95ed74cdc05a8 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift index d4ba9d436bbcd0daf0da9a8efc79d2da31f785bb..5e7986ad03378678894768dd6a87b6a261d21795 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift @@ -46,12 +46,12 @@ import AnyCodable public var string: String? public var byte: Data public var binary: URL? - public var date: Date + public var date: DateWithoutTime public var dateTime: Date? public var uuid: UUID? public var password: String - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/objcCompatible/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/objcCompatible/docs/FakeAPI.md b/samples/client/petstore/swift5/objcCompatible/docs/FakeAPI.md index a75c5864f1c6545f972c3dbda1caf1c6ee6497b9..d000bd41bbf005cd62239de62e258f6c6a813fce 100644 --- a/samples/client/petstore/swift5/objcCompatible/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/objcCompatible/docs/FakeAPI.md @@ -364,7 +364,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -386,7 +386,7 @@ let int64 = 987 // Int64 | None (optional) let float = 987 // Float | None (optional) let string = "string_example" // String | None (optional) let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -418,7 +418,7 @@ Name | Type | Description | Notes **float** | **Float** | None | [optional] **string** | **String** | None | [optional] **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/objcCompatible/docs/FormatTest.md b/samples/client/petstore/swift5/objcCompatible/docs/FormatTest.md index f74d94f6c46a8260abe3a68e30578118f76ae69c..18e421e514f18c1922531a72f18ecfd43d65cac6 100644 --- a/samples/client/petstore/swift5/objcCompatible/docs/FormatTest.md +++ b/samples/client/petstore/swift5/objcCompatible/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/oneOf/.openapi-generator/FILES b/samples/client/petstore/swift5/oneOf/.openapi-generator/FILES index 421958ec1d26e38547155fa454f8a332d50c00e5..6b092567723b6c0d242f755cd11745c42b85e119 100644 --- a/samples/client/petstore/swift5/oneOf/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/oneOf/.openapi-generator/FILES @@ -7,6 +7,7 @@ PetstoreClient/Classes/OpenAPIs/APIs.swift PetstoreClient/Classes/OpenAPIs/APIs/DefaultAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 0b17438a7c874ff681653a0aa6f08922a3fc2ef2..5fceb90be830934a27b826e6b1e95ed74cdc05a8 100644 --- a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/oneOf/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/promisekitLibrary/.openapi-generator/FILES b/samples/client/petstore/swift5/promisekitLibrary/.openapi-generator/FILES index c81943baf2afa14915ffbb3a1f05ddd21b2ee457..8da82f82679772a323bdc9bcf444c7424a1300f8 100644 --- a/samples/client/petstore/swift5/promisekitLibrary/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/promisekitLibrary/.openapi-generator/FILES @@ -12,6 +12,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index 76a588d0ac456d41946cb50b66437167c4e54836..b0f9e1df0f0ac118ac0f6ef0a812feb0e65c0041 100644 --- a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -332,7 +332,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: Promise<Void> */ - open class func testEndpointParameters( number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> Promise<Void> { + open class func testEndpointParameters( number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> Promise<Void> { let deferred = Promise<Void>.pending() testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute { result in switch result { @@ -368,7 +368,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift index af90bc2ac5dc2643ebb5449e2185fcb6141b433e..c15832a798b453d6d186a51b4c1c828e72a70cfd 100644 --- a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -92,6 +92,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift index 0a329955482409ea55eb044a727588c27e0f98ad..3d0be76a9b5caf0f1d946d7d096ee3bf391c8110 100644 --- a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift @@ -21,12 +21,12 @@ public struct FormatTest: Codable, JSONEncodable, Hashable { public var string: String? public var byte: Data public var binary: URL? - public var date: Date + public var date: DateWithoutTime public var dateTime: Date? public var uuid: UUID? public var password: String - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/promisekitLibrary/docs/FakeAPI.md b/samples/client/petstore/swift5/promisekitLibrary/docs/FakeAPI.md index 5164a64867d8b67e6c8bca718e7901858697b03f..49df0f8018042c8c586bbd6276ea36910b778c81 100644 --- a/samples/client/petstore/swift5/promisekitLibrary/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/promisekitLibrary/docs/FakeAPI.md @@ -343,7 +343,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters( number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> Promise<Void> + open class func testEndpointParameters( number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> Promise<Void> ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -365,7 +365,7 @@ let int64 = 987 // Int64 | None (optional) let float = 987 // Float | None (optional) let string = "string_example" // String | None (optional) let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -394,7 +394,7 @@ Name | Type | Description | Notes **float** | **Float** | None | [optional] **string** | **String** | None | [optional] **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/promisekitLibrary/docs/FormatTest.md b/samples/client/petstore/swift5/promisekitLibrary/docs/FormatTest.md index f74d94f6c46a8260abe3a68e30578118f76ae69c..18e421e514f18c1922531a72f18ecfd43d65cac6 100644 --- a/samples/client/petstore/swift5/promisekitLibrary/docs/FormatTest.md +++ b/samples/client/petstore/swift5/promisekitLibrary/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/readonlyProperties/.openapi-generator/FILES b/samples/client/petstore/swift5/readonlyProperties/.openapi-generator/FILES index c81943baf2afa14915ffbb3a1f05ddd21b2ee457..8da82f82679772a323bdc9bcf444c7424a1300f8 100644 --- a/samples/client/petstore/swift5/readonlyProperties/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/readonlyProperties/.openapi-generator/FILES @@ -12,6 +12,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index d980142c6ab2517d69c9df99ea69fd8d32a5e95c..0c2a9f639d6af624b5a8173279238527b33292cc 100644 --- a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -333,7 +333,7 @@ open class FakeAPI { - parameter completion: completion handler to receive the data and the error objects */ @discardableResult - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { return testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute(apiResponseQueue) { result in switch result { case .success: @@ -367,7 +367,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 0b17438a7c874ff681653a0aa6f08922a3fc2ef2..5fceb90be830934a27b826e6b1e95ed74cdc05a8 100644 --- a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift index 3bc18bc297901a71d035970be362c574d0e0c90d..9c867d27c30daeb9cc55f893beb960c3f772d4bb 100644 --- a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift @@ -21,12 +21,12 @@ public struct FormatTest: Codable, JSONEncodable, Hashable { public private(set) var string: String? public private(set) var byte: Data public private(set) var binary: URL? - public private(set) var date: Date + public private(set) var date: DateWithoutTime public private(set) var dateTime: Date? public private(set) var uuid: UUID? public private(set) var password: String - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/readonlyProperties/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/readonlyProperties/docs/FakeAPI.md b/samples/client/petstore/swift5/readonlyProperties/docs/FakeAPI.md index 69b1faa2b9918b39c1f0b873bc6670cd49ace31a..ce9c02f74b50d2a5e7336ac316092b1f4f96c339 100644 --- a/samples/client/petstore/swift5/readonlyProperties/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/readonlyProperties/docs/FakeAPI.md @@ -364,7 +364,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -386,7 +386,7 @@ let int64 = 987 // Int64 | None (optional) let float = 987 // Float | None (optional) let string = "string_example" // String | None (optional) let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -418,7 +418,7 @@ Name | Type | Description | Notes **float** | **Float** | None | [optional] **string** | **String** | None | [optional] **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/readonlyProperties/docs/FormatTest.md b/samples/client/petstore/swift5/readonlyProperties/docs/FormatTest.md index f74d94f6c46a8260abe3a68e30578118f76ae69c..18e421e514f18c1922531a72f18ecfd43d65cac6 100644 --- a/samples/client/petstore/swift5/readonlyProperties/docs/FormatTest.md +++ b/samples/client/petstore/swift5/readonlyProperties/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/resultLibrary/.openapi-generator/FILES b/samples/client/petstore/swift5/resultLibrary/.openapi-generator/FILES index c81943baf2afa14915ffbb3a1f05ddd21b2ee457..8da82f82679772a323bdc9bcf444c7424a1300f8 100644 --- a/samples/client/petstore/swift5/resultLibrary/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/resultLibrary/.openapi-generator/FILES @@ -12,6 +12,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index e34744063884303bc916024cc2e7dae4cd6a4bc3..87c0ecf551d450b26dae8c62c32f045ff6058b55 100644 --- a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -333,7 +333,7 @@ open class FakeAPI { - parameter completion: completion handler to receive the result */ @discardableResult - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ result: Swift.Result<Void, ErrorResponse>) -> Void)) -> RequestTask { + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ result: Swift.Result<Void, ErrorResponse>) -> Void)) -> RequestTask { return testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute(apiResponseQueue) { result in switch result { case .success: @@ -367,7 +367,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 0b17438a7c874ff681653a0aa6f08922a3fc2ef2..5fceb90be830934a27b826e6b1e95ed74cdc05a8 100644 --- a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift index 0a329955482409ea55eb044a727588c27e0f98ad..3d0be76a9b5caf0f1d946d7d096ee3bf391c8110 100644 --- a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift @@ -21,12 +21,12 @@ public struct FormatTest: Codable, JSONEncodable, Hashable { public var string: String? public var byte: Data public var binary: URL? - public var date: Date + public var date: DateWithoutTime public var dateTime: Date? public var uuid: UUID? public var password: String - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/resultLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/resultLibrary/docs/FakeAPI.md b/samples/client/petstore/swift5/resultLibrary/docs/FakeAPI.md index 69b1faa2b9918b39c1f0b873bc6670cd49ace31a..ce9c02f74b50d2a5e7336ac316092b1f4f96c339 100644 --- a/samples/client/petstore/swift5/resultLibrary/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/resultLibrary/docs/FakeAPI.md @@ -364,7 +364,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -386,7 +386,7 @@ let int64 = 987 // Int64 | None (optional) let float = 987 // Float | None (optional) let string = "string_example" // String | None (optional) let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -418,7 +418,7 @@ Name | Type | Description | Notes **float** | **Float** | None | [optional] **string** | **String** | None | [optional] **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/resultLibrary/docs/FormatTest.md b/samples/client/petstore/swift5/resultLibrary/docs/FormatTest.md index f74d94f6c46a8260abe3a68e30578118f76ae69c..18e421e514f18c1922531a72f18ecfd43d65cac6 100644 --- a/samples/client/petstore/swift5/resultLibrary/docs/FormatTest.md +++ b/samples/client/petstore/swift5/resultLibrary/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/rxswiftLibrary/.openapi-generator/FILES b/samples/client/petstore/swift5/rxswiftLibrary/.openapi-generator/FILES index c81943baf2afa14915ffbb3a1f05ddd21b2ee457..8da82f82679772a323bdc9bcf444c7424a1300f8 100644 --- a/samples/client/petstore/swift5/rxswiftLibrary/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/rxswiftLibrary/.openapi-generator/FILES @@ -12,6 +12,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index e27e0b6c2db34295bb62fee654358eb809c1e39a..50fdfb147afa6e8be1ba346a0a17ff93674e72f2 100644 --- a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -375,7 +375,7 @@ open class FakeAPI { - parameter apiResponseQueue: The queue on which api response is dispatched. - returns: Observable<Void> */ - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) -> Observable<Void> { + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) -> Observable<Void> { return Observable.create { observer -> Disposable in let requestTask = testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute(apiResponseQueue) { result in switch result { @@ -416,7 +416,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift index f7d0efdcb74e980b819beea0f951d83b6f9cdd3a..604df4795f4772c818c37efa2a8af36aa98bc746 100644 --- a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift index 0a329955482409ea55eb044a727588c27e0f98ad..3d0be76a9b5caf0f1d946d7d096ee3bf391c8110 100644 --- a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift @@ -21,12 +21,12 @@ public struct FormatTest: Codable, JSONEncodable, Hashable { public var string: String? public var byte: Data public var binary: URL? - public var date: Date + public var date: DateWithoutTime public var dateTime: Date? public var uuid: UUID? public var password: String - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/rxswiftLibrary/docs/FakeAPI.md b/samples/client/petstore/swift5/rxswiftLibrary/docs/FakeAPI.md index 350928e8e7f7ad9bc361f4fa282bc1502b3bfb55..f9dfefcec13b6d8609cb1537b6a646f4498e627b 100644 --- a/samples/client/petstore/swift5/rxswiftLibrary/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/rxswiftLibrary/docs/FakeAPI.md @@ -300,7 +300,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> Observable<Void> + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> Observable<Void> ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -322,7 +322,7 @@ let int64 = 987 // Int64 | None (optional) let float = 987 // Float | None (optional) let string = "string_example" // String | None (optional) let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -344,7 +344,7 @@ Name | Type | Description | Notes **float** | **Float** | None | [optional] **string** | **String** | None | [optional] **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/rxswiftLibrary/docs/FormatTest.md b/samples/client/petstore/swift5/rxswiftLibrary/docs/FormatTest.md index f74d94f6c46a8260abe3a68e30578118f76ae69c..18e421e514f18c1922531a72f18ecfd43d65cac6 100644 --- a/samples/client/petstore/swift5/rxswiftLibrary/docs/FormatTest.md +++ b/samples/client/petstore/swift5/rxswiftLibrary/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/urlsessionLibrary/.openapi-generator/FILES b/samples/client/petstore/swift5/urlsessionLibrary/.openapi-generator/FILES index 27a85ba47e60e2a0297ba43750dd42256b743fdc..a913c356a485db6c7c87c4345fa5caabe7413e59 100644 --- a/samples/client/petstore/swift5/urlsessionLibrary/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/urlsessionLibrary/.openapi-generator/FILES @@ -13,6 +13,7 @@ Sources/PetstoreClient/APIs/StoreAPI.swift Sources/PetstoreClient/APIs/UserAPI.swift Sources/PetstoreClient/CodableHelper.swift Sources/PetstoreClient/Configuration.swift +Sources/PetstoreClient/DateWithoutTime.swift Sources/PetstoreClient/Extensions.swift Sources/PetstoreClient/JSONDataEncoding.swift Sources/PetstoreClient/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/APIs/FakeAPI.swift b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/APIs/FakeAPI.swift index f336d4b552c09b9e9d63a8541471baa66a30457f..74bbd211c4210704482f64cd81b89ddbaee5246f 100644 --- a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/APIs/FakeAPI.swift @@ -336,7 +336,7 @@ open class FakeAPI { - parameter completion: completion handler to receive the data and the error objects */ @discardableResult - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { return testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute(apiResponseQueue) { result in switch result { case .success: @@ -370,7 +370,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/DateWithoutTime.swift b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Extensions.swift b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Extensions.swift index 0b17438a7c874ff681653a0aa6f08922a3fc2ef2..5fceb90be830934a27b826e6b1e95ed74cdc05a8 100644 --- a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Extensions.swift +++ b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Models/FormatTest.swift b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Models/FormatTest.swift index 9b54a4d7342f4d978213fc7a26ef67168165908b..2fc2b05ee3ffcc3f5345f20a2d07fb0d5f55c353 100644 --- a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/Models/FormatTest.swift @@ -26,12 +26,12 @@ public final class FormatTest: Codable, JSONEncodable, Hashable { public var string: String? public var byte: Data public var binary: URL? - public var date: Date + public var date: DateWithoutTime public var dateTime: Date? public var uuid: UUID? public var password: String - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/urlsessionLibrary/Sources/PetstoreClient/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/urlsessionLibrary/docs/FakeAPI.md b/samples/client/petstore/swift5/urlsessionLibrary/docs/FakeAPI.md index 69b1faa2b9918b39c1f0b873bc6670cd49ace31a..ce9c02f74b50d2a5e7336ac316092b1f4f96c339 100644 --- a/samples/client/petstore/swift5/urlsessionLibrary/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/urlsessionLibrary/docs/FakeAPI.md @@ -364,7 +364,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -386,7 +386,7 @@ let int64 = 987 // Int64 | None (optional) let float = 987 // Float | None (optional) let string = "string_example" // String | None (optional) let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -418,7 +418,7 @@ Name | Type | Description | Notes **float** | **Float** | None | [optional] **string** | **String** | None | [optional] **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/urlsessionLibrary/docs/FormatTest.md b/samples/client/petstore/swift5/urlsessionLibrary/docs/FormatTest.md index f74d94f6c46a8260abe3a68e30578118f76ae69c..18e421e514f18c1922531a72f18ecfd43d65cac6 100644 --- a/samples/client/petstore/swift5/urlsessionLibrary/docs/FormatTest.md +++ b/samples/client/petstore/swift5/urlsessionLibrary/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/vaporLibrary/.openapi-generator/FILES b/samples/client/petstore/swift5/vaporLibrary/.openapi-generator/FILES index ec27ad4b38e0a5e92ebdaa96c714608ed7e805da..b3b86d9f49782b9de4c1774e29e40e27e1968bfc 100644 --- a/samples/client/petstore/swift5/vaporLibrary/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/vaporLibrary/.openapi-generator/FILES @@ -9,6 +9,7 @@ Sources/PetstoreClient/APIs/PetAPI.swift Sources/PetstoreClient/APIs/StoreAPI.swift Sources/PetstoreClient/APIs/UserAPI.swift Sources/PetstoreClient/Configuration.swift +Sources/PetstoreClient/DateWithoutTime.swift Sources/PetstoreClient/Extensions.swift Sources/PetstoreClient/Models/AdditionalPropertiesAnyType.swift Sources/PetstoreClient/Models/AdditionalPropertiesArray.swift @@ -60,6 +61,7 @@ Sources/PetstoreClient/Models/TypeHolderDefault.swift Sources/PetstoreClient/Models/TypeHolderExample.swift Sources/PetstoreClient/Models/User.swift Sources/PetstoreClient/Models/XmlItem.swift +Sources/PetstoreClient/OpenISO8601DateFormatter.swift docs/AdditionalPropertiesAnyType.md docs/AdditionalPropertiesArray.md docs/AdditionalPropertiesBoolean.md diff --git a/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/APIs/FakeAPI.swift b/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/APIs/FakeAPI.swift index 014da8378336314ab5c8999100dcb3a73ccbd3b5..94ec5f6acf49b6e743aa02b3b5096f09b14b9506 100644 --- a/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/APIs/FakeAPI.swift @@ -423,7 +423,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: `EventLoopFuture` of `ClientResponse` */ - open class func testEndpointParametersRaw(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, headers: HTTPHeaders = PetstoreClientAPI.customHeaders, beforeSend: (inout ClientRequest) throws -> () = { _ in }) -> EventLoopFuture<ClientResponse> { + open class func testEndpointParametersRaw(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, headers: HTTPHeaders = PetstoreClientAPI.customHeaders, beforeSend: (inout ClientRequest) throws -> () = { _ in }) -> EventLoopFuture<ClientResponse> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath @@ -447,7 +447,7 @@ open class FakeAPI { var patternWithoutDelimiter: String var byte: Data var binary: Data? - var date: Date? + var date: DateWithoutTime? var dateTime: Date? var password: String? var callback: String? @@ -486,7 +486,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: `EventLoopFuture` of `TestEndpointParameters` */ - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, headers: HTTPHeaders = PetstoreClientAPI.customHeaders, beforeSend: (inout ClientRequest) throws -> () = { _ in }) -> EventLoopFuture<TestEndpointParameters> { + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, headers: HTTPHeaders = PetstoreClientAPI.customHeaders, beforeSend: (inout ClientRequest) throws -> () = { _ in }) -> EventLoopFuture<TestEndpointParameters> { return testEndpointParametersRaw(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback, headers: headers, beforeSend: beforeSend).flatMapThrowing { response -> TestEndpointParameters in switch response.status.code { case 400: diff --git a/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/DateWithoutTime.swift b/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/Models/FormatTest.swift b/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/Models/FormatTest.swift index dfdf6ae588cdc249cc5fce4592c305840e9a2830..9b1070047f46762773e327cdb98f2c8e95296d60 100644 --- a/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/Models/FormatTest.swift @@ -22,13 +22,13 @@ public final class FormatTest: Content, Hashable { public var string: String? public var byte: Data public var binary: Data? - public var date: Date + public var date: DateWithoutTime public var dateTime: Date? public var uuid: UUID? public var password: String public var bigDecimal: Decimal? - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: Data? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String, bigDecimal: Decimal? = nil) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: Data? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String, bigDecimal: Decimal? = nil) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/OpenISO8601DateFormatter.swift new file mode 100644 index 0000000000000000000000000000000000000000..cc3288805f1995e08a2cf77a4608731b9adc8e0a --- /dev/null +++ b/samples/client/petstore/swift5/vaporLibrary/Sources/PetstoreClient/OpenISO8601DateFormatter.swift @@ -0,0 +1,56 @@ +// +// OpenISO8601DateFormatter.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +// https://stackoverflow.com/a/50281094/976628 +public class OpenISO8601DateFormatter: DateFormatter { + static let withoutSeconds: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ" + return formatter + }() + + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + + private func setup() { + calendar = Calendar(identifier: .iso8601) + locale = Locale(identifier: "en_US_POSIX") + timeZone = TimeZone(secondsFromGMT: 0) + dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" + } + + override init() { + super.init() + setup() + } + + required init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + setup() + } + + override public func date(from string: String) -> Date? { + if let result = super.date(from: string) { + return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result + } + + return OpenISO8601DateFormatter.withoutTime.date(from: string) + } +} diff --git a/samples/client/petstore/swift5/vaporLibrary/docs/FakeAPI.md b/samples/client/petstore/swift5/vaporLibrary/docs/FakeAPI.md index 2cb0e52af6d447c64375dd890c9b76ca768c21d1..48ea03243b18463a9c19628386bd00428c4ffaca 100644 --- a/samples/client/petstore/swift5/vaporLibrary/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/vaporLibrary/docs/FakeAPI.md @@ -488,7 +488,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, headers: HTTPHeaders = PetstoreClientAPI.customHeaders, beforeSend: (inout ClientRequest) throws -> () = { _ in }) -> EventLoopFuture<TestEndpointParameters> + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: Data? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, headers: HTTPHeaders = PetstoreClientAPI.customHeaders, beforeSend: (inout ClientRequest) throws -> () = { _ in }) -> EventLoopFuture<TestEndpointParameters> ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -510,7 +510,7 @@ let int64 = 987 // Int64 | None (optional) let float = 987 // Float | None (optional) let string = "string_example" // String | None (optional) let binary = Data([9, 8, 7]) // Data | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -545,7 +545,7 @@ Name | Type | Description | Notes **float** | **Float** | None | [optional] **string** | **String** | None | [optional] **binary** | **Data** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/vaporLibrary/docs/FormatTest.md b/samples/client/petstore/swift5/vaporLibrary/docs/FormatTest.md index 6e6c67b2a4ff34fc39f1ccab287d69073673a4f9..c7272486bd9e277f7d60e40ac2fbd74a2c46ea9a 100644 --- a/samples/client/petstore/swift5/vaporLibrary/docs/FormatTest.md +++ b/samples/client/petstore/swift5/vaporLibrary/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **Data** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | | diff --git a/samples/client/petstore/swift5/x-swift-hashable/.openapi-generator/FILES b/samples/client/petstore/swift5/x-swift-hashable/.openapi-generator/FILES index c81943baf2afa14915ffbb3a1f05ddd21b2ee457..8da82f82679772a323bdc9bcf444c7424a1300f8 100644 --- a/samples/client/petstore/swift5/x-swift-hashable/.openapi-generator/FILES +++ b/samples/client/petstore/swift5/x-swift-hashable/.openapi-generator/FILES @@ -12,6 +12,7 @@ PetstoreClient/Classes/OpenAPIs/APIs/StoreAPI.swift PetstoreClient/Classes/OpenAPIs/APIs/UserAPI.swift PetstoreClient/Classes/OpenAPIs/CodableHelper.swift PetstoreClient/Classes/OpenAPIs/Configuration.swift +PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift PetstoreClient/Classes/OpenAPIs/Extensions.swift PetstoreClient/Classes/OpenAPIs/JSONDataEncoding.swift PetstoreClient/Classes/OpenAPIs/JSONEncodingHelper.swift diff --git a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index d980142c6ab2517d69c9df99ea69fd8d32a5e95c..0c2a9f639d6af624b5a8173279238527b33292cc 100644 --- a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -333,7 +333,7 @@ open class FakeAPI { - parameter completion: completion handler to receive the data and the error objects */ @discardableResult - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?, _ error: Error?) -> Void)) -> RequestTask { return testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute(apiResponseQueue) { result in switch result { case .success: @@ -367,7 +367,7 @@ open class FakeAPI { - parameter callback: (form) None (optional) - returns: RequestBuilder<Void> */ - open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { + open class func testEndpointParametersWithRequestBuilder(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil) -> RequestBuilder<Void> { let localVariablePath = "/fake" let localVariableURLString = PetstoreClientAPI.basePath + localVariablePath let localVariableFormParams: [String: Any?] = [ diff --git a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift new file mode 100644 index 0000000000000000000000000000000000000000..3a8e2edf62969f6ffd8c7ceb01414de6a229e1df --- /dev/null +++ b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/DateWithoutTime.swift @@ -0,0 +1,55 @@ +// DateWithoutTime.swift +// +// Generated by openapi-generator +// https://openapi-generator.tech +// + +import Foundation + +/// Represents a date without time information (e.g. a birthday) for transmission from and to a REST API +/// +/// This type is used as a representation for openapi specs `date` format which does not contain +/// time information as opposed to the `date-time` format. Although it internally uses `Date` for +/// (de-)serialization as well the generator needs to be able to distinguish between the two formats. +/// - note: As `Date` is agnostic to timezones (and calendars), timezone information is needed to be able to add +/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601. +/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate +/// can be used safely. +public struct DateWithoutTime: Codable, Hashable, Equatable { + public let wrappedDate: Date + public let timezone: TimeZone + + public enum CodingKeys: CodingKey, CaseIterable { + case wrappedDate + case timezone + } + + public init(from decoder: Decoder) throws { + let container = try decoder.singleValueContainer() + self.wrappedDate = try container.decode(Date.self) + self.timezone = OpenISO8601DateFormatter.withoutTime.timeZone + } + + public init?(wrappedDate: Date?, timezone: TimeZone = .current) { + guard let wrappedDate = wrappedDate else { + return nil + } + + self.init(wrappedDate: wrappedDate, timezone: timezone) + } + + public init(wrappedDate: Date, timezone: TimeZone) { + self.wrappedDate = wrappedDate + self.timezone = timezone + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + try container.encode(OpenISO8601DateFormatter.withoutTime.string(from: normalizedWrappedDate())) + } + + internal func normalizedWrappedDate() -> Date { + return wrappedDate.addingTimeInterval( + Double(timezone.secondsFromGMT(for: wrappedDate))) + } +} \ No newline at end of file diff --git a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Extensions.swift index 0b17438a7c874ff681653a0aa6f08922a3fc2ef2..5fceb90be830934a27b826e6b1e95ed74cdc05a8 100644 --- a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -91,6 +91,12 @@ extension Date: JSONEncodable { } } +extension DateWithoutTime: JSONEncodable { + func encodeToJSON() -> Any { + return OpenISO8601DateFormatter.withoutTime.string(from: self.normalizedWrappedDate()) + } +} + extension JSONEncodable where Self: Encodable { func encodeToJSON() -> Any { guard let data = try? CodableHelper.jsonEncoder.encode(self) else { diff --git a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift index c2883d93dce61cdad1e34495fb882cd29bd35b04..bb3f54af6522b72a4fbd880f98cbdc37a7640b0e 100644 --- a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift +++ b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/Models/FormatTest.swift @@ -21,12 +21,12 @@ public struct FormatTest: Codable, JSONEncodable { public var string: String? public var byte: Data public var binary: URL? - public var date: Date + public var date: DateWithoutTime public var dateTime: Date? public var uuid: UUID? public var password: String - public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: Date, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { + public init(integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, number: Double, float: Float? = nil, double: Double? = nil, string: String? = nil, byte: Data, binary: URL? = nil, date: DateWithoutTime, dateTime: Date? = nil, uuid: UUID? = nil, password: String) { self.integer = integer self.int32 = int32 self.int64 = int64 diff --git a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift index e06208074cd984bd3b8309e66aef4a91f3c545c1..cc3288805f1995e08a2cf77a4608731b9adc8e0a 100644 --- a/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift +++ b/samples/client/petstore/swift5/x-swift-hashable/PetstoreClient/Classes/OpenAPIs/OpenISO8601DateFormatter.swift @@ -18,6 +18,15 @@ public class OpenISO8601DateFormatter: DateFormatter { return formatter }() + static let withoutTime: DateFormatter = { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = "yyyy-MM-dd" + return formatter + }() + private func setup() { calendar = Calendar(identifier: .iso8601) locale = Locale(identifier: "en_US_POSIX") @@ -38,7 +47,10 @@ public class OpenISO8601DateFormatter: DateFormatter { override public func date(from string: String) -> Date? { if let result = super.date(from: string) { return result + } else if let result = OpenISO8601DateFormatter.withoutSeconds.date(from: string) { + return result } - return OpenISO8601DateFormatter.withoutSeconds.date(from: string) + + return OpenISO8601DateFormatter.withoutTime.date(from: string) } } diff --git a/samples/client/petstore/swift5/x-swift-hashable/docs/FakeAPI.md b/samples/client/petstore/swift5/x-swift-hashable/docs/FakeAPI.md index 69b1faa2b9918b39c1f0b873bc6670cd49ace31a..ce9c02f74b50d2a5e7336ac316092b1f4f96c339 100644 --- a/samples/client/petstore/swift5/x-swift-hashable/docs/FakeAPI.md +++ b/samples/client/petstore/swift5/x-swift-hashable/docs/FakeAPI.md @@ -364,7 +364,7 @@ No authorization required # **testEndpointParameters** ```swift - open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) + open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: DateWithoutTime? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, completion: @escaping (_ data: Void?, _ error: Error?) -> Void) ``` Fake endpoint for testing various parameters å‡ç«¯é»ž å½ã®ã‚¨ãƒ³ãƒ‰ãƒã‚¤ãƒ³ãƒˆ 가짜 엔드 í¬ì¸íЏ @@ -386,7 +386,7 @@ let int64 = 987 // Int64 | None (optional) let float = 987 // Float | None (optional) let string = "string_example" // String | None (optional) let binary = URL(string: "https://example.com")! // URL | None (optional) -let date = Date() // Date | None (optional) +let date = 987 // DateWithoutTime | None (optional) let dateTime = Date() // Date | None (optional) let password = "password_example" // String | None (optional) let callback = "callback_example" // String | None (optional) @@ -418,7 +418,7 @@ Name | Type | Description | Notes **float** | **Float** | None | [optional] **string** | **String** | None | [optional] **binary** | **URL** | None | [optional] - **date** | **Date** | None | [optional] + **date** | **DateWithoutTime** | None | [optional] **dateTime** | **Date** | None | [optional] **password** | **String** | None | [optional] **callback** | **String** | None | [optional] diff --git a/samples/client/petstore/swift5/x-swift-hashable/docs/FormatTest.md b/samples/client/petstore/swift5/x-swift-hashable/docs/FormatTest.md index f74d94f6c46a8260abe3a68e30578118f76ae69c..18e421e514f18c1922531a72f18ecfd43d65cac6 100644 --- a/samples/client/petstore/swift5/x-swift-hashable/docs/FormatTest.md +++ b/samples/client/petstore/swift5/x-swift-hashable/docs/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **String** | | [optional] **byte** | **Data** | | **binary** | **URL** | | [optional] -**date** | **Date** | | +**date** | **DateWithoutTime** | | **dateTime** | **Date** | | [optional] **uuid** | **UUID** | | [optional] **password** | **String** | |