Skip to content

Commit 66791e7

Browse files
committed
[swift6] Change Response to struct
1 parent 4c5a57f commit 66791e7

File tree

15 files changed

+44
-30
lines changed
  • docs
  • modules/openapi-generator/src/main/resources/swift6
  • samples/client/petstore/swift6
    • alamofireLibrary/Sources/PetstoreClient/Infrastructure
    • apiNonStaticMethod/Sources/PetstoreClient/Infrastructure
    • asyncAwaitLibrary/Sources/PetstoreClient/Infrastructure
    • combineDeferredLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure
    • combineLibrary/Sources/CombineLibrary/Infrastructure
    • default/Sources/PetstoreClient/Infrastructure
    • objcCompatible/Sources/PetstoreClient/Infrastructure
    • oneOf/PetstoreClient/Classes/OpenAPIs/Infrastructure
    • promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure
    • resultLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure
    • rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure
    • urlsessionLibrary/Sources/PetstoreClient/Infrastructure
    • validation/PetstoreClient/Classes/OpenAPIs/Infrastructure

15 files changed

+44
-30
lines changed

docs/contributing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ To add test cases (optional) covering the change in the code generator, please r
114114

115115
To test the templates, please perform the following:
116116

117-
- Update the Petstore sample by running the shell scripts under the `bin` folder. For example, run `./bin/generate-samples.sh ./bin/configs/python*` to update the Python-related samples under [`samples`](https://github.com/openapitools/openapi-generator/tree/master/samples). For Windows, please install [GIT bash](https://gitforwindows.org/). (If you find that there are new files generated or unexpected changes as a result of the update, that's not unusual as the test cases are added to the OpenAPI spec from time to time. If you've questions or concerns, please open a ticket to start a discussion)
117+
- Update the Petstore sample by running the shell scripts under the `bin` folder. For example, run `./bin/generate-samples.sh ./bin/configs/swift*` to update the Python-related samples under [`samples`](https://github.com/openapitools/openapi-generator/tree/master/samples). For Windows, please install [GIT bash](https://gitforwindows.org/). (If you find that there are new files generated or unexpected changes as a result of the update, that's not unusual as the test cases are added to the OpenAPI spec from time to time. If you've questions or concerns, please open a ticket to start a discussion)
118118
- During development, it can be helpful to quickly regenerate the samples without recompiling all of openapi-generator, e.g. when you have only updated the mustache templates. This can be done by passing the `-t` parameter: `-t modules/openapi-generator/src/main/resources/python`.
119119
- Run the tests in the sample folder using maven `mvn integration-test -f /path/to/pom.xml`, e.g. `mvn integration-test -f samples/client/petstore/python/pom.xml`. (some languages may not contain unit testing for Petstore and we're looking for contribution from the community to implement those tests). __Please notice:__ you must run a local instance of the Petstore server in order to perform the tests, as running them against petstore.swagger.io is not supported anymore. Please refer to item 3 of [Integration Tests - How to add integration tests for new Petstore samples](https://github.com/OpenAPITools/openapi-generator/wiki/Integration-Tests#how-to-add-integration-tests-for-new-petstore-samples) to learn how to quickly configure and run it.
120120
- Finally, git commit the updated samples files: `git commit -a` (`git add -A` if added files with new test cases)

modules/openapi-generator/src/main/resources/swift6/Models.mustache

+4-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ extension NullEncodable: Codable where Wrapped: Codable {
9090
case generalError(Error)
9191
}
9292

93-
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}open{{/nonPublicApi}} class Response<T> {
93+
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct Response<T> {
9494
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let statusCode: Int
9595
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let header: [String: String]
9696
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let body: T
@@ -103,7 +103,7 @@ extension NullEncodable: Codable where Wrapped: Codable {
103103
self.bodyData = bodyData
104104
}
105105

106-
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106+
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(response: HTTPURLResponse, body: T, bodyData: Data?) {
107107
let rawHeader = response.allHeaderFields
108108
var responseHeader = [String: String]()
109109
for (key, value) in rawHeader {
@@ -113,7 +113,8 @@ extension NullEncodable: Codable where Wrapped: Codable {
113113
}
114114
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
115115
}
116-
}{{#useAlamofire}}
116+
}
117+
extension Response : Sendable where T : Sendable {}{{#useAlamofire}}
117118

118119
/// Type-erased ResponseSerializer
119120
///

samples/client/petstore/swift6/alamofireLibrary/Sources/PetstoreClient/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public enum DecodableRequestBuilderError: Error {
9090
case generalError(Error)
9191
}
9292

93-
open class Response<T> {
93+
public struct Response<T> {
9494
public let statusCode: Int
9595
public let header: [String: String]
9696
public let body: T
@@ -103,7 +103,7 @@ open class Response<T> {
103103
self.bodyData = bodyData
104104
}
105105

106-
public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106+
public init(response: HTTPURLResponse, body: T, bodyData: Data?) {
107107
let rawHeader = response.allHeaderFields
108108
var responseHeader = [String: String]()
109109
for (key, value) in rawHeader {
@@ -114,6 +114,7 @@ open class Response<T> {
114114
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
115115
}
116116
}
117+
extension Response : Sendable where T : Sendable {}
117118

118119
/// Type-erased ResponseSerializer
119120
///

samples/client/petstore/swift6/apiNonStaticMethod/Sources/PetstoreClient/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public enum DecodableRequestBuilderError: Error {
9090
case generalError(Error)
9191
}
9292

93-
open class Response<T> {
93+
public struct Response<T> {
9494
public let statusCode: Int
9595
public let header: [String: String]
9696
public let body: T
@@ -103,7 +103,7 @@ open class Response<T> {
103103
self.bodyData = bodyData
104104
}
105105

106-
public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106+
public init(response: HTTPURLResponse, body: T, bodyData: Data?) {
107107
let rawHeader = response.allHeaderFields
108108
var responseHeader = [String: String]()
109109
for (key, value) in rawHeader {
@@ -114,6 +114,7 @@ open class Response<T> {
114114
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
115115
}
116116
}
117+
extension Response : Sendable where T : Sendable {}
117118

118119
/// Type-erased ResponseSerializer
119120
///

samples/client/petstore/swift6/asyncAwaitLibrary/Sources/PetstoreClient/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public enum DecodableRequestBuilderError: Error {
8989
case generalError(Error)
9090
}
9191

92-
open class Response<T> {
92+
public struct Response<T> {
9393
public let statusCode: Int
9494
public let header: [String: String]
9595
public let body: T
@@ -102,7 +102,7 @@ open class Response<T> {
102102
self.bodyData = bodyData
103103
}
104104

105-
public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
105+
public init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106106
let rawHeader = response.allHeaderFields
107107
var responseHeader = [String: String]()
108108
for (key, value) in rawHeader {
@@ -113,6 +113,7 @@ open class Response<T> {
113113
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
114114
}
115115
}
116+
extension Response : Sendable where T : Sendable {}
116117

117118
public final class RequestTask: @unchecked Sendable {
118119
private let lock = NSRecursiveLock()

samples/client/petstore/swift6/combineDeferredLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public enum DecodableRequestBuilderError: Error {
8989
case generalError(Error)
9090
}
9191

92-
open class Response<T> {
92+
public struct Response<T> {
9393
public let statusCode: Int
9494
public let header: [String: String]
9595
public let body: T
@@ -102,7 +102,7 @@ open class Response<T> {
102102
self.bodyData = bodyData
103103
}
104104

105-
public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
105+
public init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106106
let rawHeader = response.allHeaderFields
107107
var responseHeader = [String: String]()
108108
for (key, value) in rawHeader {
@@ -113,6 +113,7 @@ open class Response<T> {
113113
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
114114
}
115115
}
116+
extension Response : Sendable where T : Sendable {}
116117

117118
public final class RequestTask: @unchecked Sendable {
118119
private let lock = NSRecursiveLock()

samples/client/petstore/swift6/combineLibrary/Sources/CombineLibrary/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public enum DecodableRequestBuilderError: Error {
8989
case generalError(Error)
9090
}
9191

92-
open class Response<T> {
92+
public struct Response<T> {
9393
public let statusCode: Int
9494
public let header: [String: String]
9595
public let body: T
@@ -102,7 +102,7 @@ open class Response<T> {
102102
self.bodyData = bodyData
103103
}
104104

105-
public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
105+
public init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106106
let rawHeader = response.allHeaderFields
107107
var responseHeader = [String: String]()
108108
for (key, value) in rawHeader {
@@ -113,6 +113,7 @@ open class Response<T> {
113113
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
114114
}
115115
}
116+
extension Response : Sendable where T : Sendable {}
116117

117118
public final class RequestTask: @unchecked Sendable {
118119
private let lock = NSRecursiveLock()

samples/client/petstore/swift6/default/Sources/PetstoreClient/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public enum DecodableRequestBuilderError: Error {
8989
case generalError(Error)
9090
}
9191

92-
open class Response<T> {
92+
public struct Response<T> {
9393
public let statusCode: Int
9494
public let header: [String: String]
9595
public let body: T
@@ -102,7 +102,7 @@ open class Response<T> {
102102
self.bodyData = bodyData
103103
}
104104

105-
public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
105+
public init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106106
let rawHeader = response.allHeaderFields
107107
var responseHeader = [String: String]()
108108
for (key, value) in rawHeader {
@@ -113,6 +113,7 @@ open class Response<T> {
113113
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
114114
}
115115
}
116+
extension Response : Sendable where T : Sendable {}
116117

117118
public final class RequestTask: @unchecked Sendable {
118119
private let lock = NSRecursiveLock()

samples/client/petstore/swift6/objcCompatible/Sources/PetstoreClient/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public enum DecodableRequestBuilderError: Error {
8989
case generalError(Error)
9090
}
9191

92-
open class Response<T> {
92+
public struct Response<T> {
9393
public let statusCode: Int
9494
public let header: [String: String]
9595
public let body: T
@@ -102,7 +102,7 @@ open class Response<T> {
102102
self.bodyData = bodyData
103103
}
104104

105-
public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
105+
public init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106106
let rawHeader = response.allHeaderFields
107107
var responseHeader = [String: String]()
108108
for (key, value) in rawHeader {
@@ -113,6 +113,7 @@ open class Response<T> {
113113
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
114114
}
115115
}
116+
extension Response : Sendable where T : Sendable {}
116117

117118
public final class RequestTask: @unchecked Sendable {
118119
private let lock = NSRecursiveLock()

samples/client/petstore/swift6/oneOf/PetstoreClient/Classes/OpenAPIs/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public enum DecodableRequestBuilderError: Error {
8989
case generalError(Error)
9090
}
9191

92-
open class Response<T> {
92+
public struct Response<T> {
9393
public let statusCode: Int
9494
public let header: [String: String]
9595
public let body: T
@@ -102,7 +102,7 @@ open class Response<T> {
102102
self.bodyData = bodyData
103103
}
104104

105-
public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
105+
public init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106106
let rawHeader = response.allHeaderFields
107107
var responseHeader = [String: String]()
108108
for (key, value) in rawHeader {
@@ -113,6 +113,7 @@ open class Response<T> {
113113
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
114114
}
115115
}
116+
extension Response : Sendable where T : Sendable {}
116117

117118
public final class RequestTask: @unchecked Sendable {
118119
private let lock = NSRecursiveLock()

samples/client/petstore/swift6/promisekitLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public enum DecodableRequestBuilderError: Error {
8989
case generalError(Error)
9090
}
9191

92-
open class Response<T> {
92+
public struct Response<T> {
9393
public let statusCode: Int
9494
public let header: [String: String]
9595
public let body: T
@@ -102,7 +102,7 @@ open class Response<T> {
102102
self.bodyData = bodyData
103103
}
104104

105-
public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
105+
public init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106106
let rawHeader = response.allHeaderFields
107107
var responseHeader = [String: String]()
108108
for (key, value) in rawHeader {
@@ -113,6 +113,7 @@ open class Response<T> {
113113
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
114114
}
115115
}
116+
extension Response : Sendable where T : Sendable {}
116117

117118
public final class RequestTask: @unchecked Sendable {
118119
private let lock = NSRecursiveLock()

samples/client/petstore/swift6/resultLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ internal enum DecodableRequestBuilderError: Error {
8989
case generalError(Error)
9090
}
9191

92-
internal class Response<T> {
92+
internal struct Response<T> {
9393
internal let statusCode: Int
9494
internal let header: [String: String]
9595
internal let body: T
@@ -102,7 +102,7 @@ internal class Response<T> {
102102
self.bodyData = bodyData
103103
}
104104

105-
internal convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
105+
internal init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106106
let rawHeader = response.allHeaderFields
107107
var responseHeader = [String: String]()
108108
for (key, value) in rawHeader {
@@ -113,6 +113,7 @@ internal class Response<T> {
113113
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
114114
}
115115
}
116+
extension Response : Sendable where T : Sendable {}
116117

117118
internal final class RequestTask: @unchecked Sendable {
118119
private let lock = NSRecursiveLock()

samples/client/petstore/swift6/rxswiftLibrary/PetstoreClient/Classes/OpenAPIs/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public enum DecodableRequestBuilderError: Error {
8989
case generalError(Error)
9090
}
9191

92-
open class Response<T> {
92+
public struct Response<T> {
9393
public let statusCode: Int
9494
public let header: [String: String]
9595
public let body: T
@@ -102,7 +102,7 @@ open class Response<T> {
102102
self.bodyData = bodyData
103103
}
104104

105-
public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
105+
public init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106106
let rawHeader = response.allHeaderFields
107107
var responseHeader = [String: String]()
108108
for (key, value) in rawHeader {
@@ -113,6 +113,7 @@ open class Response<T> {
113113
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
114114
}
115115
}
116+
extension Response : Sendable where T : Sendable {}
116117

117118
public final class RequestTask: @unchecked Sendable {
118119
private let lock = NSRecursiveLock()

samples/client/petstore/swift6/urlsessionLibrary/Sources/PetstoreClient/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public enum DecodableRequestBuilderError: Error {
8989
case generalError(Error)
9090
}
9191

92-
open class Response<T> {
92+
public struct Response<T> {
9393
public let statusCode: Int
9494
public let header: [String: String]
9595
public let body: T
@@ -102,7 +102,7 @@ open class Response<T> {
102102
self.bodyData = bodyData
103103
}
104104

105-
public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
105+
public init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106106
let rawHeader = response.allHeaderFields
107107
var responseHeader = [String: String]()
108108
for (key, value) in rawHeader {
@@ -113,6 +113,7 @@ open class Response<T> {
113113
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
114114
}
115115
}
116+
extension Response : Sendable where T : Sendable {}
116117

117118
public final class RequestTask: @unchecked Sendable {
118119
private let lock = NSRecursiveLock()

samples/client/petstore/swift6/validation/PetstoreClient/Classes/OpenAPIs/Infrastructure/Models.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public enum DecodableRequestBuilderError: Error {
8989
case generalError(Error)
9090
}
9191

92-
open class Response<T> {
92+
public struct Response<T> {
9393
public let statusCode: Int
9494
public let header: [String: String]
9595
public let body: T
@@ -102,7 +102,7 @@ open class Response<T> {
102102
self.bodyData = bodyData
103103
}
104104

105-
public convenience init(response: HTTPURLResponse, body: T, bodyData: Data?) {
105+
public init(response: HTTPURLResponse, body: T, bodyData: Data?) {
106106
let rawHeader = response.allHeaderFields
107107
var responseHeader = [String: String]()
108108
for (key, value) in rawHeader {
@@ -113,6 +113,7 @@ open class Response<T> {
113113
self.init(statusCode: response.statusCode, header: responseHeader, body: body, bodyData: bodyData)
114114
}
115115
}
116+
extension Response : Sendable where T : Sendable {}
116117

117118
public final class RequestTask: @unchecked Sendable {
118119
private let lock = NSRecursiveLock()

0 commit comments

Comments
 (0)