forked from loafle/openapi-generator-original
[Swift4]Update templates for swift 4 (#6921)
* update versions of dependencies on swift4 and swift3 * change syntax for swift4 * run petstore script * change enum case from UpperCamel to lowerCamel * remove unneeded break statements * avoid wrapping conditionals in parentheses * avoid force casting * run pod update on petstore/swift4/rxswift * update project for swift 4 * run swift4-petstore-all.sh * fix compile error * avoid use iso8601 date strategy for encoder / decoder * resolve file references
This commit is contained in:
committed by
William Cheng
parent
b06ccec11e
commit
a5e4abe5ec
@@ -1 +1 @@
|
||||
github "Alamofire/Alamofire" >= 3.1.0
|
||||
github "Alamofire/Alamofire" ~> 4.5
|
||||
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// AnotherfakeAPI.swift
|
||||
// AnotherFakeAPI.swift
|
||||
//
|
||||
// Generated by swagger-codegen
|
||||
// https://github.com/swagger-api/swagger-codegen
|
||||
@@ -9,7 +9,7 @@ import Foundation
|
||||
import Alamofire
|
||||
|
||||
|
||||
open class AnotherfakeAPI: APIBase {
|
||||
open class AnotherFakeAPI: APIBase {
|
||||
/**
|
||||
To test special tags
|
||||
- parameter body: (body) client model
|
||||
|
||||
@@ -381,6 +381,38 @@ open class FakeAPI: APIBase {
|
||||
return requestBuilder.init(method: "GET", URLString: (url?.string ?? URLString), parameters: parameters, isBody: false, headers: headerParameters)
|
||||
}
|
||||
|
||||
/**
|
||||
test inline additionalProperties
|
||||
- parameter param: (body) request body
|
||||
- parameter completion: completion handler to receive the data and the error objects
|
||||
*/
|
||||
open class func testInlineAdditionalProperties(param: Any, completion: @escaping ((_ error: ErrorResponse?) -> Void)) {
|
||||
testInlineAdditionalPropertiesWithRequestBuilder(param: param).execute { (response, error) -> Void in
|
||||
completion(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
test inline additionalProperties
|
||||
- POST /fake/inline-additionalProperties
|
||||
-
|
||||
|
||||
- parameter param: (body) request body
|
||||
- returns: RequestBuilder<Void>
|
||||
*/
|
||||
open class func testInlineAdditionalPropertiesWithRequestBuilder(param: Any) -> RequestBuilder<Void> {
|
||||
let path = "/fake/inline-additionalProperties"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = param.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Void>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "POST", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
/**
|
||||
test json serialization of form data
|
||||
- parameter param: (form) field1
|
||||
|
||||
@@ -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<Client>
|
||||
*/
|
||||
open class func testClassnameWithRequestBuilder(body: Client) -> RequestBuilder<Client> {
|
||||
let path = "/fake_classname_test"
|
||||
let URLString = PetstoreClientAPI.basePath + path
|
||||
let parameters = body.encodeToJSON()
|
||||
|
||||
let url = NSURLComponents(string: URLString)
|
||||
|
||||
let requestBuilder: RequestBuilder<Client>.Type = PetstoreClientAPI.requestBuilderFactory.getBuilder()
|
||||
|
||||
return requestBuilder.init(method: "PATCH", URLString: (url?.string ?? URLString), parameters: parameters, isBody: true)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -118,16 +118,12 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
||||
else {
|
||||
mpForm.append(fileURL, withName: k)
|
||||
}
|
||||
break
|
||||
case let string as String:
|
||||
mpForm.append(string.data(using: String.Encoding.utf8)!, withName: k)
|
||||
break
|
||||
case let number as NSNumber:
|
||||
mpForm.append(number.stringValue.data(using: String.Encoding.utf8)!, withName: k)
|
||||
break
|
||||
default:
|
||||
fatalError("Unprocessable value \(v) with key \(k)")
|
||||
break
|
||||
}
|
||||
}
|
||||
}, to: URLString, method: xMethod!, headers: nil, encodingCompletion: { encodingResult in
|
||||
@@ -206,7 +202,7 @@ open class AlamofireRequestBuilder<T>: RequestBuilder<T> {
|
||||
validatedRequest.responseData(completionHandler: { (dataResponse) in
|
||||
cleanupRequest()
|
||||
|
||||
if (dataResponse.result.isFailure) {
|
||||
if dataResponse.result.isFailure {
|
||||
completion(
|
||||
nil,
|
||||
ErrorResponse.HttpError(statusCode: dataResponse.response?.statusCode ?? 500, data: dataResponse.data, error: dataResponse.result.error!)
|
||||
|
||||
@@ -53,7 +53,7 @@ extension Dictionary: JSONEncodable {
|
||||
func encodeToJSON() -> Any {
|
||||
var dictionary = [AnyHashable: Any]()
|
||||
for (key, value) in self {
|
||||
dictionary[key as! NSObject] = encodeIfPossible(value)
|
||||
dictionary[key] = encodeIfPossible(value)
|
||||
}
|
||||
return dictionary as Any
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ open class Response<T> {
|
||||
public convenience init(response: HTTPURLResponse, body: T?) {
|
||||
let rawHeader = response.allHeaderFields
|
||||
var header = [String:String]()
|
||||
for (key, value) in rawHeader {
|
||||
header[key as! String] = value as? String
|
||||
for case let (key, value) as (String, String) in rawHeader {
|
||||
header[key] = value
|
||||
}
|
||||
self.init(statusCode: response.statusCode, header: header, body: body)
|
||||
}
|
||||
|
||||
@@ -29,11 +29,6 @@ open class FormatTest: JSONEncodable {
|
||||
}
|
||||
}
|
||||
public var number: Double?
|
||||
public var numberNum: NSNumber? {
|
||||
get {
|
||||
return number.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
public var float: Float?
|
||||
public var floatNum: NSNumber? {
|
||||
get {
|
||||
|
||||
@@ -11,11 +11,6 @@ import Foundation
|
||||
open class NumberOnly: JSONEncodable {
|
||||
|
||||
public var justNumber: Double?
|
||||
public var justNumberNum: NSNumber? {
|
||||
get {
|
||||
return justNumber.map({ return NSNumber(value: $0) })
|
||||
}
|
||||
}
|
||||
|
||||
public init() {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user