mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-09 21:36:13 +00:00
Merge remote-tracking branch 'origin/master' into 6.0.x
This commit is contained in:
@@ -27,6 +27,7 @@ open class RequestBuilder<T> {
|
||||
public let parameters: [String: Any]?
|
||||
public let method: String
|
||||
public let URLString: String
|
||||
public let requestTask: RequestTask = RequestTask()
|
||||
|
||||
/// Optional block to obtain a reference to the request's progress instance when available.
|
||||
/// With the URLSession http client the request's progress only works on iOS 11.0, macOS 10.13, macCatalyst 13.0, tvOS 11.0, watchOS 4.0.
|
||||
@@ -49,8 +50,8 @@ open class RequestBuilder<T> {
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
open func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) -> URLSessionTask? {
|
||||
return nil
|
||||
open func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) -> RequestTask {
|
||||
return requestTask
|
||||
}
|
||||
|
||||
public func addHeader(name: String, value: String) -> Self {
|
||||
|
||||
@@ -36,6 +36,36 @@ extension CaseIterableDefaultsLast {
|
||||
}
|
||||
}
|
||||
|
||||
/// A flexible type that can be encoded (`.encodeNull` or `.encodeValue`)
|
||||
/// or not encoded (`.encodeNothing`). Intended for request payloads.
|
||||
public enum NullEncodable<Wrapped: Hashable>: Hashable {
|
||||
case encodeNothing
|
||||
case encodeNull
|
||||
case encodeValue(Wrapped)
|
||||
}
|
||||
|
||||
extension NullEncodable: Codable where Wrapped: Codable {
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
if let value = try? container.decode(Wrapped.self) {
|
||||
self = .encodeValue(value)
|
||||
} else if container.decodeNil() {
|
||||
self = .encodeNull
|
||||
} else {
|
||||
self = .encodeNothing
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
switch self {
|
||||
case .encodeNothing: return
|
||||
case .encodeNull: try container.encodeNil()
|
||||
case .encodeValue(let wrapped): try container.encode(wrapped)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum ErrorResponse: Error {
|
||||
case error(Int, Data?, URLResponse?, Error)
|
||||
}
|
||||
@@ -78,3 +108,16 @@ open class Response<T> {
|
||||
self.init(statusCode: response.statusCode, header: header, body: body)
|
||||
}
|
||||
}
|
||||
|
||||
public final class RequestTask {
|
||||
private var task: URLSessionTask?
|
||||
|
||||
internal func set(task: URLSessionTask) {
|
||||
self.task = task
|
||||
}
|
||||
|
||||
public func cancel() {
|
||||
task?.cancel()
|
||||
task = nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@ import AnyCodable
|
||||
public struct Name: Codable, Hashable {
|
||||
|
||||
public var name: Int
|
||||
public var snakeCase: Int?
|
||||
public var snakeCase: NullEncodable<Int> = .encodeValue(11033)
|
||||
public var property: String?
|
||||
public var _123number: Int?
|
||||
|
||||
public init(name: Int, snakeCase: Int? = nil, property: String? = nil, _123number: Int? = nil) {
|
||||
public init(name: Int, snakeCase: NullEncodable<Int> = .encodeValue(11033), property: String? = nil, _123number: Int? = nil) {
|
||||
self.name = name
|
||||
self.snakeCase = snakeCase
|
||||
self.property = property
|
||||
@@ -37,7 +37,10 @@ public struct Name: Codable, Hashable {
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(name, forKey: .name)
|
||||
try container.encodeIfPresent(snakeCase, forKey: .snakeCase)
|
||||
switch snakeCase {
|
||||
case .encodeNothing: break
|
||||
case .encodeNull, .encodeValue: try container.encode(snakeCase, forKey: .snakeCase)
|
||||
}
|
||||
try container.encodeIfPresent(property, forKey: .property)
|
||||
try container.encodeIfPresent(_123number, forKey: ._123number)
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ public struct Pet: Codable, Hashable {
|
||||
public var photoUrls: [String]
|
||||
public var tags: [Tag]?
|
||||
/** pet status in the store */
|
||||
public var status: Status?
|
||||
public var status: NullEncodable<Status>
|
||||
|
||||
public init(id: Int64? = nil, category: Category? = nil, name: String, photoUrls: [String], tags: [Tag]? = nil, status: Status? = nil) {
|
||||
public init(id: Int64? = nil, category: Category? = nil, name: String, photoUrls: [String], tags: [Tag]? = nil, status: NullEncodable<Status> = .encodeNull) {
|
||||
self.id = id
|
||||
self.category = category
|
||||
self.name = name
|
||||
@@ -52,7 +52,10 @@ public struct Pet: Codable, Hashable {
|
||||
try container.encode(name, forKey: .name)
|
||||
try container.encode(photoUrls, forKey: .photoUrls)
|
||||
try container.encodeIfPresent(tags, forKey: .tags)
|
||||
try container.encodeIfPresent(status, forKey: .status)
|
||||
switch status {
|
||||
case .encodeNothing: break
|
||||
case .encodeNull, .encodeValue: try container.encode(status, forKey: .status)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
override open func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) -> URLSessionTask? {
|
||||
override open func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) -> RequestTask {
|
||||
let urlSession = createURLSession()
|
||||
|
||||
guard let xMethod = HTTPMethod(rawValue: method) else {
|
||||
@@ -172,14 +172,14 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
|
||||
dataTask.resume()
|
||||
|
||||
return dataTask
|
||||
requestTask.set(task: dataTask)
|
||||
} catch {
|
||||
apiResponseQueue.async {
|
||||
completion(.failure(ErrorResponse.error(415, nil, nil, error)))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return requestTask
|
||||
}
|
||||
|
||||
fileprivate func processRequestResponse(urlRequest: URLRequest, data: Data?, response: URLResponse?, error: Error?, completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) {
|
||||
@@ -477,6 +477,15 @@ private class FormDataEncoding: ParameterEncoding {
|
||||
)
|
||||
}
|
||||
|
||||
case let data as Data:
|
||||
|
||||
urlRequest = configureDataUploadRequest(
|
||||
urlRequest: urlRequest,
|
||||
boundary: boundary,
|
||||
name: key,
|
||||
data: data
|
||||
)
|
||||
|
||||
default:
|
||||
fatalError("Unprocessable value \(value) with key \(key)")
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
"repositoryURL": "https://github.com/Flight-School/AnyCodable",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "876d162385e9862ae8b3c8d65dc301312b040005",
|
||||
"version": "0.6.0"
|
||||
"revision": "b1a7a8a6186f2fcb28f7bda67cfc545de48b3c80",
|
||||
"version": "0.6.2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "PromiseKit",
|
||||
"repositoryURL": "https://github.com/mxcl/PromiseKit.git",
|
||||
"repositoryURL": "https://github.com/mxcl/PromiseKit",
|
||||
"state": {
|
||||
"branch": null,
|
||||
"revision": "d2f7ba14bcdc45e18f4f60ad9df883fb9055f081",
|
||||
|
||||
@@ -27,9 +27,9 @@ class PetAPITests: XCTestCase {
|
||||
|
||||
func test1CreatePet() {
|
||||
let expectation = self.expectation(description: "testCreatePet")
|
||||
let category = PetstoreClient.Category(id: 1234, name: "eyeColor")
|
||||
let category = Category(id: 1234, name: "eyeColor")
|
||||
let tags = [Tag(id: 1234, name: "New York"), Tag(id: 124321, name: "Jose")]
|
||||
let newPet = Pet(id: 1000, category: category, name: "Fluffy", photoUrls: ["https://petstore.com/sample/photo1.jpg", "https://petstore.com/sample/photo2.jpg"], tags: tags, status: .available)
|
||||
let newPet = Pet(id: 1000, category: category, name: "Fluffy", photoUrls: ["https://petstore.com/sample/photo1.jpg", "https://petstore.com/sample/photo2.jpg"], tags: tags, status: .encodeValue(.available))
|
||||
|
||||
PetAPI.addPet(body: newPet).done {
|
||||
expectation.fulfill()
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
pod install
|
||||
|
||||
xcodebuild -workspace "SwaggerClient.xcworkspace" -scheme "SwaggerClient" test -destination "platform=iOS Simulator,name=iPhone 8,OS=latest" | xcpretty && exit ${PIPESTATUS[0]}
|
||||
xcodebuild clean build-for-testing -workspace "SwaggerClient.xcworkspace" -scheme "SwaggerClient" -destination "platform=iOS Simulator,name=iPhone 8,OS=latest" | xcpretty && exit ${PIPESTATUS[0]}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
Name | Type | Description | Notes
|
||||
------------ | ------------- | ------------- | -------------
|
||||
**name** | **Int** | |
|
||||
**snakeCase** | **Int** | | [optional] [readonly]
|
||||
**snakeCase** | **Int** | | [optional] [readonly] [default to .encodeValue(11033)]
|
||||
**property** | **String** | | [optional]
|
||||
**_123number** | **Int** | | [optional] [readonly]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user