Skip to content

Commit 4d5c478

Browse files
committed
[Swift6][Client] Make Swift 6 generator thread safe
1 parent 4ea9bbf commit 4d5c478

14 files changed

Lines changed: 98 additions & 14 deletions

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ import Foundation
3030

3131
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var dateFormatter: DateFormatter {
3232
get { _state.withValue { $0.customDateFormatter ?? $0.defaultDateFormatter } }
33-
set { _state.withValue { $0.customDateFormatter = newValue } }
33+
set {
34+
_state.withValue { state in
35+
state.customDateFormatter = newValue
36+
state.defaultJSONDecoder = nil
37+
state.defaultJSONEncoder = nil
38+
}
39+
}
3440
}
3541

3642
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} var jsonDecoder: JSONDecoder {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ open class CodableHelper: @unchecked Sendable {
3030

3131
public var dateFormatter: DateFormatter {
3232
get { _state.withValue { $0.customDateFormatter ?? $0.defaultDateFormatter } }
33-
set { _state.withValue { $0.customDateFormatter = newValue } }
33+
set {
34+
_state.withValue { state in
35+
state.customDateFormatter = newValue
36+
state.defaultJSONDecoder = nil
37+
state.defaultJSONEncoder = nil
38+
}
39+
}
3440
}
3541

3642
public var jsonDecoder: JSONDecoder {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ open class CodableHelper: @unchecked Sendable {
3030

3131
public var dateFormatter: DateFormatter {
3232
get { _state.withValue { $0.customDateFormatter ?? $0.defaultDateFormatter } }
33-
set { _state.withValue { $0.customDateFormatter = newValue } }
33+
set {
34+
_state.withValue { state in
35+
state.customDateFormatter = newValue
36+
state.defaultJSONDecoder = nil
37+
state.defaultJSONEncoder = nil
38+
}
39+
}
3440
}
3541

3642
public var jsonDecoder: JSONDecoder {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ open class CodableHelper: @unchecked Sendable {
3030

3131
public var dateFormatter: DateFormatter {
3232
get { _state.withValue { $0.customDateFormatter ?? $0.defaultDateFormatter } }
33-
set { _state.withValue { $0.customDateFormatter = newValue } }
33+
set {
34+
_state.withValue { state in
35+
state.customDateFormatter = newValue
36+
state.defaultJSONDecoder = nil
37+
state.defaultJSONEncoder = nil
38+
}
39+
}
3440
}
3541

3642
public var jsonDecoder: JSONDecoder {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ open class CodableHelper: @unchecked Sendable {
3030

3131
public var dateFormatter: DateFormatter {
3232
get { _state.withValue { $0.customDateFormatter ?? $0.defaultDateFormatter } }
33-
set { _state.withValue { $0.customDateFormatter = newValue } }
33+
set {
34+
_state.withValue { state in
35+
state.customDateFormatter = newValue
36+
state.defaultJSONDecoder = nil
37+
state.defaultJSONEncoder = nil
38+
}
39+
}
3440
}
3541

3642
public var jsonDecoder: JSONDecoder {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ open class CodableHelper: @unchecked Sendable {
3030

3131
public var dateFormatter: DateFormatter {
3232
get { _state.withValue { $0.customDateFormatter ?? $0.defaultDateFormatter } }
33-
set { _state.withValue { $0.customDateFormatter = newValue } }
33+
set {
34+
_state.withValue { state in
35+
state.customDateFormatter = newValue
36+
state.defaultJSONDecoder = nil
37+
state.defaultJSONEncoder = nil
38+
}
39+
}
3440
}
3541

3642
public var jsonDecoder: JSONDecoder {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ open class CodableHelper: @unchecked Sendable {
3030

3131
public var dateFormatter: DateFormatter {
3232
get { _state.withValue { $0.customDateFormatter ?? $0.defaultDateFormatter } }
33-
set { _state.withValue { $0.customDateFormatter = newValue } }
33+
set {
34+
_state.withValue { state in
35+
state.customDateFormatter = newValue
36+
state.defaultJSONDecoder = nil
37+
state.defaultJSONEncoder = nil
38+
}
39+
}
3440
}
3541

3642
public var jsonDecoder: JSONDecoder {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ open class CodableHelper: @unchecked Sendable {
3030

3131
public var dateFormatter: DateFormatter {
3232
get { _state.withValue { $0.customDateFormatter ?? $0.defaultDateFormatter } }
33-
set { _state.withValue { $0.customDateFormatter = newValue } }
33+
set {
34+
_state.withValue { state in
35+
state.customDateFormatter = newValue
36+
state.defaultJSONDecoder = nil
37+
state.defaultJSONEncoder = nil
38+
}
39+
}
3440
}
3541

3642
public var jsonDecoder: JSONDecoder {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ open class CodableHelper: @unchecked Sendable {
3030

3131
public var dateFormatter: DateFormatter {
3232
get { _state.withValue { $0.customDateFormatter ?? $0.defaultDateFormatter } }
33-
set { _state.withValue { $0.customDateFormatter = newValue } }
33+
set {
34+
_state.withValue { state in
35+
state.customDateFormatter = newValue
36+
state.defaultJSONDecoder = nil
37+
state.defaultJSONEncoder = nil
38+
}
39+
}
3440
}
3541

3642
public var jsonDecoder: JSONDecoder {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ open class CodableHelper: @unchecked Sendable {
3030

3131
public var dateFormatter: DateFormatter {
3232
get { _state.withValue { $0.customDateFormatter ?? $0.defaultDateFormatter } }
33-
set { _state.withValue { $0.customDateFormatter = newValue } }
33+
set {
34+
_state.withValue { state in
35+
state.customDateFormatter = newValue
36+
state.defaultJSONDecoder = nil
37+
state.defaultJSONEncoder = nil
38+
}
39+
}
3440
}
3541

3642
public var jsonDecoder: JSONDecoder {

0 commit comments

Comments
 (0)