Skip to content

Commit 131bd4f

Browse files
sebohdevSebastian Ohm
andauthored
Fix for Result Model Name collision (#5923)
* Fix for Result Model Name collision * Run Scripts Co-authored-by: Sebastian Ohm <[email protected]>
1 parent c479e51 commit 131bd4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+379
-289
lines changed

modules/openapi-generator/src/main/resources/swift5/APIs.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import Foundation
4444
}
4545
}
4646

47-
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func execute(_ apiResponseQueue: DispatchQueue = {{projectName}}API.apiResponseQueue, _ completion: @escaping (_ result: Result<Response<T>, Error>) -> Void) { }
47+
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func execute(_ apiResponseQueue: DispatchQueue = {{projectName}}API.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, Error>) -> Void) { }
4848

4949
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} func addHeader(name: String, value: String) -> Self {
5050
if !value.isEmpty {

modules/openapi-generator/src/main/resources/swift5/CodableHelper.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ import Foundation
3838
set { self.customJSONEncoder = newValue }
3939
}
4040

41-
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func decode<T>(_ type: T.Type, from data: Data) -> Result<T, Error> where T: Decodable {
42-
return Result { try self.jsonDecoder.decode(type, from: data) }
41+
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func decode<T>(_ type: T.Type, from data: Data) -> Swift.Result<T, Error> where T: Decodable {
42+
return Swift.Result { try self.jsonDecoder.decode(type, from: data) }
4343
}
4444

45-
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func encode<T>(_ value: T) -> Result<Data, Error> where T: Encodable {
46-
return Result { try self.jsonEncoder.encode(value) }
45+
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class func encode<T>(_ value: T) -> Swift.Result<Data, Error> where T: Encodable {
46+
return Swift.Result { try self.jsonEncoder.encode(value) }
4747
}
4848
}

modules/openapi-generator/src/main/resources/swift5/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ extension {{projectName}}API {
161161
- parameter apiResponseQueue: The queue on which api response is dispatched.
162162
- parameter completion: completion handler to receive the result
163163
*/
164-
open class func {{operationId}}({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#hasParams}}, {{/hasParams}}apiResponseQueue: DispatchQueue = {{projectName}}API.apiResponseQueue, completion: @escaping ((_ result: Result<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}, Error>) -> Void)) {
164+
open class func {{operationId}}({{#allParams}}{{paramName}}: {{#isEnum}}{{#isContainer}}{{{dataType}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}_{{operationId}}{{/isContainer}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{^required}}? = nil{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#hasParams}}, {{/hasParams}}apiResponseQueue: DispatchQueue = {{projectName}}API.apiResponseQueue, completion: @escaping ((_ result: Swift.Result<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Void{{/returnType}}, Error>) -> Void)) {
165165
{{operationId}}WithRequestBuilder({{#allParams}}{{paramName}}: {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}).execute(apiResponseQueue) { result -> Void in
166166
switch result {
167167
{{#returnType}}

modules/openapi-generator/src/main/resources/swift5/libraries/urlsession/URLSessionImplementations.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ private var urlSessionStore = SynchronizedDictionary<String, URLSession>()
102102
return modifiedRequest
103103
}
104104

105-
override {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func execute(_ apiResponseQueue: DispatchQueue = {{projectName}}API.apiResponseQueue, _ completion: @escaping (_ result: Result<Response<T>, Error>) -> Void) {
105+
override {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} func execute(_ apiResponseQueue: DispatchQueue = {{projectName}}API.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, Error>) -> Void) {
106106
let urlSessionId:String = UUID().uuidString
107107
// Create a new manager for each request to customize its request header
108108
let urlSession = createURLSession()
@@ -180,7 +180,7 @@ private var urlSessionStore = SynchronizedDictionary<String, URLSession>()
180180

181181
}
182182

183-
fileprivate func processRequestResponse(urlRequest: URLRequest, data: Data?, response: URLResponse?, error: Error?, completion: @escaping (_ result: Result<Response<T>, Error>) -> Void) {
183+
fileprivate func processRequestResponse(urlRequest: URLRequest, data: Data?, response: URLResponse?, error: Error?, completion: @escaping (_ result: Swift.Result<Response<T>, Error>) -> Void) {
184184
185185
if let error = error {
186186
completion(.failure(ErrorResponse.error(-1, data, error)))
@@ -312,7 +312,7 @@ private var urlSessionStore = SynchronizedDictionary<String, URLSession>()
312312
}
313313

314314
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class URLSessionDecodableRequestBuilder<T:Decodable>: URLSessionRequestBuilder<T> {
315-
override fileprivate func processRequestResponse(urlRequest: URLRequest, data: Data?, response: URLResponse?, error: Error?, completion: @escaping (_ result: Result<Response<T>, Error>) -> Void) {
315+
override fileprivate func processRequestResponse(urlRequest: URLRequest, data: Data?, response: URLResponse?, error: Error?, completion: @escaping (_ result: Swift.Result<Response<T>, Error>) -> Void) {
316316
317317
if let error = error {
318318
completion(.failure(ErrorResponse.error(-1, data, error)))

samples/client/petstore/swift5/default/Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
// Products define the executables and libraries produced by a package, and make them visible to other packages.
1515
.library(
1616
name: "PetstoreClient",
17-
targets: ["PetstoreClient"])
17+
targets: ["PetstoreClient"]),
1818
],
1919
dependencies: [
2020
// Dependencies declare other packages that this package depends on.
@@ -26,6 +26,6 @@ let package = Package(
2626
name: "PetstoreClient",
2727
dependencies: [],
2828
path: "PetstoreClient/Classes"
29-
)
29+
),
3030
]
3131
)

samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/APIHelper.swift

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Foundation
88

99
public struct APIHelper {
10-
public static func rejectNil(_ source: [String: Any?]) -> [String: Any]? {
10+
public static func rejectNil(_ source: [String:Any?]) -> [String:Any]? {
1111
let destination = source.reduce(into: [String: Any]()) { (result, item) in
1212
if let value = item.value {
1313
result[item.key] = value
@@ -20,17 +20,17 @@ public struct APIHelper {
2020
return destination
2121
}
2222

23-
public static func rejectNilHeaders(_ source: [String: Any?]) -> [String: String] {
23+
public static func rejectNilHeaders(_ source: [String:Any?]) -> [String:String] {
2424
return source.reduce(into: [String: String]()) { (result, item) in
25-
if let collection = item.value as? [Any?] {
26-
result[item.key] = collection.filter({ $0 != nil }).map { "\($0!)" }.joined(separator: ",")
25+
if let collection = item.value as? Array<Any?> {
26+
result[item.key] = collection.filter({ $0 != nil }).map{ "\($0!)" }.joined(separator: ",")
2727
} else if let value: Any = item.value {
2828
result[item.key] = "\(value)"
2929
}
3030
}
3131
}
3232

33-
public static func convertBoolToString(_ source: [String: Any]?) -> [String: Any]? {
33+
public static func convertBoolToString(_ source: [String: Any]?) -> [String:Any]? {
3434
guard let source = source else {
3535
return nil
3636
}
@@ -46,15 +46,15 @@ public struct APIHelper {
4646
}
4747

4848
public static func mapValueToPathItem(_ source: Any) -> Any {
49-
if let collection = source as? [Any?] {
49+
if let collection = source as? Array<Any?> {
5050
return collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
5151
}
5252
return source
5353
}
5454

55-
public static func mapValuesToQueryItems(_ source: [String: Any?]) -> [URLQueryItem]? {
55+
public static func mapValuesToQueryItems(_ source: [String:Any?]) -> [URLQueryItem]? {
5656
let destination = source.filter({ $0.value != nil}).reduce(into: [URLQueryItem]()) { (result, item) in
57-
if let collection = item.value as? [Any?] {
57+
if let collection = item.value as? Array<Any?> {
5858
let value = collection.filter({ $0 != nil }).map({"\($0!)"}).joined(separator: ",")
5959
result.append(URLQueryItem(name: item.key, value: value))
6060
} else if let value = item.value {
@@ -68,3 +68,4 @@ public struct APIHelper {
6868
return destination
6969
}
7070
}
71+

samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/APIs.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ import Foundation
99
open class PetstoreClientAPI {
1010
public static var basePath = "http://petstore.swagger.io:80/v2"
1111
public static var credential: URLCredential?
12-
public static var customHeaders: [String: String] = [:]
12+
public static var customHeaders: [String:String] = [:]
1313
public static var requestBuilderFactory: RequestBuilderFactory = URLSessionRequestBuilderFactory()
1414
public static var apiResponseQueue: DispatchQueue = .main
1515
}
1616

1717
open class RequestBuilder<T> {
1818
var credential: URLCredential?
19-
var headers: [String: String]
20-
public let parameters: [String: Any]?
19+
var headers: [String:String]
20+
public let parameters: [String:Any]?
2121
public let isBody: Bool
2222
public let method: String
2323
public let URLString: String
2424

2525
/// Optional block to obtain a reference to the request's progress instance when available.
2626
/// 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.
2727
/// If you need to get the request's progress in older OS versions, please use Alamofire http client.
28-
public var onProgressReady: ((Progress) -> Void)?
28+
public var onProgressReady: ((Progress) -> ())?
2929

30-
required public init(method: String, URLString: String, parameters: [String: Any]?, isBody: Bool, headers: [String: String] = [:]) {
30+
required public init(method: String, URLString: String, parameters: [String:Any]?, isBody: Bool, headers: [String:String] = [:]) {
3131
self.method = method
3232
self.URLString = URLString
3333
self.parameters = parameters
@@ -37,13 +37,13 @@ open class RequestBuilder<T> {
3737
addHeaders(PetstoreClientAPI.customHeaders)
3838
}
3939

40-
open func addHeaders(_ aHeaders: [String: String]) {
40+
open func addHeaders(_ aHeaders:[String:String]) {
4141
for (header, value) in aHeaders {
4242
headers[header] = value
4343
}
4444
}
4545

46-
open func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (_ result: Result<Response<T>, Error>) -> Void) { }
46+
open func execute(_ apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, _ completion: @escaping (_ result: Swift.Result<Response<T>, Error>) -> Void) { }
4747

4848
public func addHeader(name: String, value: String) -> Self {
4949
if !value.isEmpty {
@@ -60,5 +60,5 @@ open class RequestBuilder<T> {
6060

6161
public protocol RequestBuilderFactory {
6262
func getNonDecodableBuilder<T>() -> RequestBuilder<T>.Type
63-
func getBuilder<T: Decodable>() -> RequestBuilder<T>.Type
63+
func getBuilder<T:Decodable>() -> RequestBuilder<T>.Type
6464
}

samples/client/petstore/swift5/default/PetstoreClient/Classes/OpenAPIs/APIs/AnotherFakeAPI.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import Foundation
99

10+
11+
1012
open class AnotherFakeAPI {
1113
/**
1214
To test special tags
@@ -15,7 +17,7 @@ open class AnotherFakeAPI {
1517
- parameter apiResponseQueue: The queue on which api response is dispatched.
1618
- parameter completion: completion handler to receive the data and the error objects
1719
*/
18-
open class func call123testSpecialTags(body: Client, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Client?, _ error: Error?) -> Void)) {
20+
open class func call123testSpecialTags(body: Client, apiResponseQueue: DispatchQueue = PetstoreClientAPI.apiResponseQueue, completion: @escaping ((_ data: Client?,_ error: Error?) -> Void)) {
1921
call123testSpecialTagsWithRequestBuilder(body: body).execute(apiResponseQueue) { result -> Void in
2022
switch result {
2123
case let .success(response):

0 commit comments

Comments
 (0)