Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[swift5][client] remove deprecated APIs #14635

Merged
merged 2 commits into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion bin/configs/swift5-resultLibrary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ additionalProperties:
podSummary: PetstoreClient
projectName: PetstoreClient
podHomepage: https://github.com/openapitools/openapi-generator
removeMigrationProjectNameClass: true
1 change: 0 additions & 1 deletion docs/generators/swift5.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|projectName|Project name in Xcode| |null|
|readonlyProperties|Make properties readonly (default: false)| |null|
|removeMigrationProjectNameClass|Make properties removeMigrationProjectNameClass (default: false)| |null|
|responseAs|Optionally use libraries to manage response. Currently PromiseKit, RxSwift, Result, Combine, AsyncAwait are available.| |null|
|sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |true|
|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
public static final String POD_SCREENSHOTS = "podScreenshots";
public static final String POD_DOCUMENTATION_URL = "podDocumentationURL";
public static final String READONLY_PROPERTIES = "readonlyProperties";
public static final String REMOVE_MIGRATION_PROJECT_NAME_CLASS = "removeMigrationProjectNameClass";
public static final String SWIFT_USE_API_NAMESPACE = "swiftUseApiNamespace";
public static final String DEFAULT_POD_AUTHORS = "OpenAPI Generator";
public static final String LENIENT_TYPE_CAST = "lenientTypeCast";
Expand All @@ -88,7 +87,6 @@ public class Swift5ClientCodegen extends DefaultCodegen implements CodegenConfig
protected boolean objcCompatible = false;
protected boolean lenientTypeCast = false;
protected boolean readonlyProperties = false;
protected boolean removeMigrationProjectNameClass = false;
protected boolean swiftUseApiNamespace = false;
protected boolean useSPMFileStructure = false;
protected String swiftPackagePath = "Classes" + File.separator + "OpenAPIs";
Expand Down Expand Up @@ -273,8 +271,6 @@ public Swift5ClientCodegen() {
"Documentation URL used for Podspec"));
cliOptions.add(new CliOption(READONLY_PROPERTIES, "Make properties "
+ "readonly (default: false)"));
cliOptions.add(new CliOption(REMOVE_MIGRATION_PROJECT_NAME_CLASS, "Make properties "
+ "removeMigrationProjectNameClass (default: false)"));
cliOptions.add(new CliOption(SWIFT_USE_API_NAMESPACE,
"Flag to make all the API classes inner-class "
+ "of {{projectName}}API"));
Expand Down Expand Up @@ -470,12 +466,6 @@ public void processOpts() {
}
additionalProperties.put(READONLY_PROPERTIES, readonlyProperties);

// Setup removeMigrationProjectNameClass option, which keeps or remove the projectName class
if (additionalProperties.containsKey(REMOVE_MIGRATION_PROJECT_NAME_CLASS)) {
setRemoveMigrationProjectNameClass(convertPropertyToBooleanAndWriteBack(REMOVE_MIGRATION_PROJECT_NAME_CLASS));
}
additionalProperties.put(REMOVE_MIGRATION_PROJECT_NAME_CLASS, removeMigrationProjectNameClass);

