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

Commit

Permalink
feat!: make clients internal by using nonPublicApi
Browse files Browse the repository at this point in the history
When using the 'nonPublicApi' flag in OpenAPI generator, all clients
are made internal by default. This aims to keep the interface
consistent, allowing us to expose only the method we see fit through
ImmutableX instead of relying on devs using the clients directly.
  • Loading branch information
CassiusPacheco committed Nov 8, 2022
1 parent 890545d commit c0c278d
Show file tree
Hide file tree
Showing 26 changed files with 190 additions and 185 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ for soon-to-be removed features.

### Removed

for now removed features.
- (Breaking): all clients have been removed in favour of direct methods in the ImmutableX instance.

### Fixed

Expand Down
12 changes: 6 additions & 6 deletions Sources/ImmutableXCore/Generated/APIHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import Foundation

public struct APIHelper {
public static func rejectNil(_ source: [String: Any?]) -> [String: Any]? {
internal struct APIHelper {
internal static func rejectNil(_ source: [String: Any?]) -> [String: Any]? {
let destination = source.reduce(into: [String: Any]()) { result, item in
if let value = item.value {
result[item.key] = value
Expand All @@ -20,7 +20,7 @@ public struct APIHelper {
return destination
}

public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] {
internal static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] {
return source.reduce(into: [String: String]()) { result, item in
if let collection = item.value as? [Any?] {
result[item.key] = collection
Expand All @@ -35,7 +35,7 @@ public struct APIHelper {
}
}

public static func convertBoolToString(_ source: [String: Any]?) -> [String: Any]? {
internal static func convertBoolToString(_ source: [String: Any]?) -> [String: Any]? {
guard let source = source else {
return nil
}
Expand All @@ -50,7 +50,7 @@ public struct APIHelper {
}
}

public static func mapValueToPathItem(_ source: Any) -> Any {
internal static func mapValueToPathItem(_ source: Any) -> Any {
if let collection = source as? [Any?] {
return collection
.compactMap { value in
Expand All @@ -62,7 +62,7 @@ public struct APIHelper {
return source
}

public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? {
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?] {
collection
Expand Down
38 changes: 19 additions & 19 deletions Sources/ImmutableXCore/Generated/APIs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,33 @@ import Foundation
// If you are affected by this issue, please consider removing the following two lines,
// By setting the option removeMigrationProjectNameClass to true in the generator
@available(*, deprecated, renamed: "OpenAPIClientAPI")
public typealias OpenAPIClient = OpenAPIClientAPI
internal typealias OpenAPIClient = OpenAPIClientAPI

open class OpenAPIClientAPI {
public static var customHeaders: [String: String] = ["x-sdk-version": "imx-core-sdk-swift-\(ImmutableX.shared.sdkVersion)"]
public static var credential: URLCredential?
public static var requestBuilderFactory: RequestBuilderFactory = URLSessionRequestBuilderFactory()
public static var apiResponseQueue: DispatchQueue = .main
internal class OpenAPIClientAPI {
internal static var customHeaders: [String: String] = ["x-sdk-version": "imx-core-sdk-swift-\(ImmutableX.shared.sdkVersion)"]
internal static var credential: URLCredential?
internal static var requestBuilderFactory: RequestBuilderFactory = URLSessionRequestBuilderFactory()
internal static var apiResponseQueue: DispatchQueue = .main

public static var basePath: String {
internal static var basePath: String {
return ImmutableX.shared.base.publicApiUrl
}
}

open class RequestBuilder<T> {
internal class RequestBuilder<T> {
var credential: URLCredential?
var headers: [String: String]
public let parameters: [String: Any]?
public let method: String
public let URLString: String
public let requestTask: RequestTask = RequestTask()
internal let parameters: [String: Any]?
internal let method: String
internal let URLString: String
internal 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.
/// If you need to get the request's progress in older OS versions, please use Alamofire http client.
public var onProgressReady: ((Progress) -> Void)?
internal var onProgressReady: ((Progress) -> Void)?

required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:]) {
required internal init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:]) {
self.method = method
self.URLString = URLString
self.parameters = parameters
Expand All @@ -46,31 +46,31 @@ open class RequestBuilder<T> {
addHeaders(OpenAPIClientAPI.customHeaders)
}

open func addHeaders(_ aHeaders: [String: String]) {
internal func addHeaders(_ aHeaders: [String: String]) {
for (header, value) in aHeaders {
headers[header] = value
}
}

@discardableResult
open func execute(_ apiResponseQueue: DispatchQueue = OpenAPIClientAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) -> RequestTask {
internal func execute(_ apiResponseQueue: DispatchQueue = OpenAPIClientAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, ErrorResponse>) -> Void) -> RequestTask {
return requestTask
}

public func addHeader(name: String, value: String) -> Self {
internal func addHeader(name: String, value: String) -> Self {
if !value.isEmpty {
headers[name] = value
}
return self
}

open func addCredential() -> Self {
internal func addCredential() -> Self {
credential = OpenAPIClientAPI.credential
return self
}
}

public protocol RequestBuilderFactory {
internal protocol RequestBuilderFactory {
func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type
func getBuilder<T: Decodable>() -> RequestBuilder<T>.Type
}
12 changes: 6 additions & 6 deletions Sources/ImmutableXCore/Generated/APIs/AssetsAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import AnyCodable
#endif

open class AssetsAPI {
internal class AssetsAPI {

/**
Get details of an asset
Expand All @@ -21,7 +21,7 @@ open class AssetsAPI {
- returns: Asset
*/
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
open class func getAsset(tokenAddress: String, tokenId: String, includeFees: Bool? = nil) async throws -> Asset {
internal class func getAsset(tokenAddress: String, tokenId: String, includeFees: Bool? = nil) async throws -> Asset {
var requestTask: RequestTask?
return try await withTaskCancellationHandler {
try Task.checkCancellation()
Expand Down Expand Up @@ -54,7 +54,7 @@ open class AssetsAPI {
- parameter includeFees: (query) Set flag to include fees associated with the asset (optional)
- returns: RequestBuilder<Asset>
*/
open class func getAssetWithRequestBuilder(tokenAddress: String, tokenId: String, includeFees: Bool? = nil) -> RequestBuilder<Asset> {
internal class func getAssetWithRequestBuilder(tokenAddress: String, tokenId: String, includeFees: Bool? = nil) -> RequestBuilder<Asset> {
var localVariablePath = "/v1/assets/{token_address}/{token_id}"
let tokenAddressPreEscape = "\(APIHelper.mapValueToPathItem(tokenAddress))"
let tokenAddressPostEscape = tokenAddressPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
Expand Down Expand Up @@ -84,7 +84,7 @@ open class AssetsAPI {
/**
* enum for parameter orderBy
*/
public enum OrderBy_listAssets: String, CaseIterable {
internal enum OrderBy_listAssets: String, CaseIterable {
case updatedAt = "updated_at"
case name = "name"
}
Expand All @@ -111,7 +111,7 @@ open class AssetsAPI {
- returns: ListAssetsResponse
*/
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
open 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 {
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?
return try await withTaskCancellationHandler {
try Task.checkCancellation()
Expand Down Expand Up @@ -157,7 +157,7 @@ open class AssetsAPI {
- parameter auxiliaryFeeRecipients: (query) Comma separated string of fee recipients that are to be paired with auxiliary_fee_percentages (optional)
- returns: RequestBuilder<ListAssetsResponse>
*/
open class func listAssetsWithRequestBuilder(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) -> RequestBuilder<ListAssetsResponse> {
internal class func listAssetsWithRequestBuilder(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) -> RequestBuilder<ListAssetsResponse> {
let localVariablePath = "/v1/assets"
let localVariableURLString = OpenAPIClientAPI.basePath + localVariablePath
let localVariableParameters: [String: Any]? = nil
Expand Down
10 changes: 5 additions & 5 deletions Sources/ImmutableXCore/Generated/APIs/BalancesAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import AnyCodable
#endif

open class BalancesAPI {
internal class BalancesAPI {

/**
Fetches the token balances of the user
Expand All @@ -20,7 +20,7 @@ open class BalancesAPI {
- returns: Balance
*/
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
open class func getBalance(owner: String, address: String) async throws -> Balance {
internal class func getBalance(owner: String, address: String) async throws -> Balance {
var requestTask: RequestTask?
return try await withTaskCancellationHandler {
try Task.checkCancellation()
Expand Down Expand Up @@ -52,7 +52,7 @@ open class BalancesAPI {
- parameter address: (path) Token address
- returns: RequestBuilder<Balance>
*/
open class func getBalanceWithRequestBuilder(owner: String, address: String) -> RequestBuilder<Balance> {
internal class func getBalanceWithRequestBuilder(owner: String, address: String) -> RequestBuilder<Balance> {
var localVariablePath = "/v2/balances/{owner}/{address}"
let ownerPreEscape = "\(APIHelper.mapValueToPathItem(owner))"
let ownerPostEscape = ownerPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
Expand Down Expand Up @@ -83,7 +83,7 @@ open class BalancesAPI {
- returns: ListBalancesResponse
*/
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
open class func listBalances(owner: String) async throws -> ListBalancesResponse {
internal class func listBalances(owner: String) async throws -> ListBalancesResponse {
var requestTask: RequestTask?
return try await withTaskCancellationHandler {
try Task.checkCancellation()
Expand Down Expand Up @@ -114,7 +114,7 @@ open class BalancesAPI {
- parameter owner: (path) Ethereum wallet address for user
- returns: RequestBuilder<ListBalancesResponse>
*/
open class func listBalancesWithRequestBuilder(owner: String) -> RequestBuilder<ListBalancesResponse> {
internal class func listBalancesWithRequestBuilder(owner: String) -> RequestBuilder<ListBalancesResponse> {
var localVariablePath = "/v2/balances/{owner}"
let ownerPreEscape = "\(APIHelper.mapValueToPathItem(owner))"
let ownerPostEscape = ownerPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
Expand Down
Loading

0 comments on commit c0c278d

Please sign in to comment.