diff --git a/modules/swagger-codegen/src/main/resources/swift3/APIs.mustache b/modules/swagger-codegen/src/main/resources/swift3/APIs.mustache index 476924eb171..9db9ba6de80 100644 --- a/modules/swagger-codegen/src/main/resources/swift3/APIs.mustache +++ b/modules/swagger-codegen/src/main/resources/swift3/APIs.mustache @@ -32,7 +32,7 @@ open class APIBase { open class RequestBuilder { var credential: URLCredential? var headers: [String:String] - let parameters: [String:Any]? + let parameters: Any? let isBody: Bool let method: String let URLString: String @@ -40,7 +40,7 @@ open class RequestBuilder { /// Optional block to obtain a reference to the request's progress instance when available. public var onProgressReady: ((Progress) -> ())? - required public init(method: String, URLString: String, parameters: [String:Any]?, isBody: Bool, headers: [String:String] = [:]) { + required public init(method: String, URLString: String, parameters: Any?, isBody: Bool, headers: [String:String] = [:]) { self.method = method self.URLString = URLString self.parameters = parameters diff --git a/modules/swagger-codegen/src/main/resources/swift3/AlamofireImplementations.mustache b/modules/swagger-codegen/src/main/resources/swift3/AlamofireImplementations.mustache index 53b1302cd44..9e84f215801 100644 --- a/modules/swagger-codegen/src/main/resources/swift3/AlamofireImplementations.mustache +++ b/modules/swagger-codegen/src/main/resources/swift3/AlamofireImplementations.mustache @@ -43,11 +43,24 @@ private struct SynchronizedDictionary { } +class JSONEncodingWrapper: ParameterEncoding { + var bodyParameters: Any? + var encoding: JSONEncoding = JSONEncoding() + + public init(parameters: Any?) { + self.bodyParameters = parameters + } + + public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest { + return try encoding.encode(urlRequest, withJSONObject: bodyParameters) + } +} + // Store manager to retain its reference private var managerStore = SynchronizedDictionary() open class AlamofireRequestBuilder: RequestBuilder { - required public init(method: String, URLString: String, parameters: [String : Any]?, isBody: Bool, headers: [String : String] = [:]) { + required public init(method: String, URLString: String, parameters: Any?, isBody: Bool, headers: [String : String] = [:]) { super.init(method: method, URLString: URLString, parameters: parameters, isBody: isBody, headers: headers) } @@ -77,7 +90,7 @@ open class AlamofireRequestBuilder: RequestBuilder { configuration (e.g. to override the cache policy). */ open func makeRequest(manager: SessionManager, method: HTTPMethod, encoding: ParameterEncoding, headers: [String:String]) -> DataRequest { - return manager.request(URLString, method: method, parameters: parameters, encoding: encoding, headers: headers) + return manager.request(URLString, method: method, parameters: parameters as? Parameters, encoding: encoding, headers: headers) } override open func execute(_ completion: @escaping (_ response: Response?, _ error: ErrorResponse?) -> Void) { @@ -86,15 +99,17 @@ open class AlamofireRequestBuilder: RequestBuilder { let manager = createSessionManager() managerStore[managerId] = manager - let encoding:ParameterEncoding = isBody ? JSONEncoding() : URLEncoding() + let encoding:ParameterEncoding = isBody ? JSONEncodingWrapper(parameters: parameters) : URLEncoding() let xMethod = Alamofire.HTTPMethod(rawValue: method) - let fileKeys = parameters == nil ? [] : parameters!.filter { $1 is NSURL } + + let param = parameters as? Parameters + let fileKeys = param == nil ? [] : param!.filter { $1 is NSURL } .map { $0.0 } if fileKeys.count > 0 { manager.upload(multipartFormData: { mpForm in - for (k, v) in self.parameters! { + for (k, v) in param! { switch v { case let fileURL as URL: if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) { diff --git a/modules/swagger-codegen/src/main/resources/swift3/api.mustache b/modules/swagger-codegen/src/main/resources/swift3/api.mustache index fda7fadb373..d60ef7566c7 100644 --- a/modules/swagger-codegen/src/main/resources/swift3/api.mustache +++ b/modules/swagger-codegen/src/main/resources/swift3/api.mustache @@ -123,7 +123,7 @@ open class {{classname}}: APIBase { path = path.replacingOccurrences(of: "{{=<% %>=}}{<%baseName%>}<%={{ }}=%>", with: "\({{paramName}}{{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}.rawValue{{/isContainer}}{{/isEnum}})", options: .literal, range: nil){{/pathParams}} let URLString = {{projectName}}API.basePath + path {{#bodyParam}} - let parameters = {{paramName}}{{^required}}?{{/required}}.encodeToJSON() as? [String:AnyObject] + let parameters = {{paramName}}{{^required}}?{{/required}}.encodeToJSON() {{/bodyParam}} {{^bodyParam}} {{#hasFormParams}} diff --git a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs.swift b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs.swift index 903593769e4..be616c7b71d 100644 --- a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs.swift +++ b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs.swift @@ -32,7 +32,7 @@ open class APIBase { open class RequestBuilder { var credential: URLCredential? var headers: [String:String] - let parameters: [String:Any]? + let parameters: Any? let isBody: Bool let method: String let URLString: String @@ -40,7 +40,7 @@ open class RequestBuilder { /// Optional block to obtain a reference to the request's progress instance when available. public var onProgressReady: ((Progress) -> ())? - required public init(method: String, URLString: String, parameters: [String:Any]?, isBody: Bool, headers: [String:String] = [:]) { + required public init(method: String, URLString: String, parameters: Any?, isBody: Bool, headers: [String:String] = [:]) { self.method = method self.URLString = URLString self.parameters = parameters diff --git a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift new file mode 100644 index 00000000000..2e100b1fdcd --- /dev/null +++ b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift @@ -0,0 +1,48 @@ +// +// AnotherFakeAPI.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire + + +open class AnotherFakeAPI: APIBase { + /** + To test special tags + - parameter body: (body) client model + - parameter completion: completion handler to receive the data and the error objects + */ + open class func testSpecialTags(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) { + testSpecialTagsWithRequestBuilder(body: body).execute { (response, error) -> Void in + completion(response?.body, error) + } + } + + + /** + To test special tags + - PATCH /another-fake/dummy + - To test special tags + + - examples: [{contentType=application/json, example={ + "client" : "client" +}}] + - parameter body: (body) client model + - returns: RequestBuilder + */ + open class func testSpecialTagsWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/another-fake/dummy" + let URLString = PetstoreClientAPI.basePath + path + let parameters = body.encodeToJSON() + + let url = NSURLComponents(string: URLString) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift index 1f5991b2537..dbe5c7ceb6e 100644 --- a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift @@ -32,7 +32,7 @@ open class FakeAPI: APIBase { open class func fakeOuterBooleanSerializeWithRequestBuilder(body: OuterBoolean? = nil) -> RequestBuilder { let path = "/fake/outer/boolean" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -67,7 +67,7 @@ open class FakeAPI: APIBase { open class func fakeOuterCompositeSerializeWithRequestBuilder(body: OuterComposite? = nil) -> RequestBuilder { let path = "/fake/outer/composite" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -98,7 +98,7 @@ open class FakeAPI: APIBase { open class func fakeOuterNumberSerializeWithRequestBuilder(body: OuterNumber? = nil) -> RequestBuilder { let path = "/fake/outer/number" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -129,7 +129,7 @@ open class FakeAPI: APIBase { open class func fakeOuterStringSerializeWithRequestBuilder(body: OuterString? = nil) -> RequestBuilder { let path = "/fake/outer/string" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -164,7 +164,7 @@ open class FakeAPI: APIBase { open class func testClientModelWithRequestBuilder(body: Client) -> RequestBuilder { let path = "/fake" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -307,7 +307,7 @@ open class FakeAPI: APIBase { */ public enum EnumQueryInteger_testEnumParameters: Int32 { case _1 = 1 - case numberminus2 = -2 + case number2 = -2 } /** @@ -315,7 +315,7 @@ open class FakeAPI: APIBase { */ public enum EnumQueryDouble_testEnumParameters: Double { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } /** diff --git a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift new file mode 100644 index 00000000000..e0313d4b2a2 --- /dev/null +++ b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift @@ -0,0 +1,49 @@ +// +// FakeClassnameTags123API.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire + + +open class FakeClassnameTags123API: APIBase { + /** + To test class name in snake case + - parameter body: (body) client model + - parameter completion: completion handler to receive the data and the error objects + */ + open class func testClassname(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) { + testClassnameWithRequestBuilder(body: body).execute { (response, error) -> Void in + completion(response?.body, error) + } + } + + + /** + To test class name in snake case + - PATCH /fake_classname_test + - API Key: + - type: apiKey api_key_query (QUERY) + - name: api_key_query + - examples: [{contentType=application/json, example={ + "client" : "client" +}}] + - parameter body: (body) client model + - returns: RequestBuilder + */ + open class func testClassnameWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/fake_classname_test" + let URLString = PetstoreClientAPI.basePath + path + let parameters = body.encodeToJSON() + + let url = NSURLComponents(string: URLString) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift index 502ed84ec4a..7eaa9ab093f 100644 --- a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift +++ b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift @@ -35,7 +35,7 @@ open class PetAPI: APIBase { open class func addPetWithRequestBuilder(body: Pet) -> RequestBuilder { let path = "/pet" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -448,7 +448,7 @@ open class PetAPI: APIBase { open class func updatePetWithRequestBuilder(body: Pet) -> RequestBuilder { let path = "/pet" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) diff --git a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift index 024c99c7453..006be5ab186 100644 --- a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift +++ b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift @@ -194,7 +194,7 @@ open class StoreAPI: APIBase { open class func placeOrderWithRequestBuilder(body: Order) -> RequestBuilder { let path = "/store/order" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) diff --git a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift index adbd7e690c4..d4020a0a9c8 100644 --- a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift +++ b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift @@ -33,7 +33,7 @@ open class UserAPI: APIBase { open class func createUserWithRequestBuilder(body: User) -> RequestBuilder { let path = "/user" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -65,7 +65,7 @@ open class UserAPI: APIBase { open class func createUsersWithArrayInputWithRequestBuilder(body: [User]) -> RequestBuilder { let path = "/user/createWithArray" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -97,7 +97,7 @@ open class UserAPI: APIBase { open class func createUsersWithListInputWithRequestBuilder(body: [User]) -> RequestBuilder { let path = "/user/createWithList" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -308,7 +308,7 @@ open class UserAPI: APIBase { var path = "/user/{username}" path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil) let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) diff --git a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift index 53b1302cd44..9e84f215801 100644 --- a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift +++ b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift @@ -43,11 +43,24 @@ private struct SynchronizedDictionary { } +class JSONEncodingWrapper: ParameterEncoding { + var bodyParameters: Any? + var encoding: JSONEncoding = JSONEncoding() + + public init(parameters: Any?) { + self.bodyParameters = parameters + } + + public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest { + return try encoding.encode(urlRequest, withJSONObject: bodyParameters) + } +} + // Store manager to retain its reference private var managerStore = SynchronizedDictionary() open class AlamofireRequestBuilder: RequestBuilder { - required public init(method: String, URLString: String, parameters: [String : Any]?, isBody: Bool, headers: [String : String] = [:]) { + required public init(method: String, URLString: String, parameters: Any?, isBody: Bool, headers: [String : String] = [:]) { super.init(method: method, URLString: URLString, parameters: parameters, isBody: isBody, headers: headers) } @@ -77,7 +90,7 @@ open class AlamofireRequestBuilder: RequestBuilder { configuration (e.g. to override the cache policy). */ open func makeRequest(manager: SessionManager, method: HTTPMethod, encoding: ParameterEncoding, headers: [String:String]) -> DataRequest { - return manager.request(URLString, method: method, parameters: parameters, encoding: encoding, headers: headers) + return manager.request(URLString, method: method, parameters: parameters as? Parameters, encoding: encoding, headers: headers) } override open func execute(_ completion: @escaping (_ response: Response?, _ error: ErrorResponse?) -> Void) { @@ -86,15 +99,17 @@ open class AlamofireRequestBuilder: RequestBuilder { let manager = createSessionManager() managerStore[managerId] = manager - let encoding:ParameterEncoding = isBody ? JSONEncoding() : URLEncoding() + let encoding:ParameterEncoding = isBody ? JSONEncodingWrapper(parameters: parameters) : URLEncoding() let xMethod = Alamofire.HTTPMethod(rawValue: method) - let fileKeys = parameters == nil ? [] : parameters!.filter { $1 is NSURL } + + let param = parameters as? Parameters + let fileKeys = param == nil ? [] : param!.filter { $1 is NSURL } .map { $0.0 } if fileKeys.count > 0 { manager.upload(multipartFormData: { mpForm in - for (k, v) in self.parameters! { + for (k, v) in param! { switch v { case let fileURL as URL: if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) { diff --git a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift index ac5a3307532..2607822cb94 100644 --- a/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift +++ b/samples/client/petstore/swift3/default/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift @@ -17,11 +17,11 @@ open class EnumTest: JSONEncodable { } public enum EnumInteger: Int32 { case _1 = 1 - case numberminus1 = -1 + case number1 = -1 } public enum EnumNumber: Double { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } public var enumString: EnumString? public var enumInteger: EnumInteger? diff --git a/samples/client/petstore/swift3/default/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift b/samples/client/petstore/swift3/default/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift index 103ee1b90d1..87d10dd12e0 100644 --- a/samples/client/petstore/swift3/default/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift +++ b/samples/client/petstore/swift3/default/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift @@ -79,6 +79,39 @@ class UserAPITests: XCTestCase { self.waitForExpectations(timeout: testTimeout, handler: nil) } + func testCreateUserWithArray() { + let expectation = self.expectation(description: "testCreateUserWithArray") + let newUser = User() + newUser.email = "test@test.com" + newUser.firstName = "Test" + newUser.lastName = "Tester" + newUser.id = 1000 + newUser.password = "test!" + newUser.phone = "867-5309" + newUser.username = "test@test.com" + newUser.userStatus = 0 + + let newUser2 = User() + newUser2.email = "test2@test.com" + newUser2.firstName = "Test2" + newUser2.lastName = "Tester2" + newUser2.id = 1001 + newUser2.password = "test2!" + newUser2.phone = "867-5302" + newUser2.username = "test2@test.com" + newUser2.userStatus = 0 + + UserAPI.createUsersWithArrayInput(body: [newUser, newUser2]) { (error) in + guard error == nil else { + XCTFail("error creating users") + return + } + + expectation.fulfill() + } + self.waitForExpectations(timeout: testTimeout, handler: nil) + } + func test2GetUser() { let expectation = self.expectation(description: "testGetUser") diff --git a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs.swift b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs.swift index 903593769e4..be616c7b71d 100644 --- a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs.swift +++ b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs.swift @@ -32,7 +32,7 @@ open class APIBase { open class RequestBuilder { var credential: URLCredential? var headers: [String:String] - let parameters: [String:Any]? + let parameters: Any? let isBody: Bool let method: String let URLString: String @@ -40,7 +40,7 @@ open class RequestBuilder { /// Optional block to obtain a reference to the request's progress instance when available. public var onProgressReady: ((Progress) -> ())? - required public init(method: String, URLString: String, parameters: [String:Any]?, isBody: Bool, headers: [String:String] = [:]) { + required public init(method: String, URLString: String, parameters: Any?, isBody: Bool, headers: [String:String] = [:]) { self.method = method self.URLString = URLString self.parameters = parameters diff --git a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift new file mode 100644 index 00000000000..82e9b8fac64 --- /dev/null +++ b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift @@ -0,0 +1,65 @@ +// +// AnotherFakeAPI.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire +import PromiseKit + + +open class AnotherFakeAPI: APIBase { + /** + To test special tags + - parameter body: (body) client model + - parameter completion: completion handler to receive the data and the error objects + */ + open class func testSpecialTags(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) { + testSpecialTagsWithRequestBuilder(body: body).execute { (response, error) -> Void in + completion(response?.body, error) + } + } + + /** + To test special tags + - parameter body: (body) client model + - returns: Promise + */ + open class func testSpecialTags( body: Client) -> Promise { + let deferred = Promise.pending() + testSpecialTags(body: body) { data, error in + if let error = error { + deferred.reject(error) + } else { + deferred.fulfill(data!) + } + } + return deferred.promise + } + + /** + To test special tags + - PATCH /another-fake/dummy + - To test special tags + + - examples: [{contentType=application/json, example={ + "client" : "client" +}}] + - parameter body: (body) client model + - returns: RequestBuilder + */ + open class func testSpecialTagsWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/another-fake/dummy" + let URLString = PetstoreClientAPI.basePath + path + let parameters = body.encodeToJSON() + + let url = NSURLComponents(string: URLString) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift index 53fa0b3866b..1e328450eb7 100644 --- a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift @@ -48,7 +48,7 @@ open class FakeAPI: APIBase { open class func fakeOuterBooleanSerializeWithRequestBuilder(body: OuterBoolean? = nil) -> RequestBuilder { let path = "/fake/outer/boolean" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -98,7 +98,7 @@ open class FakeAPI: APIBase { open class func fakeOuterCompositeSerializeWithRequestBuilder(body: OuterComposite? = nil) -> RequestBuilder { let path = "/fake/outer/composite" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -144,7 +144,7 @@ open class FakeAPI: APIBase { open class func fakeOuterNumberSerializeWithRequestBuilder(body: OuterNumber? = nil) -> RequestBuilder { let path = "/fake/outer/number" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -190,7 +190,7 @@ open class FakeAPI: APIBase { open class func fakeOuterStringSerializeWithRequestBuilder(body: OuterString? = nil) -> RequestBuilder { let path = "/fake/outer/string" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -241,7 +241,7 @@ open class FakeAPI: APIBase { open class func testClientModelWithRequestBuilder(body: Client) -> RequestBuilder { let path = "/fake" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -413,7 +413,7 @@ open class FakeAPI: APIBase { */ public enum EnumQueryInteger_testEnumParameters: Int32 { case _1 = 1 - case numberminus2 = -2 + case number2 = -2 } /** @@ -421,7 +421,7 @@ open class FakeAPI: APIBase { */ public enum EnumQueryDouble_testEnumParameters: Double { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } /** diff --git a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift new file mode 100644 index 00000000000..37f48c0e719 --- /dev/null +++ b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift @@ -0,0 +1,66 @@ +// +// FakeClassnameTags123API.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire +import PromiseKit + + +open class FakeClassnameTags123API: APIBase { + /** + To test class name in snake case + - parameter body: (body) client model + - parameter completion: completion handler to receive the data and the error objects + */ + open class func testClassname(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) { + testClassnameWithRequestBuilder(body: body).execute { (response, error) -> Void in + completion(response?.body, error) + } + } + + /** + To test class name in snake case + - parameter body: (body) client model + - returns: Promise + */ + open class func testClassname( body: Client) -> Promise { + let deferred = Promise.pending() + testClassname(body: body) { data, error in + if let error = error { + deferred.reject(error) + } else { + deferred.fulfill(data!) + } + } + return deferred.promise + } + + /** + To test class name in snake case + - PATCH /fake_classname_test + - API Key: + - type: apiKey api_key_query (QUERY) + - name: api_key_query + - examples: [{contentType=application/json, example={ + "client" : "client" +}}] + - parameter body: (body) client model + - returns: RequestBuilder + */ + open class func testClassnameWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/fake_classname_test" + let URLString = PetstoreClientAPI.basePath + path + let parameters = body.encodeToJSON() + + let url = NSURLComponents(string: URLString) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift index a632b3bfc22..09da8f6f1fe 100644 --- a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift +++ b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift @@ -52,7 +52,7 @@ open class PetAPI: APIBase { open class func addPetWithRequestBuilder(body: Pet) -> RequestBuilder { let path = "/pet" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -546,7 +546,7 @@ open class PetAPI: APIBase { open class func updatePetWithRequestBuilder(body: Pet) -> RequestBuilder { let path = "/pet" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) diff --git a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift index b76092dda11..599711ea67d 100644 --- a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift +++ b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift @@ -258,7 +258,7 @@ open class StoreAPI: APIBase { open class func placeOrderWithRequestBuilder(body: Order) -> RequestBuilder { let path = "/store/order" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) diff --git a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift index 2c848d22f40..6ec966a9567 100644 --- a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift +++ b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift @@ -50,7 +50,7 @@ open class UserAPI: APIBase { open class func createUserWithRequestBuilder(body: User) -> RequestBuilder { let path = "/user" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -98,7 +98,7 @@ open class UserAPI: APIBase { open class func createUsersWithArrayInputWithRequestBuilder(body: [User]) -> RequestBuilder { let path = "/user/createWithArray" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -146,7 +146,7 @@ open class UserAPI: APIBase { open class func createUsersWithListInputWithRequestBuilder(body: [User]) -> RequestBuilder { let path = "/user/createWithList" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -438,7 +438,7 @@ open class UserAPI: APIBase { var path = "/user/{username}" path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil) let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) diff --git a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift index 53b1302cd44..9e84f215801 100644 --- a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift +++ b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift @@ -43,11 +43,24 @@ private struct SynchronizedDictionary { } +class JSONEncodingWrapper: ParameterEncoding { + var bodyParameters: Any? + var encoding: JSONEncoding = JSONEncoding() + + public init(parameters: Any?) { + self.bodyParameters = parameters + } + + public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest { + return try encoding.encode(urlRequest, withJSONObject: bodyParameters) + } +} + // Store manager to retain its reference private var managerStore = SynchronizedDictionary() open class AlamofireRequestBuilder: RequestBuilder { - required public init(method: String, URLString: String, parameters: [String : Any]?, isBody: Bool, headers: [String : String] = [:]) { + required public init(method: String, URLString: String, parameters: Any?, isBody: Bool, headers: [String : String] = [:]) { super.init(method: method, URLString: URLString, parameters: parameters, isBody: isBody, headers: headers) } @@ -77,7 +90,7 @@ open class AlamofireRequestBuilder: RequestBuilder { configuration (e.g. to override the cache policy). */ open func makeRequest(manager: SessionManager, method: HTTPMethod, encoding: ParameterEncoding, headers: [String:String]) -> DataRequest { - return manager.request(URLString, method: method, parameters: parameters, encoding: encoding, headers: headers) + return manager.request(URLString, method: method, parameters: parameters as? Parameters, encoding: encoding, headers: headers) } override open func execute(_ completion: @escaping (_ response: Response?, _ error: ErrorResponse?) -> Void) { @@ -86,15 +99,17 @@ open class AlamofireRequestBuilder: RequestBuilder { let manager = createSessionManager() managerStore[managerId] = manager - let encoding:ParameterEncoding = isBody ? JSONEncoding() : URLEncoding() + let encoding:ParameterEncoding = isBody ? JSONEncodingWrapper(parameters: parameters) : URLEncoding() let xMethod = Alamofire.HTTPMethod(rawValue: method) - let fileKeys = parameters == nil ? [] : parameters!.filter { $1 is NSURL } + + let param = parameters as? Parameters + let fileKeys = param == nil ? [] : param!.filter { $1 is NSURL } .map { $0.0 } if fileKeys.count > 0 { manager.upload(multipartFormData: { mpForm in - for (k, v) in self.parameters! { + for (k, v) in param! { switch v { case let fileURL as URL: if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) { diff --git a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift index ac5a3307532..2607822cb94 100644 --- a/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift +++ b/samples/client/petstore/swift3/promisekit/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift @@ -17,11 +17,11 @@ open class EnumTest: JSONEncodable { } public enum EnumInteger: Int32 { case _1 = 1 - case numberminus1 = -1 + case number1 = -1 } public enum EnumNumber: Double { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } public var enumString: EnumString? public var enumInteger: EnumInteger? diff --git a/samples/client/petstore/swift3/promisekit/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift b/samples/client/petstore/swift3/promisekit/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift index 3042129608c..f172e732513 100644 --- a/samples/client/petstore/swift3/promisekit/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift +++ b/samples/client/petstore/swift3/promisekit/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift @@ -48,6 +48,34 @@ class UserAPITests: XCTestCase { self.waitForExpectations(timeout: testTimeout, handler: nil) } + func testCreateUserWithArray() { + let expectation = self.expectation(description: "testCreateUserWithArray") + let newUser = User() + newUser.email = "test@test.com" + newUser.firstName = "Test" + newUser.lastName = "Tester" + newUser.id = 1000 + newUser.password = "test!" + newUser.phone = "867-5309" + newUser.username = "test@test.com" + newUser.userStatus = 0 + + let newUser2 = User() + newUser2.email = "test2@test.com" + newUser2.firstName = "Test2" + newUser2.lastName = "Tester2" + newUser2.id = 1001 + newUser2.password = "test2!" + newUser2.phone = "867-5302" + newUser2.username = "test2@test.com" + newUser2.userStatus = 0 + + _ = UserAPI.createUsersWithArrayInput(body: [newUser, newUser2]).then { + expectation.fulfill() + } + self.waitForExpectations(timeout: testTimeout, handler: nil) + } + func test2GetUser() { let expectation = self.expectation(description: "testGetUser") UserAPI.getUserByName(username: "test@test.com").then {user -> Void in diff --git a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs.swift b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs.swift index 903593769e4..be616c7b71d 100644 --- a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs.swift +++ b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs.swift @@ -32,7 +32,7 @@ open class APIBase { open class RequestBuilder { var credential: URLCredential? var headers: [String:String] - let parameters: [String:Any]? + let parameters: Any? let isBody: Bool let method: String let URLString: String @@ -40,7 +40,7 @@ open class RequestBuilder { /// Optional block to obtain a reference to the request's progress instance when available. public var onProgressReady: ((Progress) -> ())? - required public init(method: String, URLString: String, parameters: [String:Any]?, isBody: Bool, headers: [String:String] = [:]) { + required public init(method: String, URLString: String, parameters: Any?, isBody: Bool, headers: [String:String] = [:]) { self.method = method self.URLString = URLString self.parameters = parameters diff --git a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift new file mode 100644 index 00000000000..b37257eb955 --- /dev/null +++ b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift @@ -0,0 +1,67 @@ +// +// AnotherFakeAPI.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire +import RxSwift + + +open class AnotherFakeAPI: APIBase { + /** + To test special tags + - parameter body: (body) client model + - parameter completion: completion handler to receive the data and the error objects + */ + open class func testSpecialTags(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) { + testSpecialTagsWithRequestBuilder(body: body).execute { (response, error) -> Void in + completion(response?.body, error) + } + } + + /** + To test special tags + - parameter body: (body) client model + - returns: Observable + */ + open class func testSpecialTags(body: Client) -> Observable { + return Observable.create { observer -> Disposable in + testSpecialTags(body: body) { data, error in + if let error = error { + observer.on(.error(error as Error)) + } else { + observer.on(.next(data!)) + } + observer.on(.completed) + } + return Disposables.create() + } + } + + /** + To test special tags + - PATCH /another-fake/dummy + - To test special tags + + - examples: [{contentType=application/json, example={ + "client" : "client" +}}] + - parameter body: (body) client model + - returns: RequestBuilder + */ + open class func testSpecialTagsWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/another-fake/dummy" + let URLString = PetstoreClientAPI.basePath + path + let parameters = body.encodeToJSON() + + let url = NSURLComponents(string: URLString) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift index 3309c9b98b0..a372f52b955 100644 --- a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift @@ -50,7 +50,7 @@ open class FakeAPI: APIBase { open class func fakeOuterBooleanSerializeWithRequestBuilder(body: OuterBoolean? = nil) -> RequestBuilder { let path = "/fake/outer/boolean" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -102,7 +102,7 @@ open class FakeAPI: APIBase { open class func fakeOuterCompositeSerializeWithRequestBuilder(body: OuterComposite? = nil) -> RequestBuilder { let path = "/fake/outer/composite" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -150,7 +150,7 @@ open class FakeAPI: APIBase { open class func fakeOuterNumberSerializeWithRequestBuilder(body: OuterNumber? = nil) -> RequestBuilder { let path = "/fake/outer/number" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -198,7 +198,7 @@ open class FakeAPI: APIBase { open class func fakeOuterStringSerializeWithRequestBuilder(body: OuterString? = nil) -> RequestBuilder { let path = "/fake/outer/string" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -251,7 +251,7 @@ open class FakeAPI: APIBase { open class func testClientModelWithRequestBuilder(body: Client) -> RequestBuilder { let path = "/fake" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -425,7 +425,7 @@ open class FakeAPI: APIBase { */ public enum EnumQueryInteger_testEnumParameters: Int32 { case _1 = 1 - case numberminus2 = -2 + case number2 = -2 } /** @@ -433,7 +433,7 @@ open class FakeAPI: APIBase { */ public enum EnumQueryDouble_testEnumParameters: Double { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } /** diff --git a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift new file mode 100644 index 00000000000..bbad2e38b9f --- /dev/null +++ b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift @@ -0,0 +1,68 @@ +// +// FakeClassnameTags123API.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire +import RxSwift + + +open class FakeClassnameTags123API: APIBase { + /** + To test class name in snake case + - parameter body: (body) client model + - parameter completion: completion handler to receive the data and the error objects + */ + open class func testClassname(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) { + testClassnameWithRequestBuilder(body: body).execute { (response, error) -> Void in + completion(response?.body, error) + } + } + + /** + To test class name in snake case + - parameter body: (body) client model + - returns: Observable + */ + open class func testClassname(body: Client) -> Observable { + return Observable.create { observer -> Disposable in + testClassname(body: body) { data, error in + if let error = error { + observer.on(.error(error as Error)) + } else { + observer.on(.next(data!)) + } + observer.on(.completed) + } + return Disposables.create() + } + } + + /** + To test class name in snake case + - PATCH /fake_classname_test + - API Key: + - type: apiKey api_key_query (QUERY) + - name: api_key_query + - examples: [{contentType=application/json, example={ + "client" : "client" +}}] + - parameter body: (body) client model + - returns: RequestBuilder + */ + open class func testClassnameWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/fake_classname_test" + let URLString = PetstoreClientAPI.basePath + path + let parameters = body.encodeToJSON() + + let url = NSURLComponents(string: URLString) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift index ae0bf564d4b..ecd41c83355 100644 --- a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift +++ b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift @@ -54,7 +54,7 @@ open class PetAPI: APIBase { open class func addPetWithRequestBuilder(body: Pet) -> RequestBuilder { let path = "/pet" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -558,7 +558,7 @@ open class PetAPI: APIBase { open class func updatePetWithRequestBuilder(body: Pet) -> RequestBuilder { let path = "/pet" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) diff --git a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift index f78b6766486..3a6112402d8 100644 --- a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift +++ b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift @@ -266,7 +266,7 @@ open class StoreAPI: APIBase { open class func placeOrderWithRequestBuilder(body: Order) -> RequestBuilder { let path = "/store/order" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) diff --git a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift index 8456a04a5a9..99a91b910f4 100644 --- a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift +++ b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift @@ -52,7 +52,7 @@ open class UserAPI: APIBase { open class func createUserWithRequestBuilder(body: User) -> RequestBuilder { let path = "/user" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -102,7 +102,7 @@ open class UserAPI: APIBase { open class func createUsersWithArrayInputWithRequestBuilder(body: [User]) -> RequestBuilder { let path = "/user/createWithArray" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -152,7 +152,7 @@ open class UserAPI: APIBase { open class func createUsersWithListInputWithRequestBuilder(body: [User]) -> RequestBuilder { let path = "/user/createWithList" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -454,7 +454,7 @@ open class UserAPI: APIBase { var path = "/user/{username}" path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil) let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) diff --git a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift index 53b1302cd44..9e84f215801 100644 --- a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift +++ b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift @@ -43,11 +43,24 @@ private struct SynchronizedDictionary { } +class JSONEncodingWrapper: ParameterEncoding { + var bodyParameters: Any? + var encoding: JSONEncoding = JSONEncoding() + + public init(parameters: Any?) { + self.bodyParameters = parameters + } + + public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest { + return try encoding.encode(urlRequest, withJSONObject: bodyParameters) + } +} + // Store manager to retain its reference private var managerStore = SynchronizedDictionary() open class AlamofireRequestBuilder: RequestBuilder { - required public init(method: String, URLString: String, parameters: [String : Any]?, isBody: Bool, headers: [String : String] = [:]) { + required public init(method: String, URLString: String, parameters: Any?, isBody: Bool, headers: [String : String] = [:]) { super.init(method: method, URLString: URLString, parameters: parameters, isBody: isBody, headers: headers) } @@ -77,7 +90,7 @@ open class AlamofireRequestBuilder: RequestBuilder { configuration (e.g. to override the cache policy). */ open func makeRequest(manager: SessionManager, method: HTTPMethod, encoding: ParameterEncoding, headers: [String:String]) -> DataRequest { - return manager.request(URLString, method: method, parameters: parameters, encoding: encoding, headers: headers) + return manager.request(URLString, method: method, parameters: parameters as? Parameters, encoding: encoding, headers: headers) } override open func execute(_ completion: @escaping (_ response: Response?, _ error: ErrorResponse?) -> Void) { @@ -86,15 +99,17 @@ open class AlamofireRequestBuilder: RequestBuilder { let manager = createSessionManager() managerStore[managerId] = manager - let encoding:ParameterEncoding = isBody ? JSONEncoding() : URLEncoding() + let encoding:ParameterEncoding = isBody ? JSONEncodingWrapper(parameters: parameters) : URLEncoding() let xMethod = Alamofire.HTTPMethod(rawValue: method) - let fileKeys = parameters == nil ? [] : parameters!.filter { $1 is NSURL } + + let param = parameters as? Parameters + let fileKeys = param == nil ? [] : param!.filter { $1 is NSURL } .map { $0.0 } if fileKeys.count > 0 { manager.upload(multipartFormData: { mpForm in - for (k, v) in self.parameters! { + for (k, v) in param! { switch v { case let fileURL as URL: if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) { diff --git a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift index ac5a3307532..2607822cb94 100644 --- a/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift +++ b/samples/client/petstore/swift3/rxswift/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift @@ -17,11 +17,11 @@ open class EnumTest: JSONEncodable { } public enum EnumInteger: Int32 { case _1 = 1 - case numberminus1 = -1 + case number1 = -1 } public enum EnumNumber: Double { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } public var enumString: EnumString? public var enumInteger: EnumInteger? diff --git a/samples/client/petstore/swift3/rxswift/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift b/samples/client/petstore/swift3/rxswift/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift index c806c6a799a..4159baa1754 100644 --- a/samples/client/petstore/swift3/rxswift/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift +++ b/samples/client/petstore/swift3/rxswift/SwaggerClientTests/SwaggerClientTests/UserAPITests.swift @@ -93,6 +93,36 @@ class UserAPITests: XCTestCase { }, onCompleted: nil, onDisposed: nil).addDisposableTo(disposeBag) self.waitForExpectations(timeout: testTimeout, handler: nil) } + + func testCreateUserWithArray() { + let expectation = self.expectation(description: "testCreateUserWithArray") + let newUser = User() + newUser.email = "test@test.com" + newUser.firstName = "Test" + newUser.lastName = "Tester" + newUser.id = 1000 + newUser.password = "test!" + newUser.phone = "867-5309" + newUser.username = "test@test.com" + newUser.userStatus = 0 + + let newUser2 = User() + newUser2.email = "test2@test.com" + newUser2.firstName = "Test2" + newUser2.lastName = "Tester2" + newUser2.id = 1001 + newUser2.password = "test2!" + newUser2.phone = "867-5302" + newUser2.username = "test2@test.com" + newUser2.userStatus = 0 + + _ = UserAPI.createUsersWithArrayInput(body: [newUser, newUser2]).subscribe(onNext: { + expectation.fulfill() + }, onError: { _ in + XCTFail("error creating users") + }) + self.waitForExpectations(timeout: testTimeout, handler: nil) + } func test2GetUser() { let expectation = self.expectation(description: "testGetUser") diff --git a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs.swift b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs.swift index 903593769e4..be616c7b71d 100644 --- a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs.swift +++ b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs.swift @@ -32,7 +32,7 @@ open class APIBase { open class RequestBuilder { var credential: URLCredential? var headers: [String:String] - let parameters: [String:Any]? + let parameters: Any? let isBody: Bool let method: String let URLString: String @@ -40,7 +40,7 @@ open class RequestBuilder { /// Optional block to obtain a reference to the request's progress instance when available. public var onProgressReady: ((Progress) -> ())? - required public init(method: String, URLString: String, parameters: [String:Any]?, isBody: Bool, headers: [String:String] = [:]) { + required public init(method: String, URLString: String, parameters: Any?, isBody: Bool, headers: [String:String] = [:]) { self.method = method self.URLString = URLString self.parameters = parameters diff --git a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift new file mode 100644 index 00000000000..2e100b1fdcd --- /dev/null +++ b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/AnotherFakeAPI.swift @@ -0,0 +1,48 @@ +// +// AnotherFakeAPI.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire + + +open class AnotherFakeAPI: APIBase { + /** + To test special tags + - parameter body: (body) client model + - parameter completion: completion handler to receive the data and the error objects + */ + open class func testSpecialTags(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) { + testSpecialTagsWithRequestBuilder(body: body).execute { (response, error) -> Void in + completion(response?.body, error) + } + } + + + /** + To test special tags + - PATCH /another-fake/dummy + - To test special tags + + - examples: [{contentType=application/json, example={ + "client" : "client" +}}] + - parameter body: (body) client model + - returns: RequestBuilder + */ + open class func testSpecialTagsWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/another-fake/dummy" + let URLString = PetstoreClientAPI.basePath + path + let parameters = body.encodeToJSON() + + let url = NSURLComponents(string: URLString) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift index 1f5991b2537..dbe5c7ceb6e 100644 --- a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift +++ b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/FakeAPI.swift @@ -32,7 +32,7 @@ open class FakeAPI: APIBase { open class func fakeOuterBooleanSerializeWithRequestBuilder(body: OuterBoolean? = nil) -> RequestBuilder { let path = "/fake/outer/boolean" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -67,7 +67,7 @@ open class FakeAPI: APIBase { open class func fakeOuterCompositeSerializeWithRequestBuilder(body: OuterComposite? = nil) -> RequestBuilder { let path = "/fake/outer/composite" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -98,7 +98,7 @@ open class FakeAPI: APIBase { open class func fakeOuterNumberSerializeWithRequestBuilder(body: OuterNumber? = nil) -> RequestBuilder { let path = "/fake/outer/number" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -129,7 +129,7 @@ open class FakeAPI: APIBase { open class func fakeOuterStringSerializeWithRequestBuilder(body: OuterString? = nil) -> RequestBuilder { let path = "/fake/outer/string" let URLString = PetstoreClientAPI.basePath + path - let parameters = body?.encodeToJSON() as? [String:AnyObject] + let parameters = body?.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -164,7 +164,7 @@ open class FakeAPI: APIBase { open class func testClientModelWithRequestBuilder(body: Client) -> RequestBuilder { let path = "/fake" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -307,7 +307,7 @@ open class FakeAPI: APIBase { */ public enum EnumQueryInteger_testEnumParameters: Int32 { case _1 = 1 - case numberminus2 = -2 + case number2 = -2 } /** @@ -315,7 +315,7 @@ open class FakeAPI: APIBase { */ public enum EnumQueryDouble_testEnumParameters: Double { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } /** diff --git a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift new file mode 100644 index 00000000000..e0313d4b2a2 --- /dev/null +++ b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/FakeClassnameTags123API.swift @@ -0,0 +1,49 @@ +// +// FakeClassnameTags123API.swift +// +// Generated by swagger-codegen +// https://github.com/swagger-api/swagger-codegen +// + +import Foundation +import Alamofire + + +open class FakeClassnameTags123API: APIBase { + /** + To test class name in snake case + - parameter body: (body) client model + - parameter completion: completion handler to receive the data and the error objects + */ + open class func testClassname(body: Client, completion: @escaping ((_ data: Client?, _ error: ErrorResponse?) -> Void)) { + testClassnameWithRequestBuilder(body: body).execute { (response, error) -> Void in + completion(response?.body, error) + } + } + + + /** + To test class name in snake case + - PATCH /fake_classname_test + - API Key: + - type: apiKey api_key_query (QUERY) + - name: api_key_query + - examples: [{contentType=application/json, example={ + "client" : "client" +}}] + - parameter body: (body) client model + - returns: RequestBuilder + */ + open class func testClassnameWithRequestBuilder(body: Client) -> RequestBuilder { + let path = "/fake_classname_test" + let URLString = PetstoreClientAPI.basePath + path + let parameters = body.encodeToJSON() + + let url = NSURLComponents(string: URLString) + + let requestBuilder: RequestBuilder.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder() + + return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true) + } + +} diff --git a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift index 502ed84ec4a..7eaa9ab093f 100644 --- a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift +++ b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/PetAPI.swift @@ -35,7 +35,7 @@ open class PetAPI: APIBase { open class func addPetWithRequestBuilder(body: Pet) -> RequestBuilder { let path = "/pet" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -448,7 +448,7 @@ open class PetAPI: APIBase { open class func updatePetWithRequestBuilder(body: Pet) -> RequestBuilder { let path = "/pet" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) diff --git a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift index 024c99c7453..006be5ab186 100644 --- a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift +++ b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/StoreAPI.swift @@ -194,7 +194,7 @@ open class StoreAPI: APIBase { open class func placeOrderWithRequestBuilder(body: Order) -> RequestBuilder { let path = "/store/order" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) diff --git a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift index adbd7e690c4..d4020a0a9c8 100644 --- a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift +++ b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/APIs/UserAPI.swift @@ -33,7 +33,7 @@ open class UserAPI: APIBase { open class func createUserWithRequestBuilder(body: User) -> RequestBuilder { let path = "/user" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -65,7 +65,7 @@ open class UserAPI: APIBase { open class func createUsersWithArrayInputWithRequestBuilder(body: [User]) -> RequestBuilder { let path = "/user/createWithArray" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -97,7 +97,7 @@ open class UserAPI: APIBase { open class func createUsersWithListInputWithRequestBuilder(body: [User]) -> RequestBuilder { let path = "/user/createWithList" let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) @@ -308,7 +308,7 @@ open class UserAPI: APIBase { var path = "/user/{username}" path = path.replacingOccurrences(of: "{username}", with: "\(username)", options: .literal, range: nil) let URLString = PetstoreClientAPI.basePath + path - let parameters = body.encodeToJSON() as? [String:AnyObject] + let parameters = body.encodeToJSON() let url = NSURLComponents(string: URLString) diff --git a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift index 53b1302cd44..9e84f215801 100644 --- a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift +++ b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/AlamofireImplementations.swift @@ -43,11 +43,24 @@ private struct SynchronizedDictionary { } +class JSONEncodingWrapper: ParameterEncoding { + var bodyParameters: Any? + var encoding: JSONEncoding = JSONEncoding() + + public init(parameters: Any?) { + self.bodyParameters = parameters + } + + public func encode(_ urlRequest: URLRequestConvertible, with parameters: Parameters?) throws -> URLRequest { + return try encoding.encode(urlRequest, withJSONObject: bodyParameters) + } +} + // Store manager to retain its reference private var managerStore = SynchronizedDictionary() open class AlamofireRequestBuilder: RequestBuilder { - required public init(method: String, URLString: String, parameters: [String : Any]?, isBody: Bool, headers: [String : String] = [:]) { + required public init(method: String, URLString: String, parameters: Any?, isBody: Bool, headers: [String : String] = [:]) { super.init(method: method, URLString: URLString, parameters: parameters, isBody: isBody, headers: headers) } @@ -77,7 +90,7 @@ open class AlamofireRequestBuilder: RequestBuilder { configuration (e.g. to override the cache policy). */ open func makeRequest(manager: SessionManager, method: HTTPMethod, encoding: ParameterEncoding, headers: [String:String]) -> DataRequest { - return manager.request(URLString, method: method, parameters: parameters, encoding: encoding, headers: headers) + return manager.request(URLString, method: method, parameters: parameters as? Parameters, encoding: encoding, headers: headers) } override open func execute(_ completion: @escaping (_ response: Response?, _ error: ErrorResponse?) -> Void) { @@ -86,15 +99,17 @@ open class AlamofireRequestBuilder: RequestBuilder { let manager = createSessionManager() managerStore[managerId] = manager - let encoding:ParameterEncoding = isBody ? JSONEncoding() : URLEncoding() + let encoding:ParameterEncoding = isBody ? JSONEncodingWrapper(parameters: parameters) : URLEncoding() let xMethod = Alamofire.HTTPMethod(rawValue: method) - let fileKeys = parameters == nil ? [] : parameters!.filter { $1 is NSURL } + + let param = parameters as? Parameters + let fileKeys = param == nil ? [] : param!.filter { $1 is NSURL } .map { $0.0 } if fileKeys.count > 0 { manager.upload(multipartFormData: { mpForm in - for (k, v) in self.parameters! { + for (k, v) in param! { switch v { case let fileURL as URL: if let mimeType = self.contentTypeForFormPart(fileURL: fileURL) { diff --git a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift index ffcc81417d0..840c0e768d1 100644 --- a/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift +++ b/samples/client/petstore/swift3/unwraprequired/PetstoreClient/Classes/Swaggers/Models/EnumTest.swift @@ -17,11 +17,11 @@ open class EnumTest: JSONEncodable { } public enum EnumInteger: Int32 { case _1 = 1 - case numberminus1 = -1 + case number1 = -1 } public enum EnumNumber: Double { case _11 = 1.1 - case numberminus12 = -1.2 + case number12 = -1.2 } public var enumString: EnumString? public var enumInteger: EnumInteger?