// Setup swiftUseApiNamespace option, which makes all the API
// classes inner-class of {{projectName}}API
if (additionalProperties.containsKey(SWIFT_USE_API_NAMESPACE)) {
Expand Down Expand Up @@ -957,10 +947,6 @@ public void setReadonlyProperties(boolean readonlyProperties) {
this.readonlyProperties = readonlyProperties;
}

public void setRemoveMigrationProjectNameClass(boolean removeMigrationProjectNameClass) {
this.removeMigrationProjectNameClass = removeMigrationProjectNameClass;
}

public void setResponseAs(String[] responseAs) {
this.responseAs = responseAs;
}
Expand Down
14 changes: 2 additions & 12 deletions modules/openapi-generator/src/main/resources/swift5/APIs.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@

import Foundation{{#useVapor}}
import Vapor
{{/useVapor}}{{^removeMigrationProjectNameClass}}

// We reverted the change of {{projectName}}API to {{projectName}} introduced in https://github.com/OpenAPITools/openapi-generator/pull/9624
// Because it was causing the following issue https://github.com/OpenAPITools/openapi-generator/issues/9953
// 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: "{{projectName}}API")
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} typealias {{projectName}} = {{projectName}}API
{{/removeMigrationProjectNameClass}}
{{/useVapor}}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class {{projectName}}API {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static var basePath = "{{{basePath}}}"
Expand All @@ -39,9 +31,7 @@ import Vapor
{{#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}}
/// Optional block to obtain a reference to the request's progress instance when available.
{{#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] = [:], requiresAuthentication: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ extension {{projectName}}API {
{{#useVapor}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static var apiClient: Vapor.Client? = nil
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static var apiWrapper: (inout Vapor.ClientRequest) throws -> () = { _ in }
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static var contentConfiguration = ContentConfiguration.default(){{/useVapor}}{{^useVapor}}
// This value is used to configure the date formatter that is used to serialize dates into JSON format.
// You must set it prior to encoding any dates, and it will only be read once.
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
/// Configures the range of HTTP status codes that will result in a successful response
///
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private var credentialStore = SynchronizedDictionary<Int, URLCredential>()
- intercept and handle errors like authorization
- retry the request.
*/
@available(*, deprecated, message: "Please override execute() method to intercept and handle errors like authorization or retry the request. Check the Wiki for more info. https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-do-i-implement-bearer-token-authentication-with-urlsession-on-the-swift-api-client")
@available(*, unavailable, message: "Please override execute() method to intercept and handle errors like authorization or retry the request. Check the Wiki for more info. https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-do-i-implement-bearer-token-authentication-with-urlsession-on-the-swift-api-client")
{{#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] = [:], requiresAuthentication: Bool) {
Expand Down Expand Up @@ -145,32 +145,13 @@ private var credentialStore = SynchronizedDictionary<Int, URLCredential>()
}

let dataTask = urlSession.dataTask(with: request) { data, response, error in

if let taskCompletionShouldRetry = self.taskCompletionShouldRetry {

taskCompletionShouldRetry(data, response, error) { shouldRetry in

if shouldRetry {
cleanupRequest()
self.execute(apiResponseQueue, completion)
} else {
apiResponseQueue.async {
self.processRequestResponse(urlRequest: request, data: data, response: response, error: error, completion: completion)
cleanupRequest()
}
}
}
} else {
apiResponseQueue.async {
self.processRequestResponse(urlRequest: request, data: data, response: response, error: error, completion: completion)
cleanupRequest()
}
apiResponseQueue.async {
self.processRequestResponse(urlRequest: request, data: data, response: response, error: error, completion: completion)
cleanupRequest()
}
}

if #available(iOS 11.0, macOS 10.13, macCatalyst 13.0, tvOS 11.0, watchOS 4.0, *) {
onProgressReady?(dataTask.progress)
}
onProgressReady?(dataTask.progress)

taskIdentifier = dataTask.taskIdentifier
challengeHandlerStore[dataTask.taskIdentifier] = taskDidReceiveChallenge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class Swift5OptionsProvider implements OptionsProvider {
public static final String POD_SCREENSHOTS_VALUE = "podScreenshots";
public static final String POD_DOCUMENTATION_URL_VALUE = "podDocumentationURL";
public static final String READONLY_PROPERTIES_VALUE = "false";
public static final String REMOVE_MIGRATION_PROJECT_NAME_CLASS_VALUE = "false";
public static final String SWIFT_USE_API_NAMESPACE_VALUE = "swiftUseApiNamespace";
public static final String USE_BACKTICKS_ESCAPES_VALUE = "false";
public static final String GENERATE_MODEL_ADDITIONAL_PROPERTIES_VALUE = "true";
Expand Down Expand Up @@ -85,7 +84,6 @@ public Map<String, String> createOptions() {
.put(Swift5ClientCodegen.POD_SCREENSHOTS, POD_SCREENSHOTS_VALUE)
.put(Swift5ClientCodegen.POD_DOCUMENTATION_URL, POD_DOCUMENTATION_URL_VALUE)
.put(Swift5ClientCodegen.READONLY_PROPERTIES, READONLY_PROPERTIES_VALUE)
.put(Swift5ClientCodegen.REMOVE_MIGRATION_PROJECT_NAME_CLASS, REMOVE_MIGRATION_PROJECT_NAME_CLASS_VALUE)
.put(Swift5ClientCodegen.SWIFT_USE_API_NAMESPACE, SWIFT_USE_API_NAMESPACE_VALUE)
.put(Swift5ClientCodegen.USE_BACKTICK_ESCAPES, USE_BACKTICKS_ESCAPES_VALUE)
.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ protected void verifyOptions() {
verify(clientCodegen).setLenientTypeCast(Boolean.parseBoolean(Swift5OptionsProvider.LENIENT_TYPE_CAST_VALUE));
verify(clientCodegen).setPrependFormOrBodyParameters(Boolean.valueOf(Swift5OptionsProvider.PREPEND_FORM_OR_BODY_PARAMETERS_VALUE));
verify(clientCodegen).setReadonlyProperties(Boolean.parseBoolean(Swift5OptionsProvider.READONLY_PROPERTIES_VALUE));
verify(clientCodegen).setRemoveMigrationProjectNameClass(Boolean.parseBoolean(Swift5OptionsProvider.REMOVE_MIGRATION_PROJECT_NAME_CLASS_VALUE));
verify(clientCodegen).setGenerateModelAdditionalProperties(Boolean.parseBoolean(Swift5OptionsProvider.GENERATE_MODEL_ADDITIONAL_PROPERTIES_VALUE));
verify(clientCodegen).setHashableModels(Boolean.parseBoolean(Swift5OptionsProvider.HASHABLE_MODELS_VALUE));
verify(clientCodegen).setEnumUnknownDefaultCase(Boolean.parseBoolean(Swift5OptionsProvider.ENUM_UNKNOWN_DEFAULT_CASE_VALUE));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
//

import Foundation

// We reverted the change of PetstoreClientAPI to PetstoreClient introduced in https://github.com/OpenAPITools/openapi-generator/pull/9624
// Because it was causing the following issue https://github.com/OpenAPITools/openapi-generator/issues/9953
// 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: "PetstoreClientAPI")
public typealias PetstoreClient = PetstoreClientAPI

open class PetstoreClientAPI {
public static var basePath = "http://petstore.swagger.io:80/v2"
public static var customHeaders: [String: String] = [:]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import Alamofire

open class Configuration {

// This value is used to configure the date formatter that is used to serialize dates into JSON format.
// You must set it prior to encoding any dates, and it will only be read once.
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
/// Configures the range of HTTP status codes that will result in a successful response
///
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
//

import Foundation

// We reverted the change of PetstoreClientAPI to PetstoreClient introduced in https://github.com/OpenAPITools/openapi-generator/pull/9624
// Because it was causing the following issue https://github.com/OpenAPITools/openapi-generator/issues/9953
// 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: "PetstoreClientAPI")
public typealias PetstoreClient = PetstoreClientAPI

open class PetstoreClientAPI {
public static var basePath = "http://petstore.swagger.io:80/v2"
public static var customHeaders: [String: String] = [:]
Expand All @@ -31,8 +23,6 @@ open class RequestBuilder<T> {
public 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.
public var onProgressReady: ((Progress) -> Void)?

required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import Foundation

open class Configuration {

// This value is used to configure the date formatter that is used to serialize dates into JSON format.
// You must set it prior to encoding any dates, and it will only be read once.
@available(*, unavailable, message: "To set a different date format, use CodableHelper.dateFormatter instead.")
public static var dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
/// Configures the range of HTTP status codes that will result in a successful response
///
/// If a HTTP status code is outside of this range the response will be interpreted as failed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
- intercept and handle errors like authorization
- retry the request.
*/
@available(*, deprecated, message: "Please override execute() method to intercept and handle errors like authorization or retry the request. Check the Wiki for more info. https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-do-i-implement-bearer-token-authentication-with-urlsession-on-the-swift-api-client")
@available(*, unavailable, message: "Please override execute() method to intercept and handle errors like authorization or retry the request. Check the Wiki for more info. https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#how-do-i-implement-bearer-token-authentication-with-urlsession-on-the-swift-api-client")
public var taskCompletionShouldRetry: ((Data?, URLResponse?, Error?, @escaping (Bool) -> Void) -> Void)?

required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool) {
Expand Down Expand Up @@ -145,32 +145,13 @@ open class URLSessionRequestBuilder<T>: RequestBuilder<T> {
}

let dataTask = urlSession.dataTask(with: request) { data, response, error in

if let taskCompletionShouldRetry = self.taskCompletionShouldRetry {

taskCompletionShouldRetry(data, response, error) { shouldRetry in

if shouldRetry {
cleanupRequest()
self.execute(apiResponseQueue, completion)
} else {
apiResponseQueue.async {
self.processRequestResponse(urlRequest: request, data: data, response: response, error: error, completion: completion)
cleanupRequest()
}
}
}
} else {
apiResponseQueue.async {
self.processRequestResponse(urlRequest: request, data: data, response: response, error: error, completion: completion)
cleanupRequest()
}
apiResponseQueue.async {
self.processRequestResponse(urlRequest: request, data: data, response: response, error: error, completion: completion)
cleanupRequest()
}
}

if #available(iOS 11.0, macOS 10.13, macCatalyst 13.0, tvOS 11.0, watchOS 4.0, *) {
onProgressReady?(dataTask.progress)
}
onProgressReady?(dataTask.progress)

taskIdentifier = dataTask.taskIdentifier
challengeHandlerStore[dataTask.taskIdentifier] = taskDidReceiveChallenge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
//

import Foundation

// We reverted the change of PetstoreClientAPI to PetstoreClient introduced in https://github.com/OpenAPITools/openapi-generator/pull/9624
// Because it was causing the following issue https://github.com/OpenAPITools/openapi-generator/issues/9953
// 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: "PetstoreClientAPI")
public typealias PetstoreClient = PetstoreClientAPI

open class PetstoreClientAPI {
public static var basePath = "http://petstore.swagger.io:80/v2"
public static var customHeaders: [String: String] = [:]
Expand All @@ -31,8 +23,6 @@ open class RequestBuilder<T> {
public 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.
public var onProgressReady: ((Progress) -> Void)?

required public init(method: String, URLString: String, parameters: [String: Any]?, headers: [String: String] = [:], requiresAuthentication: Bool) {
Expand Down
Loading