Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
chore: update OpenAPIGenerator templates to v6.2.1
Browse files Browse the repository at this point in the history
There were some minor internal Swift updates in the new version which
would cause compiling issues when the command was run in the latest
version of the generator.
  • Loading branch information
CassiusPacheco committed Nov 10, 2022
1 parent dfd14c8 commit 27709a2
Show file tree
Hide file tree
Showing 24 changed files with 541 additions and 400 deletions.
4 changes: 3 additions & 1 deletion .openapi-generator/templates/swift5/APIs.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,19 @@ import Vapor
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let method: String
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let URLString: String
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let requestTask: RequestTask = RequestTask()
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let requiresAuthentication: Bool

/// Optional block to obtain a reference to the request's progress instance when available.{{#useURLSession}}
/// 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.
/// If you need to get the request's progress in older OS versions, please use Alamofire http client.{{/useURLSession}}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var onProgressReady: ((Progress) -> Void)?

required {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:]) {
required {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool) {
self.method = method
self.URLString = URLString
self.parameters = parameters
self.headers = headers
self.requiresAuthentication = requiresAuthentication
addHeaders({{projectName}}API.customHeaders)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ private var credentialStore = SynchronizedDictionary<Int, URLCredential>()
*/
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var taskCompletionShouldRetry: ((Data?, URLResponse?, Error?, @escaping (Bool) -> Void) -> Void)?

required {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:]) {
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers)
required {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool) {
super.init(method: method, URLString: URLString, parameters: parameters, headers: headers, requiresAuthentication: requiresAuthentication)
}

/**
Expand Down
6 changes: 4 additions & 2 deletions Sources/ImmutableXCore/Custom APIs/ExchangesAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class ExchangesAPI {
let requestBuilder = requestBuilderType.init(
method: "POST",
URLString: URLString,
parameters: parameters
parameters: parameters,
requiresAuthentication: false
)

return try await requestBuilder.execute()
Expand All @@ -75,7 +76,8 @@ class ExchangesAPI {
let requestBuilder = requestBuilderType.init(
method: "GET",
URLString: URLString,
parameters: nil
parameters: nil,
requiresAuthentication: false
)

let response = try await requestBuilder.execute()
Expand Down
3 changes: 2 additions & 1 deletion Sources/ImmutableXCore/Custom APIs/MoonpayAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class MoonpayAPI {
let requestBuilder = requestBuilderType.init(
method: "POST",
URLString: URLString,
parameters: parameters
parameters: parameters,
requiresAuthentication: false
)

let response = try await requestBuilder.execute()
Expand Down
36 changes: 36 additions & 0 deletions Sources/ImmutableXCore/Generated/APIHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,41 @@ internal struct APIHelper {
return source
}

/// maps all values from source to query parameters
///
/// explode attribute is respected: collection values might be either joined or split up into seperate key value pairs
internal static func mapValuesToQueryItems(_ source: [String: (wrappedValue: Any?, isExplode: Bool)]) -> [URLQueryItem]? {
let destination = source.filter { $0.value.wrappedValue != nil }.reduce(into: [URLQueryItem]()) { result, item in
if let collection = item.value.wrappedValue as? [Any?] {

let collectionValues: [String] = collection.compactMap { value in
guard let value = value else { return nil }
return "\(value)"
}

if !item.value.isExplode {
result.append(URLQueryItem(name: item.key, value: collectionValues.joined(separator: ",")))
} else {
collectionValues
.forEach { value in
result.append(URLQueryItem(name: item.key, value: value))
}
}

} else if let value = item.value.wrappedValue {
result.append(URLQueryItem(name: item.key, value: "\(value)"))
}
}

if destination.isEmpty {
return nil
}
return destination
}

/// maps all values from source to query parameters
///
/// collection values are always exploded
internal static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? {
let destination = source.filter { $0.value != nil }.reduce(into: [URLQueryItem]()) { result, item in
if let collection = item.value as? [Any?] {
Expand All @@ -73,6 +108,7 @@ internal struct APIHelper {
.forEach { value in
result.append(URLQueryItem(name: item.key, value: value))
}

} else if let value = item.value {
result.append(URLQueryItem(name: item.key, value: "\(value)"))
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/ImmutableXCore/Generated/APIs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ internal class RequestBuilder<T> {
internal let method: String
internal let URLString: String
internal let requestTask: RequestTask = RequestTask()
internal let requiresAuthentication: Bool

/// 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.
/// If you need to get the request's progress in older OS versions, please use Alamofire http client.
internal var onProgressReady: ((Progress) -> Void)?

required internal init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:]) {
required internal init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool) {
self.method = method
self.URLString = URLString
self.parameters = parameters
self.headers = headers
self.requiresAuthentication = requiresAuthentication

addHeaders(OpenAPIClientAPI.customHeaders)
}
Expand Down
56 changes: 29 additions & 27 deletions Sources/ImmutableXCore/Generated/APIs/AssetsAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ internal class AssetsAPI {
*/
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
internal class func getAsset(tokenAddress: String, tokenId: String, includeFees: Bool? = nil) async throws -> Asset {
var requestTask: RequestTask?
let requestBuilder = getAssetWithRequestBuilder(tokenAddress: tokenAddress, tokenId: tokenId, includeFees: includeFees)
let requestTask = requestBuilder.requestTask
return try await withTaskCancellationHandler {
try Task.checkCancellation()
return try await withCheckedThrowingContinuation { continuation in
Expand All @@ -31,7 +32,7 @@ internal class AssetsAPI {
return
}

requestTask = getAssetWithRequestBuilder(tokenAddress: tokenAddress, tokenId: tokenId, includeFees: includeFees).execute { result in
requestBuilder.execute { result in
switch result {
case let .success(response):
continuation.resume(returning: response.body)
Expand All @@ -40,8 +41,8 @@ internal class AssetsAPI {
}
}
}
} onCancel: { [requestTask] in
requestTask?.cancel()
} onCancel: {
requestTask.cancel()
}
}

Expand All @@ -67,7 +68,7 @@ internal class AssetsAPI {

var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"include_fees": includeFees?.encodeToJSON(),
"include_fees": (wrappedValue: includeFees?.encodeToJSON(), isExplode: false),
])

let localVariableNillableHeaders: [String: Any?] = [
Expand All @@ -78,7 +79,7 @@ internal class AssetsAPI {

let localVariableRequestBuilder: RequestBuilder<Asset>.Type = OpenAPIClientAPI.requestBuilderFactory.getBuilder()

return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: false)
}

/**
Expand Down Expand Up @@ -112,7 +113,8 @@ internal class AssetsAPI {
*/
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
internal class func listAssets(pageSize: Int? = nil, cursor: String? = nil, orderBy: OrderBy_listAssets? = nil, direction: String? = nil, user: String? = nil, status: String? = nil, name: String? = nil, metadata: String? = nil, sellOrders: Bool? = nil, buyOrders: Bool? = nil, includeFees: Bool? = nil, collection: String? = nil, updatedMinTimestamp: String? = nil, updatedMaxTimestamp: String? = nil, auxiliaryFeePercentages: String? = nil, auxiliaryFeeRecipients: String? = nil) async throws -> ListAssetsResponse {
var requestTask: RequestTask?
let requestBuilder = listAssetsWithRequestBuilder(pageSize: pageSize, cursor: cursor, orderBy: orderBy, direction: direction, user: user, status: status, name: name, metadata: metadata, sellOrders: sellOrders, buyOrders: buyOrders, includeFees: includeFees, collection: collection, updatedMinTimestamp: updatedMinTimestamp, updatedMaxTimestamp: updatedMaxTimestamp, auxiliaryFeePercentages: auxiliaryFeePercentages, auxiliaryFeeRecipients: auxiliaryFeeRecipients)
let requestTask = requestBuilder.requestTask
return try await withTaskCancellationHandler {
try Task.checkCancellation()
return try await withCheckedThrowingContinuation { continuation in
Expand All @@ -121,7 +123,7 @@ internal class AssetsAPI {
return
}

requestTask = listAssetsWithRequestBuilder(pageSize: pageSize, cursor: cursor, orderBy: orderBy, direction: direction, user: user, status: status, name: name, metadata: metadata, sellOrders: sellOrders, buyOrders: buyOrders, includeFees: includeFees, collection: collection, updatedMinTimestamp: updatedMinTimestamp, updatedMaxTimestamp: updatedMaxTimestamp, auxiliaryFeePercentages: auxiliaryFeePercentages, auxiliaryFeeRecipients: auxiliaryFeeRecipients).execute { result in
requestBuilder.execute { result in
switch result {
case let .success(response):
continuation.resume(returning: response.body)
Expand All @@ -130,8 +132,8 @@ internal class AssetsAPI {
}
}
}
} onCancel: { [requestTask] in
requestTask?.cancel()
} onCancel: {
requestTask.cancel()
}
}

Expand Down Expand Up @@ -164,22 +166,22 @@ internal class AssetsAPI {

var localVariableUrlComponents = URLComponents(string: localVariableURLString)
localVariableUrlComponents?.queryItems = APIHelper.mapValuesToQueryItems([
"page_size": pageSize?.encodeToJSON(),
"cursor": cursor?.encodeToJSON(),
"order_by": orderBy?.encodeToJSON(),
"direction": direction?.encodeToJSON(),
"user": user?.encodeToJSON(),
"status": status?.encodeToJSON(),
"name": name?.encodeToJSON(),
"metadata": metadata?.encodeToJSON(),
"sell_orders": sellOrders?.encodeToJSON(),
"buy_orders": buyOrders?.encodeToJSON(),
"include_fees": includeFees?.encodeToJSON(),
"collection": collection?.encodeToJSON(),
"updated_min_timestamp": updatedMinTimestamp?.encodeToJSON(),
"updated_max_timestamp": updatedMaxTimestamp?.encodeToJSON(),
"auxiliary_fee_percentages": auxiliaryFeePercentages?.encodeToJSON(),
"auxiliary_fee_recipients": auxiliaryFeeRecipients?.encodeToJSON(),
"page_size": (wrappedValue: pageSize?.encodeToJSON(), isExplode: false),
"cursor": (wrappedValue: cursor?.encodeToJSON(), isExplode: false),
"order_by": (wrappedValue: orderBy?.encodeToJSON(), isExplode: false),
"direction": (wrappedValue: direction?.encodeToJSON(), isExplode: false),
"user": (wrappedValue: user?.encodeToJSON(), isExplode: false),
"status": (wrappedValue: status?.encodeToJSON(), isExplode: false),
"name": (wrappedValue: name?.encodeToJSON(), isExplode: false),
"metadata": (wrappedValue: metadata?.encodeToJSON(), isExplode: false),
"sell_orders": (wrappedValue: sellOrders?.encodeToJSON(), isExplode: false),
"buy_orders": (wrappedValue: buyOrders?.encodeToJSON(), isExplode: false),
"include_fees": (wrappedValue: includeFees?.encodeToJSON(), isExplode: false),
"collection": (wrappedValue: collection?.encodeToJSON(), isExplode: false),
"updated_min_timestamp": (wrappedValue: updatedMinTimestamp?.encodeToJSON(), isExplode: false),
"updated_max_timestamp": (wrappedValue: updatedMaxTimestamp?.encodeToJSON(), isExplode: false),
"auxiliary_fee_percentages": (wrappedValue: auxiliaryFeePercentages?.encodeToJSON(), isExplode: false),
"auxiliary_fee_recipients": (wrappedValue: auxiliaryFeeRecipients?.encodeToJSON(), isExplode: false),
])

let localVariableNillableHeaders: [String: Any?] = [
Expand All @@ -190,6 +192,6 @@ internal class AssetsAPI {

let localVariableRequestBuilder: RequestBuilder<ListAssetsResponse>.Type = OpenAPIClientAPI.requestBuilderFactory.getBuilder()

return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: false)
}
}
22 changes: 12 additions & 10 deletions Sources/ImmutableXCore/Generated/APIs/BalancesAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ internal class BalancesAPI {
*/
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
internal class func getBalance(owner: String, address: String) async throws -> Balance {
var requestTask: RequestTask?
let requestBuilder = getBalanceWithRequestBuilder(owner: owner, address: address)
let requestTask = requestBuilder.requestTask
return try await withTaskCancellationHandler {
try Task.checkCancellation()
return try await withCheckedThrowingContinuation { continuation in
Expand All @@ -30,7 +31,7 @@ internal class BalancesAPI {
return
}

requestTask = getBalanceWithRequestBuilder(owner: owner, address: address).execute { result in
requestBuilder.execute { result in
switch result {
case let .success(response):
continuation.resume(returning: response.body)
Expand All @@ -39,8 +40,8 @@ internal class BalancesAPI {
}
}
}
} onCancel: { [requestTask] in
requestTask?.cancel()
} onCancel: {
requestTask.cancel()
}
}

Expand Down Expand Up @@ -73,7 +74,7 @@ internal class BalancesAPI {

let localVariableRequestBuilder: RequestBuilder<Balance>.Type = OpenAPIClientAPI.requestBuilderFactory.getBuilder()

return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: false)
}

/**
Expand All @@ -84,7 +85,8 @@ internal class BalancesAPI {
*/
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
internal class func listBalances(owner: String) async throws -> ListBalancesResponse {
var requestTask: RequestTask?
let requestBuilder = listBalancesWithRequestBuilder(owner: owner)
let requestTask = requestBuilder.requestTask
return try await withTaskCancellationHandler {
try Task.checkCancellation()
return try await withCheckedThrowingContinuation { continuation in
Expand All @@ -93,7 +95,7 @@ internal class BalancesAPI {
return
}

requestTask = listBalancesWithRequestBuilder(owner: owner).execute { result in
requestBuilder.execute { result in
switch result {
case let .success(response):
continuation.resume(returning: response.body)
Expand All @@ -102,8 +104,8 @@ internal class BalancesAPI {
}
}
}
} onCancel: { [requestTask] in
requestTask?.cancel()
} onCancel: {
requestTask.cancel()
}
}

Expand Down Expand Up @@ -132,6 +134,6 @@ internal class BalancesAPI {

let localVariableRequestBuilder: RequestBuilder<ListBalancesResponse>.Type = OpenAPIClientAPI.requestBuilderFactory.getBuilder()

return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters)
return localVariableRequestBuilder.init(method: "GET", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: false)
}
}
Loading

0 comments on commit 27709a2

Please sign in to comment.