diff --git a/modules/openapi-generator/src/main/resources/swift4/CodableHelper.mustache b/modules/openapi-generator/src/main/resources/swift4/CodableHelper.mustache index e9d28accdf4c..584de8c3d57a 100644 --- a/modules/openapi-generator/src/main/resources/swift4/CodableHelper.mustache +++ b/modules/openapi-generator/src/main/resources/swift4/CodableHelper.mustache @@ -26,7 +26,7 @@ open class CodableHelper { 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:ss.SSSXXXXX" + formatter.dateFormat = Configuration.dateFormat decoder.dateDecodingStrategy = .formatted(formatter) } @@ -55,7 +55,7 @@ open class CodableHelper { 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:ss.SSSXXXXX" + formatter.dateFormat = Configuration.dateFormat encoder.dateEncodingStrategy = .formatted(formatter) } diff --git a/modules/openapi-generator/src/main/resources/swift4/Extensions.mustache b/modules/openapi-generator/src/main/resources/swift4/Extensions.mustache index 7f5e1c1f7396..61d55e8afec7 100644 --- a/modules/openapi-generator/src/main/resources/swift4/Extensions.mustache +++ b/modules/openapi-generator/src/main/resources/swift4/Extensions.mustache @@ -67,10 +67,16 @@ extension Data: JSONEncodable { } private let dateFormatter: DateFormatter = { - let fmt = DateFormatter() - fmt.dateFormat = Configuration.dateFormat - fmt.locale = Locale(identifier: "en_US_POSIX") - return fmt + if let formatter = CodableHelper.dateformatter { + return formatter + } else { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = Configuration.dateFormat + return formatter + } }() extension Date: JSONEncodable { diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index 02b129d41efc..a209a492192a 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -455,13 +455,16 @@ open class FakeAPI { /** Fake endpoint to test group parameters (optional) + - parameter requiredStringGroup: (query) Required String in group parameters + - parameter requiredBooleanGroup: (header) Required Boolean in group parameters + - parameter requiredInt64Group: (query) Required Integer in group parameters - parameter stringGroup: (query) String in group parameters (optional) - parameter booleanGroup: (header) Boolean in group parameters (optional) - parameter int64Group: (query) Integer in group parameters (optional) - parameter completion: completion handler to receive the data and the error objects */ - open class func testGroupParameters(stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) { - testGroupParametersWithRequestBuilder(stringGroup: stringGroup, booleanGroup: booleanGroup, int64Group: int64Group).execute { (response, error) -> Void in + open class func testGroupParameters(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) { + testGroupParametersWithRequestBuilder(requiredStringGroup: requiredStringGroup, requiredBooleanGroup: requiredBooleanGroup, requiredInt64Group: requiredInt64Group, stringGroup: stringGroup, booleanGroup: booleanGroup, int64Group: int64Group).execute { (response, error) -> Void in if error == nil { completion((), error) } else { @@ -475,22 +478,28 @@ open class FakeAPI { Fake endpoint to test group parameters (optional) - DELETE /fake - Fake endpoint to test group parameters (optional) + - parameter requiredStringGroup: (query) Required String in group parameters + - parameter requiredBooleanGroup: (header) Required Boolean in group parameters + - parameter requiredInt64Group: (query) Required Integer in group parameters - parameter stringGroup: (query) String in group parameters (optional) - parameter booleanGroup: (header) Boolean in group parameters (optional) - parameter int64Group: (query) Integer in group parameters (optional) - returns: RequestBuilder */ - open class func testGroupParametersWithRequestBuilder(stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil) -> RequestBuilder { + open class func testGroupParametersWithRequestBuilder(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil) -> RequestBuilder { let path = "/fake" let URLString = PetstoreClientAPI.basePath + path let parameters: [String:Any]? = nil var url = URLComponents(string: URLString) url?.queryItems = APIHelper.mapValuesToQueryItems([ + "required_string_group": requiredStringGroup.encodeToJSON(), + "required_int64_group": requiredInt64Group.encodeToJSON(), "string_group": stringGroup?.encodeToJSON(), "int64_group": int64Group?.encodeToJSON() ]) let nillableHeaders: [String: Any?] = [ + "required_boolean_group": requiredBooleanGroup, "boolean_group": booleanGroup ] let headerParameters = APIHelper.rejectNilHeaders(nillableHeaders) diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift index e9d28accdf4c..584de8c3d57a 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift @@ -26,7 +26,7 @@ open class CodableHelper { 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:ss.SSSXXXXX" + formatter.dateFormat = Configuration.dateFormat decoder.dateDecodingStrategy = .formatted(formatter) } @@ -55,7 +55,7 @@ open class CodableHelper { 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:ss.SSSXXXXX" + formatter.dateFormat = Configuration.dateFormat encoder.dateEncodingStrategy = .formatted(formatter) } diff --git a/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Extensions.swift index abe218b4e7ac..8bf1829ba806 100644 --- a/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift4/default/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -66,10 +66,16 @@ extension Data: JSONEncodable { } private let dateFormatter: DateFormatter = { - let fmt = DateFormatter() - fmt.dateFormat = Configuration.dateFormat - fmt.locale = Locale(identifier: "en_US_POSIX") - return fmt + if let formatter = CodableHelper.dateformatter { + return formatter + } else { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = Configuration.dateFormat + return formatter + } }() extension Date: JSONEncodable { diff --git a/samples/client/petstore/swift4/default/SwaggerClientTests/SwaggerClient.xcodeproj/project.pbxproj b/samples/client/petstore/swift4/default/SwaggerClientTests/SwaggerClient.xcodeproj/project.pbxproj index 583e008421fa..2c13537f84cc 100644 --- a/samples/client/petstore/swift4/default/SwaggerClientTests/SwaggerClient.xcodeproj/project.pbxproj +++ b/samples/client/petstore/swift4/default/SwaggerClientTests/SwaggerClient.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 1A501F48219C3DC600F372F6 /* DateFormatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A501F47219C3DC600F372F6 /* DateFormatTests.swift */; }; 54DA06C1D70D78EC0EC72B61 /* Pods_SwaggerClientTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F65B6638217EDDC99D103B16 /* Pods_SwaggerClientTests.framework */; }; 6D4EFB951C692C6300B96B06 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4EFB941C692C6300B96B06 /* AppDelegate.swift */; }; 6D4EFB971C692C6300B96B06 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6D4EFB961C692C6300B96B06 /* ViewController.swift */; }; @@ -30,6 +31,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 1A501F47219C3DC600F372F6 /* DateFormatTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateFormatTests.swift; sourceTree = ""; }; 289E8A9E9C0BB66AD190C7C6 /* Pods-SwaggerClientTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SwaggerClientTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SwaggerClientTests/Pods-SwaggerClientTests.debug.xcconfig"; sourceTree = ""; }; 6D4EFB911C692C6300B96B06 /* SwaggerClient.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SwaggerClient.app; sourceTree = BUILT_PRODUCTS_DIR; }; 6D4EFB941C692C6300B96B06 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -132,6 +134,7 @@ 6D4EFBB41C693BE200B96B06 /* PetAPITests.swift */, 6D4EFBB61C693BED00B96B06 /* StoreAPITests.swift */, 6D4EFBB81C693BFC00B96B06 /* UserAPITests.swift */, + 1A501F47219C3DC600F372F6 /* DateFormatTests.swift */, ); path = SwaggerClientTests; sourceTree = ""; @@ -360,6 +363,7 @@ files = ( 6D4EFBB71C693BED00B96B06 /* StoreAPITests.swift in Sources */, 6D4EFBB91C693BFC00B96B06 /* UserAPITests.swift in Sources */, + 1A501F48219C3DC600F372F6 /* DateFormatTests.swift in Sources */, 6D4EFBB51C693BE200B96B06 /* PetAPITests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/samples/client/petstore/swift4/default/SwaggerClientTests/SwaggerClientTests/DateFormatTests.swift b/samples/client/petstore/swift4/default/SwaggerClientTests/SwaggerClientTests/DateFormatTests.swift new file mode 100644 index 000000000000..978417c35867 --- /dev/null +++ b/samples/client/petstore/swift4/default/SwaggerClientTests/SwaggerClientTests/DateFormatTests.swift @@ -0,0 +1,113 @@ +// +// DateFormatTests.swift +// SwaggerClientTests +// +// Created by James on 14/11/2018. +// Copyright © 2018 Swagger. All rights reserved. +// + +import Foundation +import XCTest +@testable import PetstoreClient +@testable import SwaggerClient + +class DateFormatTests: XCTestCase { + + struct DateTest: Codable { + let date: Date + } + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testEncodeToJSONAlwaysResultsInUTCEncodedDate() { + var dateComponents = DateComponents() + dateComponents.calendar = Calendar(identifier: .gregorian) + dateComponents.year = 2018 + dateComponents.month = 11 + dateComponents.day = 14 + dateComponents.hour = 11 + dateComponents.minute = 35 + dateComponents.second = 43 + dateComponents.nanosecond = 500 + + // Testing a date with a timezone of +00:00 (UTC) + dateComponents.timeZone = TimeZone(secondsFromGMT: 0) + XCTAssert(dateComponents.isValidDate) + + guard let utcDate = dateComponents.date else { + XCTFail("Couldn't get a valid date") + return + } + + var encodedDate = utcDate.encodeToJSON() as! String + XCTAssert(encodedDate.hasSuffix("Z")) + + // test with a positive timzone offset from UTC + dateComponents.timeZone = TimeZone(secondsFromGMT: 60 * 60) // +01:00 + XCTAssert(dateComponents.isValidDate) + + guard let nonUTCDate1 = dateComponents.date else { + XCTFail("Couldn't get a valid date") + return + } + + encodedDate = nonUTCDate1.encodeToJSON() as! String + XCTAssert(encodedDate.hasSuffix("Z")) + + // test with a negative timzone offset from UTC + dateComponents.timeZone = TimeZone(secondsFromGMT: -(60 * 60)) // -01:00 + XCTAssert(dateComponents.isValidDate) + + guard let nonUTCDate2 = dateComponents.date else { + XCTFail("Couldn't get a valid date") + return + } + + encodedDate = nonUTCDate2.encodeToJSON() as! String + XCTAssert(encodedDate.hasSuffix("Z")) + } + + func testCodableAlwaysResultsInUTCEncodedDate() { + let jsonData = "{\"date\":\"1970-01-01T00:00:00.000Z\"}".data(using: .utf8)! + let decodeResult = CodableHelper.decode(DateTest.self, from: jsonData) + XCTAssert(decodeResult.decodableObj != nil && decodeResult.error == nil) + + var dateComponents = DateComponents() + dateComponents.calendar = Calendar(identifier: .gregorian) + dateComponents.year = 1970 + dateComponents.month = 01 + dateComponents.day = 01 + dateComponents.hour = 00 + dateComponents.minute = 00 + dateComponents.second = 00 + + // Testing a date with a timezone of +00:00 (UTC) + dateComponents.timeZone = TimeZone(secondsFromGMT: 0) + XCTAssert(dateComponents.isValidDate) + + guard let date = dateComponents.date else { + XCTFail("Couldn't get a valid date") + return + } + + let dateTest = DateTest(date: date) + let encodeResult = CodableHelper.encode(dateTest) + XCTAssert(encodeResult.data != nil && encodeResult.error == nil) + guard let jsonString = String(data: encodeResult.data!, encoding: .utf8) else { + XCTFail("Unable to convert encoded data to string.") + return + } + + let exampleJSONString = "{\"date\":\"1970-01-01T00:00:00.000Z\"}" + XCTAssert(jsonString == exampleJSONString, "Encoded JSON String: \(jsonString) should match: \(exampleJSONString)") + } + +} diff --git a/samples/client/petstore/swift4/objcCompatible/.openapi-generator/VERSION b/samples/client/petstore/swift4/objcCompatible/.openapi-generator/VERSION index 6d94c9c2e12a..e24c1f857e01 100644 --- a/samples/client/petstore/swift4/objcCompatible/.openapi-generator/VERSION +++ b/samples/client/petstore/swift4/objcCompatible/.openapi-generator/VERSION @@ -1 +1 @@ -3.3.0-SNAPSHOT \ No newline at end of file +3.3.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs.swift index 8cae3aacfe5a..2890bffa2747 100644 --- a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs.swift +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs.swift @@ -7,10 +7,10 @@ import Foundation open class PetstoreClientAPI { - open static var basePath = "http://petstore.swagger.io:80/v2" - open static var credential: URLCredential? - open static var customHeaders: [String:String] = [:] - open static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory() + public static var basePath = "http://petstore.swagger.io:80/v2" + public static var credential: URLCredential? + public static var customHeaders: [String:String] = [:] + public static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory() } open class RequestBuilder { diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index 7dc52cc3b00f..a209a492192a 100644 --- a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -452,6 +452,63 @@ open class FakeAPI { return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false, headers: headerParameters) } + /** + Fake endpoint to test group parameters (optional) + + - parameter requiredStringGroup: (query) Required String in group parameters + - parameter requiredBooleanGroup: (header) Required Boolean in group parameters + - parameter requiredInt64Group: (query) Required Integer in group parameters + - parameter stringGroup: (query) String in group parameters (optional) + - parameter booleanGroup: (header) Boolean in group parameters (optional) + - parameter int64Group: (query) Integer in group parameters (optional) + - parameter completion: completion handler to receive the data and the error objects + */ + open class func testGroupParameters(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) { + testGroupParametersWithRequestBuilder(requiredStringGroup: requiredStringGroup, requiredBooleanGroup: requiredBooleanGroup, requiredInt64Group: requiredInt64Group, stringGroup: stringGroup, booleanGroup: booleanGroup, int64Group: int64Group).execute { (response, error) -> Void in + if error == nil { + completion((), error) + } else { + completion(nil, error) + } + } + } + + + /** + Fake endpoint to test group parameters (optional) + - DELETE /fake + - Fake endpoint to test group parameters (optional) + - parameter requiredStringGroup: (query) Required String in group parameters + - parameter requiredBooleanGroup: (header) Required Boolean in group parameters + - parameter requiredInt64Group: (query) Required Integer in group parameters + - parameter stringGroup: (query) String in group parameters (optional) + - parameter booleanGroup: (header) Boolean in group parameters (optional) + - parameter int64Group: (query) Integer in group parameters (optional) + - returns: RequestBuilder + */ + open class func testGroupParametersWithRequestBuilder(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil) -> RequestBuilder { + let path = "/fake" + let URLString = PetstoreClientAPI.basePath + path + let parameters: [String:Any]? = nil + + var url = URLComponents(string: URLString) + url?.queryItems = APIHelper.mapValuesToQueryItems([ + "required_string_group": requiredStringGroup.encodeToJSON(), + "required_int64_group": requiredInt64Group.encodeToJSON(), + "string_group": stringGroup?.encodeToJSON(), + "int64_group": int64Group?.encodeToJSON() + ]) + let nillableHeaders: [String: Any?] = [ + "required_boolean_group": requiredBooleanGroup, + "boolean_group": booleanGroup + ] + let headerParameters = APIHelper.rejectNilHeaders(nillableHeaders) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + return requestBuilder.init(method: "DELETE", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false, headers: headerParameters) + } + /** test inline additionalProperties diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift index 2ade78f5a616..ac14f72c7d0e 100644 --- a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift @@ -154,7 +154,7 @@ open class AlamofireRequestBuilder: RequestBuilder { if stringResponse.result.isFailure { completion( nil, - ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!) + ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error!) ) return } @@ -356,7 +356,7 @@ open class AlamofireDecodableRequestBuilder: AlamofireRequestBuilde if stringResponse.result.isFailure { completion( nil, - ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!) + ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error!) ) return } diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift index bd72d81846d2..584de8c3d57a 100644 --- a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift @@ -11,7 +11,7 @@ public typealias EncodeResult = (data: Data?, error: Error?) open class CodableHelper { - open static var dateformatter: DateFormatter? + public static var dateformatter: DateFormatter? open class func decode(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T : Decodable { var returnedDecodable: T? = nil @@ -26,7 +26,7 @@ open class CodableHelper { 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:ss.SSSXXXXX" + formatter.dateFormat = Configuration.dateFormat decoder.dateDecodingStrategy = .formatted(formatter) } @@ -55,7 +55,7 @@ open class CodableHelper { 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:ss.SSSXXXXX" + formatter.dateFormat = Configuration.dateFormat encoder.dateEncodingStrategy = .formatted(formatter) } diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Configuration.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Configuration.swift index f8180752b67b..516590da5d9e 100644 --- a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Configuration.swift +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Configuration.swift @@ -10,6 +10,6 @@ open class Configuration { // This value is used to configure the date formatter that is used to serialize dates into JSON format. // You must set it prior to encoding any dates, and it will only be read once. - open static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" + public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" } \ No newline at end of file diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Extensions.swift index abe218b4e7ac..8bf1829ba806 100644 --- a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -66,10 +66,16 @@ extension Data: JSONEncodable { } private let dateFormatter: DateFormatter = { - let fmt = DateFormatter() - fmt.dateFormat = Configuration.dateFormat - fmt.locale = Locale(identifier: "en_US_POSIX") - return fmt + if let formatter = CodableHelper.dateformatter { + return formatter + } else { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = Configuration.dateFormat + return formatter + } }() extension Date: JSONEncodable { diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models.swift index 42f8186ae4af..408563890359 100644 --- a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -15,9 +15,9 @@ public enum ErrorResponse : Error { } open class Response { - open let statusCode: Int - open let header: [String: String] - open let body: T? + public let statusCode: Int + public let header: [String: String] + public let body: T? public init(statusCode: Int, header: [String: String], body: T?) { self.statusCode = statusCode diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Category.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Category.swift index c27be481ecf6..10f625e35b09 100644 --- a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Category.swift +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/Category.swift @@ -17,9 +17,9 @@ public struct Category: Codable { return _id.map({ return NSNumber(value: $0) }) } } - public var name: String? + public var name: String = "default-name" - public init(_id: Int64?, name: String?) { + public init(_id: Int64?, name: String) { self._id = _id self.name = name } diff --git a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift index 2d3a45d35a0c..392c1e443839 100644 --- a/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift +++ b/samples/client/petstore/swift4/objcCompatible/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift @@ -18,9 +18,9 @@ public struct MapTest: Codable { public var mapMapOfString: [String:[String:String]]? public var mapOfEnumString: [String:String]? public var directMap: [String:Bool]? - public var indirectMap: StringBooleanMap? + public var indirectMap: [String:Bool]? - public init(mapMapOfString: [String:[String:String]]?, mapOfEnumString: [String:String]?, directMap: [String:Bool]?, indirectMap: StringBooleanMap?) { + public init(mapMapOfString: [String:[String:String]]?, mapOfEnumString: [String:String]?, directMap: [String:Bool]?, indirectMap: [String:Bool]?) { self.mapMapOfString = mapMapOfString self.mapOfEnumString = mapOfEnumString self.directMap = directMap diff --git a/samples/client/petstore/swift4/promisekit/.openapi-generator/VERSION b/samples/client/petstore/swift4/promisekit/.openapi-generator/VERSION index 6d94c9c2e12a..e24c1f857e01 100644 --- a/samples/client/petstore/swift4/promisekit/.openapi-generator/VERSION +++ b/samples/client/petstore/swift4/promisekit/.openapi-generator/VERSION @@ -1 +1 @@ -3.3.0-SNAPSHOT \ No newline at end of file +3.3.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs.swift index 8cae3aacfe5a..2890bffa2747 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs.swift @@ -7,10 +7,10 @@ import Foundation open class PetstoreClientAPI { - open static var basePath = "http://petstore.swagger.io:80/v2" - open static var credential: URLCredential? - open static var customHeaders: [String:String] = [:] - open static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory() + public static var basePath = "http://petstore.swagger.io:80/v2" + public static var credential: URLCredential? + public static var customHeaders: [String:String] = [:] + public static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory() } open class RequestBuilder { diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index ea2799c3411f..2256dc531cb1 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -621,6 +621,85 @@ open class FakeAPI { return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false, headers: headerParameters) } + /** + Fake endpoint to test group parameters (optional) + + - parameter requiredStringGroup: (query) Required String in group parameters + - parameter requiredBooleanGroup: (header) Required Boolean in group parameters + - parameter requiredInt64Group: (query) Required Integer in group parameters + - parameter stringGroup: (query) String in group parameters (optional) + - parameter booleanGroup: (header) Boolean in group parameters (optional) + - parameter int64Group: (query) Integer in group parameters (optional) + - parameter completion: completion handler to receive the data and the error objects + */ + open class func testGroupParameters(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) { + testGroupParametersWithRequestBuilder(requiredStringGroup: requiredStringGroup, requiredBooleanGroup: requiredBooleanGroup, requiredInt64Group: requiredInt64Group, stringGroup: stringGroup, booleanGroup: booleanGroup, int64Group: int64Group).execute { (response, error) -> Void in + if error == nil { + completion((), error) + } else { + completion(nil, error) + } + } + } + + /** + Fake endpoint to test group parameters (optional) + + - parameter requiredStringGroup: (query) Required String in group parameters + - parameter requiredBooleanGroup: (header) Required Boolean in group parameters + - parameter requiredInt64Group: (query) Required Integer in group parameters + - parameter stringGroup: (query) String in group parameters (optional) + - parameter booleanGroup: (header) Boolean in group parameters (optional) + - parameter int64Group: (query) Integer in group parameters (optional) + - returns: Promise + */ + open class func testGroupParameters( requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil) -> Promise { + let deferred = Promise.pending() + testGroupParameters(requiredStringGroup: requiredStringGroup, requiredBooleanGroup: requiredBooleanGroup, requiredInt64Group: requiredInt64Group, stringGroup: stringGroup, booleanGroup: booleanGroup, int64Group: int64Group) { data, error in + if let error = error { + deferred.reject(error) + } else { + deferred.fulfill(data!) + } + } + return deferred.promise + } + + /** + Fake endpoint to test group parameters (optional) + - DELETE /fake + - Fake endpoint to test group parameters (optional) + - parameter requiredStringGroup: (query) Required String in group parameters + - parameter requiredBooleanGroup: (header) Required Boolean in group parameters + - parameter requiredInt64Group: (query) Required Integer in group parameters + - parameter stringGroup: (query) String in group parameters (optional) + - parameter booleanGroup: (header) Boolean in group parameters (optional) + - parameter int64Group: (query) Integer in group parameters (optional) + - returns: RequestBuilder + */ + open class func testGroupParametersWithRequestBuilder(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil) -> RequestBuilder { + let path = "/fake" + let URLString = PetstoreClientAPI.basePath + path + let parameters: [String:Any]? = nil + + var url = URLComponents(string: URLString) + url?.queryItems = APIHelper.mapValuesToQueryItems([ + "required_string_group": requiredStringGroup.encodeToJSON(), + "required_int64_group": requiredInt64Group.encodeToJSON(), + "string_group": stringGroup?.encodeToJSON(), + "int64_group": int64Group?.encodeToJSON() + ]) + let nillableHeaders: [String: Any?] = [ + "required_boolean_group": requiredBooleanGroup, + "boolean_group": booleanGroup + ] + let headerParameters = APIHelper.rejectNilHeaders(nillableHeaders) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + return requestBuilder.init(method: "DELETE", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false, headers: headerParameters) + } + /** test inline additionalProperties diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift index 2ade78f5a616..ac14f72c7d0e 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift @@ -154,7 +154,7 @@ open class AlamofireRequestBuilder: RequestBuilder { if stringResponse.result.isFailure { completion( nil, - ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!) + ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error!) ) return } @@ -356,7 +356,7 @@ open class AlamofireDecodableRequestBuilder: AlamofireRequestBuilde if stringResponse.result.isFailure { completion( nil, - ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!) + ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error!) ) return } diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift index bd72d81846d2..584de8c3d57a 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift @@ -11,7 +11,7 @@ public typealias EncodeResult = (data: Data?, error: Error?) open class CodableHelper { - open static var dateformatter: DateFormatter? + public static var dateformatter: DateFormatter? open class func decode(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T : Decodable { var returnedDecodable: T? = nil @@ -26,7 +26,7 @@ open class CodableHelper { 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:ss.SSSXXXXX" + formatter.dateFormat = Configuration.dateFormat decoder.dateDecodingStrategy = .formatted(formatter) } @@ -55,7 +55,7 @@ open class CodableHelper { 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:ss.SSSXXXXX" + formatter.dateFormat = Configuration.dateFormat encoder.dateEncodingStrategy = .formatted(formatter) } diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Configuration.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Configuration.swift index f8180752b67b..516590da5d9e 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Configuration.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Configuration.swift @@ -10,6 +10,6 @@ open class Configuration { // This value is used to configure the date formatter that is used to serialize dates into JSON format. // You must set it prior to encoding any dates, and it will only be read once. - open static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" + public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" } \ No newline at end of file diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Extensions.swift index eb03b10eb477..97a90f9af490 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -67,10 +67,16 @@ extension Data: JSONEncodable { } private let dateFormatter: DateFormatter = { - let fmt = DateFormatter() - fmt.dateFormat = Configuration.dateFormat - fmt.locale = Locale(identifier: "en_US_POSIX") - return fmt + if let formatter = CodableHelper.dateformatter { + return formatter + } else { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = Configuration.dateFormat + return formatter + } }() extension Date: JSONEncodable { diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models.swift index 42f8186ae4af..408563890359 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -15,9 +15,9 @@ public enum ErrorResponse : Error { } open class Response { - open let statusCode: Int - open let header: [String: String] - open let body: T? + public let statusCode: Int + public let header: [String: String] + public let body: T? public init(statusCode: Int, header: [String: String], body: T?) { self.statusCode = statusCode diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/Category.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/Category.swift index 77fba95c1d79..afdc89b6dd06 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/Category.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/Category.swift @@ -12,9 +12,9 @@ import Foundation public struct Category: Codable { public var _id: Int64? - public var name: String? + public var name: String = "default-name" - public init(_id: Int64?, name: String?) { + public init(_id: Int64?, name: String) { self._id = _id self.name = name } diff --git a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift index 2d3a45d35a0c..392c1e443839 100644 --- a/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift +++ b/samples/client/petstore/swift4/promisekit/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift @@ -18,9 +18,9 @@ public struct MapTest: Codable { public var mapMapOfString: [String:[String:String]]? public var mapOfEnumString: [String:String]? public var directMap: [String:Bool]? - public var indirectMap: StringBooleanMap? + public var indirectMap: [String:Bool]? - public init(mapMapOfString: [String:[String:String]]?, mapOfEnumString: [String:String]?, directMap: [String:Bool]?, indirectMap: StringBooleanMap?) { + public init(mapMapOfString: [String:[String:String]]?, mapOfEnumString: [String:String]?, directMap: [String:Bool]?, indirectMap: [String:Bool]?) { self.mapMapOfString = mapMapOfString self.mapOfEnumString = mapOfEnumString self.directMap = directMap diff --git a/samples/client/petstore/swift4/rxswift/.openapi-generator/VERSION b/samples/client/petstore/swift4/rxswift/.openapi-generator/VERSION index 6d94c9c2e12a..e24c1f857e01 100644 --- a/samples/client/petstore/swift4/rxswift/.openapi-generator/VERSION +++ b/samples/client/petstore/swift4/rxswift/.openapi-generator/VERSION @@ -1 +1 @@ -3.3.0-SNAPSHOT \ No newline at end of file +3.3.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs.swift index 8cae3aacfe5a..2890bffa2747 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs.swift @@ -7,10 +7,10 @@ import Foundation open class PetstoreClientAPI { - open static var basePath = "http://petstore.swagger.io:80/v2" - open static var credential: URLCredential? - open static var customHeaders: [String:String] = [:] - open static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory() + public static var basePath = "http://petstore.swagger.io:80/v2" + public static var credential: URLCredential? + public static var customHeaders: [String:String] = [:] + public static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory() } open class RequestBuilder { diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index 415cdf8c231a..8a7431a3b9be 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -639,6 +639,87 @@ open class FakeAPI { return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false, headers: headerParameters) } + /** + Fake endpoint to test group parameters (optional) + + - parameter requiredStringGroup: (query) Required String in group parameters + - parameter requiredBooleanGroup: (header) Required Boolean in group parameters + - parameter requiredInt64Group: (query) Required Integer in group parameters + - parameter stringGroup: (query) String in group parameters (optional) + - parameter booleanGroup: (header) Boolean in group parameters (optional) + - parameter int64Group: (query) Integer in group parameters (optional) + - parameter completion: completion handler to receive the data and the error objects + */ + open class func testGroupParameters(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) { + testGroupParametersWithRequestBuilder(requiredStringGroup: requiredStringGroup, requiredBooleanGroup: requiredBooleanGroup, requiredInt64Group: requiredInt64Group, stringGroup: stringGroup, booleanGroup: booleanGroup, int64Group: int64Group).execute { (response, error) -> Void in + if error == nil { + completion((), error) + } else { + completion(nil, error) + } + } + } + + /** + Fake endpoint to test group parameters (optional) + + - parameter requiredStringGroup: (query) Required String in group parameters + - parameter requiredBooleanGroup: (header) Required Boolean in group parameters + - parameter requiredInt64Group: (query) Required Integer in group parameters + - parameter stringGroup: (query) String in group parameters (optional) + - parameter booleanGroup: (header) Boolean in group parameters (optional) + - parameter int64Group: (query) Integer in group parameters (optional) + - returns: Observable + */ + open class func testGroupParameters(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil) -> Observable { + return Observable.create { observer -> Disposable in + testGroupParameters(requiredStringGroup: requiredStringGroup, requiredBooleanGroup: requiredBooleanGroup, requiredInt64Group: requiredInt64Group, stringGroup: stringGroup, booleanGroup: booleanGroup, int64Group: int64Group) { data, error in + if let error = error { + observer.on(.error(error)) + } else { + observer.on(.next(data!)) + } + observer.on(.completed) + } + return Disposables.create() + } + } + + /** + Fake endpoint to test group parameters (optional) + - DELETE /fake + - Fake endpoint to test group parameters (optional) + - parameter requiredStringGroup: (query) Required String in group parameters + - parameter requiredBooleanGroup: (header) Required Boolean in group parameters + - parameter requiredInt64Group: (query) Required Integer in group parameters + - parameter stringGroup: (query) String in group parameters (optional) + - parameter booleanGroup: (header) Boolean in group parameters (optional) + - parameter int64Group: (query) Integer in group parameters (optional) + - returns: RequestBuilder + */ + open class func testGroupParametersWithRequestBuilder(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil) -> RequestBuilder { + let path = "/fake" + let URLString = PetstoreClientAPI.basePath + path + let parameters: [String:Any]? = nil + + var url = URLComponents(string: URLString) + url?.queryItems = APIHelper.mapValuesToQueryItems([ + "required_string_group": requiredStringGroup.encodeToJSON(), + "required_int64_group": requiredInt64Group.encodeToJSON(), + "string_group": stringGroup?.encodeToJSON(), + "int64_group": int64Group?.encodeToJSON() + ]) + let nillableHeaders: [String: Any?] = [ + "required_boolean_group": requiredBooleanGroup, + "boolean_group": booleanGroup + ] + let headerParameters = APIHelper.rejectNilHeaders(nillableHeaders) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + return requestBuilder.init(method: "DELETE", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false, headers: headerParameters) + } + /** test inline additionalProperties diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift index 2ade78f5a616..ac14f72c7d0e 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift @@ -154,7 +154,7 @@ open class AlamofireRequestBuilder: RequestBuilder { if stringResponse.result.isFailure { completion( nil, - ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!) + ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error!) ) return } @@ -356,7 +356,7 @@ open class AlamofireDecodableRequestBuilder: AlamofireRequestBuilde if stringResponse.result.isFailure { completion( nil, - ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!) + ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error!) ) return } diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift index bd72d81846d2..584de8c3d57a 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift @@ -11,7 +11,7 @@ public typealias EncodeResult = (data: Data?, error: Error?) open class CodableHelper { - open static var dateformatter: DateFormatter? + public static var dateformatter: DateFormatter? open class func decode(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T : Decodable { var returnedDecodable: T? = nil @@ -26,7 +26,7 @@ open class CodableHelper { 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:ss.SSSXXXXX" + formatter.dateFormat = Configuration.dateFormat decoder.dateDecodingStrategy = .formatted(formatter) } @@ -55,7 +55,7 @@ open class CodableHelper { 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:ss.SSSXXXXX" + formatter.dateFormat = Configuration.dateFormat encoder.dateEncodingStrategy = .formatted(formatter) } diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Configuration.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Configuration.swift index f8180752b67b..516590da5d9e 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Configuration.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Configuration.swift @@ -10,6 +10,6 @@ open class Configuration { // This value is used to configure the date formatter that is used to serialize dates into JSON format. // You must set it prior to encoding any dates, and it will only be read once. - open static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" + public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" } \ No newline at end of file diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Extensions.swift index abe218b4e7ac..8bf1829ba806 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -66,10 +66,16 @@ extension Data: JSONEncodable { } private let dateFormatter: DateFormatter = { - let fmt = DateFormatter() - fmt.dateFormat = Configuration.dateFormat - fmt.locale = Locale(identifier: "en_US_POSIX") - return fmt + if let formatter = CodableHelper.dateformatter { + return formatter + } else { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = Configuration.dateFormat + return formatter + } }() extension Date: JSONEncodable { diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models.swift index 42f8186ae4af..408563890359 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -15,9 +15,9 @@ public enum ErrorResponse : Error { } open class Response { - open let statusCode: Int - open let header: [String: String] - open let body: T? + public let statusCode: Int + public let header: [String: String] + public let body: T? public init(statusCode: Int, header: [String: String], body: T?) { self.statusCode = statusCode diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/Category.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/Category.swift index 77fba95c1d79..afdc89b6dd06 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/Category.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/Category.swift @@ -12,9 +12,9 @@ import Foundation public struct Category: Codable { public var _id: Int64? - public var name: String? + public var name: String = "default-name" - public init(_id: Int64?, name: String?) { + public init(_id: Int64?, name: String) { self._id = _id self.name = name } diff --git a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift index 2d3a45d35a0c..392c1e443839 100644 --- a/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift +++ b/samples/client/petstore/swift4/rxswift/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift @@ -18,9 +18,9 @@ public struct MapTest: Codable { public var mapMapOfString: [String:[String:String]]? public var mapOfEnumString: [String:String]? public var directMap: [String:Bool]? - public var indirectMap: StringBooleanMap? + public var indirectMap: [String:Bool]? - public init(mapMapOfString: [String:[String:String]]?, mapOfEnumString: [String:String]?, directMap: [String:Bool]?, indirectMap: StringBooleanMap?) { + public init(mapMapOfString: [String:[String:String]]?, mapOfEnumString: [String:String]?, directMap: [String:Bool]?, indirectMap: [String:Bool]?) { self.mapMapOfString = mapMapOfString self.mapOfEnumString = mapOfEnumString self.directMap = directMap diff --git a/samples/client/petstore/swift4/unwrapRequired/.openapi-generator/VERSION b/samples/client/petstore/swift4/unwrapRequired/.openapi-generator/VERSION index 6d94c9c2e12a..e24c1f857e01 100644 --- a/samples/client/petstore/swift4/unwrapRequired/.openapi-generator/VERSION +++ b/samples/client/petstore/swift4/unwrapRequired/.openapi-generator/VERSION @@ -1 +1 @@ -3.3.0-SNAPSHOT \ No newline at end of file +3.3.3-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs.swift b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs.swift index 8cae3aacfe5a..2890bffa2747 100644 --- a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs.swift +++ b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs.swift @@ -7,10 +7,10 @@ import Foundation open class PetstoreClientAPI { - open static var basePath = "http://petstore.swagger.io:80/v2" - open static var credential: URLCredential? - open static var customHeaders: [String:String] = [:] - open static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory() + public static var basePath = "http://petstore.swagger.io:80/v2" + public static var credential: URLCredential? + public static var customHeaders: [String:String] = [:] + public static var requestBuilderFactory: RequestBuilderFactory = AlamofireRequestBuilderFactory() } open class RequestBuilder { diff --git a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift index 7dc52cc3b00f..a209a492192a 100644 --- a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/APIs/FakeAPI.swift @@ -452,6 +452,63 @@ open class FakeAPI { return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false, headers: headerParameters) } + /** + Fake endpoint to test group parameters (optional) + + - parameter requiredStringGroup: (query) Required String in group parameters + - parameter requiredBooleanGroup: (header) Required Boolean in group parameters + - parameter requiredInt64Group: (query) Required Integer in group parameters + - parameter stringGroup: (query) String in group parameters (optional) + - parameter booleanGroup: (header) Boolean in group parameters (optional) + - parameter int64Group: (query) Integer in group parameters (optional) + - parameter completion: completion handler to receive the data and the error objects + */ + open class func testGroupParameters(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) { + testGroupParametersWithRequestBuilder(requiredStringGroup: requiredStringGroup, requiredBooleanGroup: requiredBooleanGroup, requiredInt64Group: requiredInt64Group, stringGroup: stringGroup, booleanGroup: booleanGroup, int64Group: int64Group).execute { (response, error) -> Void in + if error == nil { + completion((), error) + } else { + completion(nil, error) + } + } + } + + + /** + Fake endpoint to test group parameters (optional) + - DELETE /fake + - Fake endpoint to test group parameters (optional) + - parameter requiredStringGroup: (query) Required String in group parameters + - parameter requiredBooleanGroup: (header) Required Boolean in group parameters + - parameter requiredInt64Group: (query) Required Integer in group parameters + - parameter stringGroup: (query) String in group parameters (optional) + - parameter booleanGroup: (header) Boolean in group parameters (optional) + - parameter int64Group: (query) Integer in group parameters (optional) + - returns: RequestBuilder + */ + open class func testGroupParametersWithRequestBuilder(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil) -> RequestBuilder { + let path = "/fake" + let URLString = PetstoreClientAPI.basePath + path + let parameters: [String:Any]? = nil + + var url = URLComponents(string: URLString) + url?.queryItems = APIHelper.mapValuesToQueryItems([ + "required_string_group": requiredStringGroup.encodeToJSON(), + "required_int64_group": requiredInt64Group.encodeToJSON(), + "string_group": stringGroup?.encodeToJSON(), + "int64_group": int64Group?.encodeToJSON() + ]) + let nillableHeaders: [String: Any?] = [ + "required_boolean_group": requiredBooleanGroup, + "boolean_group": booleanGroup + ] + let headerParameters = APIHelper.rejectNilHeaders(nillableHeaders) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getNonDecodableBuilder() + + return requestBuilder.init(method: "DELETE", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false, headers: headerParameters) + } + /** test inline additionalProperties diff --git a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift index 2ade78f5a616..ac14f72c7d0e 100644 --- a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift +++ b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/AlamofireImplementations.swift @@ -154,7 +154,7 @@ open class AlamofireRequestBuilder: RequestBuilder { if stringResponse.result.isFailure { completion( nil, - ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!) + ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error!) ) return } @@ -356,7 +356,7 @@ open class AlamofireDecodableRequestBuilder: AlamofireRequestBuilde if stringResponse.result.isFailure { completion( nil, - ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error as Error!) + ErrorResponse.error(stringResponse.response?.statusCode ?? 500, stringResponse.data, stringResponse.result.error!) ) return } diff --git a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift index bd72d81846d2..584de8c3d57a 100644 --- a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift +++ b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/CodableHelper.swift @@ -11,7 +11,7 @@ public typealias EncodeResult = (data: Data?, error: Error?) open class CodableHelper { - open static var dateformatter: DateFormatter? + public static var dateformatter: DateFormatter? open class func decode(_ type: T.Type, from data: Data) -> (decodableObj: T?, error: Error?) where T : Decodable { var returnedDecodable: T? = nil @@ -26,7 +26,7 @@ open class CodableHelper { 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:ss.SSSXXXXX" + formatter.dateFormat = Configuration.dateFormat decoder.dateDecodingStrategy = .formatted(formatter) } @@ -55,7 +55,7 @@ open class CodableHelper { 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:ss.SSSXXXXX" + formatter.dateFormat = Configuration.dateFormat encoder.dateEncodingStrategy = .formatted(formatter) } diff --git a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Configuration.swift b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Configuration.swift index f8180752b67b..516590da5d9e 100644 --- a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Configuration.swift +++ b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Configuration.swift @@ -10,6 +10,6 @@ open class Configuration { // This value is used to configure the date formatter that is used to serialize dates into JSON format. // You must set it prior to encoding any dates, and it will only be read once. - open static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" + public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" } \ No newline at end of file diff --git a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Extensions.swift b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Extensions.swift index abe218b4e7ac..8bf1829ba806 100644 --- a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Extensions.swift +++ b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Extensions.swift @@ -66,10 +66,16 @@ extension Data: JSONEncodable { } private let dateFormatter: DateFormatter = { - let fmt = DateFormatter() - fmt.dateFormat = Configuration.dateFormat - fmt.locale = Locale(identifier: "en_US_POSIX") - return fmt + if let formatter = CodableHelper.dateformatter { + return formatter + } else { + let formatter = DateFormatter() + formatter.calendar = Calendar(identifier: .iso8601) + formatter.locale = Locale(identifier: "en_US_POSIX") + formatter.timeZone = TimeZone(secondsFromGMT: 0) + formatter.dateFormat = Configuration.dateFormat + return formatter + } }() extension Date: JSONEncodable { diff --git a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models.swift b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models.swift index 42f8186ae4af..408563890359 100644 --- a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models.swift +++ b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models.swift @@ -15,9 +15,9 @@ public enum ErrorResponse : Error { } open class Response { - open let statusCode: Int - open let header: [String: String] - open let body: T? + public let statusCode: Int + public let header: [String: String] + public let body: T? public init(statusCode: Int, header: [String: String], body: T?) { self.statusCode = statusCode diff --git a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/Category.swift b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/Category.swift index 77fba95c1d79..f369f382d3f2 100644 --- a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/Category.swift +++ b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/Category.swift @@ -12,7 +12,7 @@ import Foundation public struct Category: Codable { public var _id: Int64? - public var name: String? + public var name: String? = "default-name" public init(_id: Int64?, name: String?) { self._id = _id diff --git a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift index 2d3a45d35a0c..392c1e443839 100644 --- a/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift +++ b/samples/client/petstore/swift4/unwrapRequired/PetstoreClient/Classes/OpenAPIs/Models/MapTest.swift @@ -18,9 +18,9 @@ public struct MapTest: Codable { public var mapMapOfString: [String:[String:String]]? public var mapOfEnumString: [String:String]? public var directMap: [String:Bool]? - public var indirectMap: StringBooleanMap? + public var indirectMap: [String:Bool]? - public init(mapMapOfString: [String:[String:String]]?, mapOfEnumString: [String:String]?, directMap: [String:Bool]?, indirectMap: StringBooleanMap?) { + public init(mapMapOfString: [String:[String:String]]?, mapOfEnumString: [String:String]?, directMap: [String:Bool]?, indirectMap: [String:Bool]?) { self.mapMapOfString = mapMapOfString self.mapOfEnumString = mapOfEnumString self.directMap = directMap