forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 5.4.x
This commit is contained in:
@@ -48,7 +48,10 @@ open class RequestBuilder<T> {
|
||||
}
|
||||
}
|
||||
|
||||
open func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) { }
|
||||
@discardableResult
|
||||
open func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) -> URLSessionTask? {
|
||||
return nil
|
||||
}
|
||||
|
||||
public func addHeader(name: String, value: String) -> Self {
|
||||
if !value.isEmpty {
|
||||
|
||||
@@ -21,15 +21,26 @@ open class AnotherFakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func call123testSpecialTags(body: Client, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> Client {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
call123testSpecialTagsWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = call123testSpecialTagsWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,15 +20,26 @@ open class FakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func fakeOuterBooleanSerialize(body: Bool? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> Bool {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
fakeOuterBooleanSerializeWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = fakeOuterBooleanSerializeWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,15 +75,26 @@ open class FakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func fakeOuterCompositeSerialize(body: OuterComposite? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> OuterComposite {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
fakeOuterCompositeSerializeWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = fakeOuterCompositeSerializeWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,15 +130,26 @@ open class FakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func fakeOuterNumberSerialize(body: Double? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> Double {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
fakeOuterNumberSerializeWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = fakeOuterNumberSerializeWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,15 +185,26 @@ open class FakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func fakeOuterStringSerialize(body: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> String {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
fakeOuterStringSerializeWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = fakeOuterStringSerializeWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,15 +240,26 @@ open class FakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func testBodyWithFileSchema(body: FileSchemaTestClass, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
testBodyWithFileSchemaWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = testBodyWithFileSchemaWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,15 +296,26 @@ open class FakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func testBodyWithQueryParams(query: String, body: User, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
testBodyWithQueryParamsWithRequestBuilder(query: query, body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = testBodyWithQueryParamsWithRequestBuilder(query: query, body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,15 +355,26 @@ open class FakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func testClientModel(body: Client, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> Client {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
testClientModelWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = testClientModelWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -348,15 +425,26 @@ open class FakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func testEndpointParameters(number: Double, double: Double, patternWithoutDelimiter: String, byte: Data, integer: Int? = nil, int32: Int? = nil, int64: Int64? = nil, float: Float? = nil, string: String? = nil, binary: URL? = nil, date: Date? = nil, dateTime: Date? = nil, password: String? = nil, callback: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = testEndpointParametersWithRequestBuilder(number: number, double: double, patternWithoutDelimiter: patternWithoutDelimiter, byte: byte, integer: integer, int32: int32, int64: int64, float: float, string: string, binary: binary, date: date, dateTime: dateTime, password: password, callback: callback).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,15 +590,26 @@ open class FakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func testEnumParameters(enumHeaderStringArray: [String]? = nil, enumHeaderString: EnumHeaderString_testEnumParameters? = nil, enumQueryStringArray: [String]? = nil, enumQueryString: EnumQueryString_testEnumParameters? = nil, enumQueryInteger: EnumQueryInteger_testEnumParameters? = nil, enumQueryDouble: EnumQueryDouble_testEnumParameters? = nil, enumFormStringArray: [String]? = nil, enumFormString: EnumFormString_testEnumParameters? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
testEnumParametersWithRequestBuilder(enumHeaderStringArray: enumHeaderStringArray, enumHeaderString: enumHeaderString, enumQueryStringArray: enumQueryStringArray, enumQueryString: enumQueryString, enumQueryInteger: enumQueryInteger, enumQueryDouble: enumQueryDouble, enumFormStringArray: enumFormStringArray, enumFormString: enumFormString).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = testEnumParametersWithRequestBuilder(enumHeaderStringArray: enumHeaderStringArray, enumHeaderString: enumHeaderString, enumQueryStringArray: enumQueryStringArray, enumQueryString: enumQueryString, enumQueryInteger: enumQueryInteger, enumQueryDouble: enumQueryDouble, enumFormStringArray: enumFormStringArray, enumFormString: enumFormString).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,15 +673,26 @@ open class FakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func testGroupParameters(requiredStringGroup: Int, requiredBooleanGroup: Bool, requiredInt64Group: Int64, stringGroup: Int? = nil, booleanGroup: Bool? = nil, int64Group: Int64? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
testGroupParametersWithRequestBuilder(requiredStringGroup: requiredStringGroup, requiredBooleanGroup: requiredBooleanGroup, requiredInt64Group: requiredInt64Group, stringGroup: stringGroup, booleanGroup: booleanGroup, int64Group: int64Group).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = testGroupParametersWithRequestBuilder(requiredStringGroup: requiredStringGroup, requiredBooleanGroup: requiredBooleanGroup, requiredInt64Group: requiredInt64Group, stringGroup: stringGroup, booleanGroup: booleanGroup, int64Group: int64Group).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -632,15 +742,26 @@ open class FakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func testInlineAdditionalProperties(param: [String: String], apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
testInlineAdditionalPropertiesWithRequestBuilder(param: param).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = testInlineAdditionalPropertiesWithRequestBuilder(param: param).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -678,15 +799,26 @@ open class FakeAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func testJsonFormData(param: String, param2: String, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
testJsonFormDataWithRequestBuilder(param: param, param2: param2).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = testJsonFormDataWithRequestBuilder(param: param, param2: param2).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,15 +21,26 @@ open class FakeClassnameTags123API {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func testClassname(body: Client, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> Client {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
testClassnameWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = testClassnameWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,15 +21,26 @@ open class PetAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func addPet(body: Pet, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
addPetWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = addPetWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,15 +81,26 @@ open class PetAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func deletePet(petId: Int64, apiKey: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
deletePetWithRequestBuilder(petId: petId, apiKey: apiKey).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = deletePetWithRequestBuilder(petId: petId, apiKey: apiKey).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,15 +153,26 @@ open class PetAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func findPetsByStatus(status: [String], apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> [Pet] {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
findPetsByStatusWithRequestBuilder(status: status).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = findPetsByStatusWithRequestBuilder(status: status).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,15 +217,26 @@ open class PetAPI {
|
||||
@available(*, deprecated, message: "This operation is deprecated.")
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func findPetsByTags(tags: [String], apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> [Pet] {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
findPetsByTagsWithRequestBuilder(tags: tags).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = findPetsByTagsWithRequestBuilder(tags: tags).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,15 +281,26 @@ open class PetAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func getPetById(petId: Int64, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> Pet {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
getPetByIdWithRequestBuilder(petId: petId).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = getPetByIdWithRequestBuilder(petId: petId).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,15 +344,26 @@ open class PetAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func updatePet(body: Pet, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
updatePetWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = updatePetWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,15 +405,26 @@ open class PetAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func updatePetWithForm(petId: Int64, name: String? = nil, status: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
updatePetWithFormWithRequestBuilder(petId: petId, name: name, status: status).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = updatePetWithFormWithRequestBuilder(petId: petId, name: name, status: status).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,15 +477,26 @@ open class PetAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func uploadFile(petId: Int64, additionalMetadata: String? = nil, file: URL? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> ApiResponse {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
uploadFileWithRequestBuilder(petId: petId, additionalMetadata: additionalMetadata, file: file).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = uploadFileWithRequestBuilder(petId: petId, additionalMetadata: additionalMetadata, file: file).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,15 +549,26 @@ open class PetAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func uploadFileWithRequiredFile(petId: Int64, requiredFile: URL, additionalMetadata: String? = nil, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> ApiResponse {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
uploadFileWithRequiredFileWithRequestBuilder(petId: petId, requiredFile: requiredFile, additionalMetadata: additionalMetadata).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = uploadFileWithRequiredFileWithRequestBuilder(petId: petId, requiredFile: requiredFile, additionalMetadata: additionalMetadata).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,15 +21,26 @@ open class StoreAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func deleteOrder(orderId: String, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
deleteOrderWithRequestBuilder(orderId: orderId).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = deleteOrderWithRequestBuilder(orderId: orderId).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,15 +80,26 @@ open class StoreAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func getInventory(apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> [String: Int] {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
getInventoryWithRequestBuilder().execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = getInventoryWithRequestBuilder().execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,15 +139,26 @@ open class StoreAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func getOrderById(orderId: Int64, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> Order {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
getOrderByIdWithRequestBuilder(orderId: orderId).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = getOrderByIdWithRequestBuilder(orderId: orderId).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,15 +199,26 @@ open class StoreAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func placeOrder(body: Order, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> Order {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
placeOrderWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = placeOrderWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,15 +21,26 @@ open class UserAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func createUser(body: User, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
createUserWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = createUserWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,15 +78,26 @@ open class UserAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func createUsersWithArrayInput(body: [User], apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
createUsersWithArrayInputWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = createUsersWithArrayInputWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,15 +134,26 @@ open class UserAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func createUsersWithListInput(body: [User], apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
createUsersWithListInputWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = createUsersWithListInputWithRequestBuilder(body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,15 +190,26 @@ open class UserAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func deleteUser(username: String, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
deleteUserWithRequestBuilder(username: username).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = deleteUserWithRequestBuilder(username: username).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,15 +250,26 @@ open class UserAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func getUserByName(username: String, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> User {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
getUserByNameWithRequestBuilder(username: username).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = getUserByNameWithRequestBuilder(username: username).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,15 +310,26 @@ open class UserAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func loginUser(username: String, password: String, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws -> String {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
loginUserWithRequestBuilder(username: username, password: password).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = loginUserWithRequestBuilder(username: username, password: password).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
continuation.resume(returning: response.body!)
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,15 +371,26 @@ open class UserAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func logoutUser(apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
logoutUserWithRequestBuilder().execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = logoutUserWithRequestBuilder().execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,15 +427,26 @@ open class UserAPI {
|
||||
*/
|
||||
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
|
||||
open class func updateUser(username: String, body: User, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue) async throws {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
updateUserWithRequestBuilder(username: username, body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
var task: URLSessionTask?
|
||||
return try await withTaskCancellationHandler {
|
||||
try Task.checkCancellation()
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
guard !Task.isCancelled else {
|
||||
continuation.resume(throwing: CancellationError())
|
||||
return
|
||||
}
|
||||
|
||||
task = updateUserWithRequestBuilder(username: username, body: body).execute(apiResponseQueue) { result in
|
||||
switch result {
|
||||
case .success:
|
||||
continuation.resume(returning: ())
|
||||
case let .failure(error):
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
} onCancel: { [task] in
|
||||
task?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,15 +19,26 @@ class URLSessionRequestBuilderFactory: RequestBuilderFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public typealias PetstoreClientAPIChallengeHandler = ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))
|
||||
|
||||
// Store the URLSession's delegate to retain its reference
|
||||
private let sessionDelegate = SessionDelegate()
|
||||
|
||||
// Store the URLSession to retain its reference
|
||||
private var urlSessionStore = SynchronizedDictionary<String, URLSession>()
|
||||
private let defaultURLSession = URLSession(configuration: .default, delegate: sessionDelegate, delegateQueue: nil)
|
||||
|
||||
// Store current taskDidReceiveChallenge for every URLSessionTask
|
||||
private var challengeHandlerStore = SynchronizedDictionary<Int, PetstoreClientAPIChallengeHandler>()
|
||||
|
||||
// Store current URLCredential for every URLSessionTask
|
||||
private var credentialStore = SynchronizedDictionary<Int, URLCredential>()
|
||||
|
||||
open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
|
||||
/**
|
||||
May be assigned if you want to control the authentication challenges.
|
||||
*/
|
||||
public var taskDidReceiveChallenge: ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))?
|
||||
public var taskDidReceiveChallenge: PetstoreClientAPIChallengeHandler?
|
||||
|
||||
/**
|
||||
May be assigned if you want to do any of those things:
|
||||
@@ -47,12 +58,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
configuration.
|
||||
*/
|
||||
open func createURLSession() -> URLSession {
|
||||
let configuration = URLSessionConfiguration.default
|
||||
configuration.httpAdditionalHeaders = buildHeaders()
|
||||
let sessionDelegate = SessionDelegate()
|
||||
sessionDelegate.credential = credential
|
||||
sessionDelegate.taskDidReceiveChallenge = taskDidReceiveChallenge
|
||||
return URLSession(configuration: configuration, delegate: sessionDelegate, delegateQueue: nil)
|
||||
return defaultURLSession
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,11 +99,9 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
return modifiedRequest
|
||||
}
|
||||
|
||||
override open func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) {
|
||||
let urlSessionId = UUID().uuidString
|
||||
// Create a new manager for each request to customize its request header
|
||||
@discardableResult
|
||||
override open func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) -> URLSessionTask? {
|
||||
let urlSession = createURLSession()
|
||||
urlSessionStore[urlSessionId] = urlSession
|
||||
|
||||
guard let xMethod = HTTPMethod(rawValue: method) else {
|
||||
fatalError("Unsupported Http method - \(method)")
|
||||
@@ -123,14 +127,17 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
}
|
||||
}
|
||||
|
||||
let cleanupRequest = {
|
||||
urlSessionStore[urlSessionId]?.finishTasksAndInvalidate()
|
||||
urlSessionStore[urlSessionId] = nil
|
||||
}
|
||||
|
||||
do {
|
||||
let request = try createURLRequest(urlSession: urlSession, method: xMethod, encoding: encoding, headers: headers)
|
||||
|
||||
var taskIdentifier: Int?
|
||||
let cleanupRequest = {
|
||||
if let taskIdentifier = taskIdentifier {
|
||||
challengeHandlerStore[taskIdentifier] = nil
|
||||
credentialStore[taskIdentifier] = nil
|
||||
}
|
||||
}
|
||||
|
||||
let dataTask = urlSession.dataTask(with: request) { data, response, error in
|
||||
|
||||
if let taskCompletionShouldRetry = self.taskCompletionShouldRetry {
|
||||
@@ -159,13 +166,19 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
|
||||
onProgressReady?(dataTask.progress)
|
||||
}
|
||||
|
||||
taskIdentifier = dataTask.taskIdentifier
|
||||
challengeHandlerStore[dataTask.taskIdentifier] = taskDidReceiveChallenge
|
||||
credentialStore[dataTask.taskIdentifier] = credential
|
||||
|
||||
dataTask.resume()
|
||||
|
||||
return dataTask
|
||||
} catch {
|
||||
apiResponseQueue.async {
|
||||
cleanupRequest()
|
||||
completion(.failure(ErrorResponse.error(415, nil, nil, error)))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,25 +411,20 @@ open class URLSessionDecodableRequestBuilder<T: Decodable>: URLSessionRequestBui
|
||||
}
|
||||
}
|
||||
|
||||
private class SessionDelegate: NSObject, URLSessionDelegate, URLSessionDataDelegate {
|
||||
|
||||
var credential: URLCredential?
|
||||
|
||||
var taskDidReceiveChallenge: ((URLSession, URLSessionTask, URLAuthenticationChallenge) -> (URLSession.AuthChallengeDisposition, URLCredential?))?
|
||||
|
||||
private class SessionDelegate: NSObject, URLSessionTaskDelegate {
|
||||
func urlSession(_ session: URLSession, task: URLSessionTask, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
|
||||
|
||||
var disposition: URLSession.AuthChallengeDisposition = .performDefaultHandling
|
||||
|
||||
var credential: URLCredential?
|
||||
|
||||
if let taskDidReceiveChallenge = taskDidReceiveChallenge {
|
||||
if let taskDidReceiveChallenge = challengeHandlerStore[task.taskIdentifier] {
|
||||
(disposition, credential) = taskDidReceiveChallenge(session, task, challenge)
|
||||
} else {
|
||||
if challenge.previousFailureCount > 0 {
|
||||
disposition = .rejectProtectionSpace
|
||||
} else {
|
||||
credential = self.credential ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)
|
||||
credential = credentialStore[task.taskIdentifier] ?? session.configuration.urlCredentialStorage?.defaultCredential(for: challenge.protectionSpace)
|
||||
|
||||
if credential != nil {
|
||||
disposition = .useCredential
|
||||
|
||||
Reference in New Issue
Block a user