Skip to content

Commit

Permalink
[swift6] Add Sendable conformance to structs and enums (OpenAPITools#…
Browse files Browse the repository at this point in the history
  • Loading branch information
x-sheep authored Nov 4, 2024
1 parent 67af02c commit 00dbe59
Show file tree
Hide file tree
Showing 447 changed files with 668 additions and 639 deletions.
1 change: 1 addition & 0 deletions bin/configs/swift6-urlsessionLibrary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ additionalProperties:
useSPMFileStructure: true
mapFileBinaryToData: true
useClasses: true
readonlyProperties: true
swiftUseApiNamespace: true
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum JSONValue: Codable, Hashable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum JSONValue: Sendable, Codable, Hashable {
case string(String)
case int(Int)
case double(Double)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ extension CaseIterableDefaultsLast {
case encodeValue(Wrapped)
}

extension NullEncodable: Sendable where Wrapped: Sendable {}

extension NullEncodable: Codable where Wrapped: Codable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation
/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601.
/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate
/// can be used safely.
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct OpenAPIDateWithoutTime: Codable, Hashable, Equatable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct OpenAPIDateWithoutTime: Sendable, Codable, Hashable, Equatable {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let wrappedDate: Date
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} let timezone: TimeZone

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import Foundation

internal struct SynchronizedDictionary<K: Hashable, V> {
internal struct SynchronizedDictionary<K: Hashable, V> : @unchecked Sendable {
private var dictionary = [K: V]()
private let lock = NSRecursiveLock()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{dataType}}, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}, JSONEncodable{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{/enumUnknownDefaultCase}} {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{dataType}}, Sendable, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}, JSONEncodable{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{/enumUnknownDefaultCase}} {
{{#allowableValues}}
{{#enumVars}}
case {{{name}}} = {{{value}}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{enumName}}: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isContainer}}{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}, JSONEncodable{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/isContainer}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{#isContainer}}, CaseIterableDefaultsLast{{/isContainer}}{{/enumUnknownDefaultCase}} {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{enumName}}: {{^isContainer}}{{dataType}}{{/isContainer}}{{#isContainer}}String{{/isContainer}}, Sendable, {{#useVapor}}Content, Hashable{{/useVapor}}{{^useVapor}}Codable{{^isContainer}}{{^isString}}{{^isInteger}}{{^isFloat}}{{^isDouble}}, JSONEncodable{{/isDouble}}{{/isFloat}}{{/isInteger}}{{/isString}}{{/isContainer}}{{/useVapor}}, CaseIterable{{#enumUnknownDefaultCase}}{{#isInteger}}, CaseIterableDefaultsLast{{/isInteger}}{{#isFloat}}, CaseIterableDefaultsLast{{/isFloat}}{{#isDouble}}, CaseIterableDefaultsLast{{/isDouble}}{{#isString}}, CaseIterableDefaultsLast{{/isString}}{{#isContainer}}, CaseIterableDefaultsLast{{/isContainer}}{{/enumUnknownDefaultCase}} {
{{#allowableValues}}
{{#enumVars}}
case {{{name}}} = {{{value}}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} {{#useClasses}}final class{{/useClasses}}{{^useClasses}}struct{{/useClasses}} {{{classname}}}: {{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable{{#useJsonEncodable}}, JSONEncodable{{/useJsonEncodable}}{{/useVapor}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}} {
{{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} {{#useClasses}}final class{{/useClasses}}{{^useClasses}}struct{{/useClasses}} {{{classname}}}: {{^useClasses}}Sendable, {{/useClasses}}{{#useClasses}}{{#readonlyProperties}}@unchecked Sendable, {{/readonlyProperties}}{{/useClasses}}{{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable{{#useJsonEncodable}}, JSONEncodable{{/useJsonEncodable}}{{/useVapor}}{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}} {
{{/objcCompatible}}{{#objcCompatible}}@objcMembers {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable{{#useJsonEncodable}}, JSONEncodable{{/useJsonEncodable}} {
{{/objcCompatible}}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable, JSONEncodable{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}}{{/useVapor}} {
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum {{classname}}: {{^useClasses}}Sendable, {{/useClasses}}{{#useClasses}}{{#readonlyProperties}}Sendable, {{/readonlyProperties}}{{/useClasses}}{{#useVapor}}Content{{/useVapor}}{{^useVapor}}Codable, JSONEncodable{{#vendorExtensions.x-swift-hashable}}, Hashable{{/vendorExtensions.x-swift-hashable}}{{/useVapor}} {
{{#oneOf}}
case type{{.}}({{.}})
{{/oneOf}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public enum JSONValue: Codable, Hashable {
public enum JSONValue: Sendable, Codable, Hashable {
case string(String)
case int(Int)
case double(Double)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public enum NullEncodable<Wrapped: Hashable>: Hashable {
case encodeValue(Wrapped)
}

extension NullEncodable: Sendable where Wrapped: Sendable {}

extension NullEncodable: Codable where Wrapped: Codable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Foundation
/// an appropriate padding in order to transform to GMT+0 which is the assumed timezone in ISO 8601.
/// When decoding, GMT+0 can be assumed (again: ISO8601) so there is no padding necessary and wrappedDate
/// can be used safely.
public struct OpenAPIDateWithoutTime: Codable, Hashable, Equatable {
public struct OpenAPIDateWithoutTime: Sendable, Codable, Hashable, Equatable {
public let wrappedDate: Date
public let timezone: TimeZone

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import Foundation

internal struct SynchronizedDictionary<K: Hashable, V> {
internal struct SynchronizedDictionary<K: Hashable, V> : @unchecked Sendable {

private var dictionary = [K: V]()
private let lock = NSRecursiveLock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct AdditionalPropertiesClass: Codable, JSONEncodable, Hashable {
public struct AdditionalPropertiesClass: Sendable, Codable, JSONEncodable, Hashable {

public var mapString: [String: String]?
public var mapMapString: [String: [String: String]]?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Animal: Codable, JSONEncodable, Hashable {
public struct Animal: Sendable, Codable, JSONEncodable, Hashable {

public var className: String
public var color: String? = "red"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct ApiResponse: Codable, JSONEncodable, Hashable {
public struct ApiResponse: Sendable, Codable, JSONEncodable, Hashable {

public var code: Int?
public var type: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct ArrayOfArrayOfNumberOnly: Codable, JSONEncodable, Hashable {
public struct ArrayOfArrayOfNumberOnly: Sendable, Codable, JSONEncodable, Hashable {

public var arrayArrayNumber: [[Double]]?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct ArrayOfNumberOnly: Codable, JSONEncodable, Hashable {
public struct ArrayOfNumberOnly: Sendable, Codable, JSONEncodable, Hashable {

public var arrayNumber: [Double]?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct ArrayTest: Codable, JSONEncodable, Hashable {
public struct ArrayTest: Sendable, Codable, JSONEncodable, Hashable {

public var arrayOfString: [String]?
public var arrayArrayOfInteger: [[Int64]]?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Capitalization: Codable, JSONEncodable, Hashable {
public struct Capitalization: Sendable, Codable, JSONEncodable, Hashable {

public var smallCamel: String?
public var capitalCamel: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Cat: Codable, JSONEncodable, Hashable {
public struct Cat: Sendable, Codable, JSONEncodable, Hashable {

public var className: String
public var color: String? = "red"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Category: Codable, JSONEncodable, Hashable {
public struct Category: Sendable, Codable, JSONEncodable, Hashable {

public var id: Int64?
public var name: String? = "default-name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/** Model for testing model with \&quot;_class\&quot; property */
public struct ClassModel: Codable, JSONEncodable, Hashable {
public struct ClassModel: Sendable, Codable, JSONEncodable, Hashable {

public var _class: String?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Client: Codable, JSONEncodable, Hashable {
public struct Client: Sendable, Codable, JSONEncodable, Hashable {

public var client: String?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Dog: Codable, JSONEncodable, Hashable {
public struct Dog: Sendable, Codable, JSONEncodable, Hashable {

public var className: String
public var color: String? = "red"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

import Foundation

public struct EnumArrays: Codable, JSONEncodable, Hashable {
public struct EnumArrays: Sendable, Codable, JSONEncodable, Hashable {

public enum JustSymbol: String, Codable, CaseIterable {
public enum JustSymbol: String, Sendable, Codable, CaseIterable {
case greaterThanOrEqualTo = ">="
case dollar = "$"
}
public enum ArrayEnum: String, Codable, CaseIterable {
public enum ArrayEnum: String, Sendable, Codable, CaseIterable {
case fish = "fish"
case crab = "crab"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public enum EnumClass: String, Codable, CaseIterable {
public enum EnumClass: String, Sendable, Codable, CaseIterable {
case abc = "_abc"
case efg = "-efg"
case xyz = "(xyz)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@

import Foundation

public struct EnumTest: Codable, JSONEncodable, Hashable {
public struct EnumTest: Sendable, Codable, JSONEncodable, Hashable {

public enum EnumString: String, Codable, CaseIterable {
public enum EnumString: String, Sendable, Codable, CaseIterable {
case upper = "UPPER"
case lower = "lower"
case empty = ""
}
public enum EnumStringRequired: String, Codable, CaseIterable {
public enum EnumStringRequired: String, Sendable, Codable, CaseIterable {
case upper = "UPPER"
case lower = "lower"
case empty = ""
}
public enum EnumInteger: Int, Codable, CaseIterable {
public enum EnumInteger: Int, Sendable, Codable, CaseIterable {
case _1 = 1
case number1 = -1
}
public enum EnumNumber: Double, Codable, CaseIterable {
public enum EnumNumber: Double, Sendable, Codable, CaseIterable {
case _11 = 1.1
case number12 = -1.2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/** Must be named &#x60;File&#x60; for test. */
public struct File: Codable, JSONEncodable, Hashable {
public struct File: Sendable, Codable, JSONEncodable, Hashable {

/** Test capitalization */
public var sourceURI: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct FileSchemaTestClass: Codable, JSONEncodable, Hashable {
public struct FileSchemaTestClass: Sendable, Codable, JSONEncodable, Hashable {

public var file: File?
public var files: [File]?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct FormatTest: Codable, JSONEncodable, Hashable {
public struct FormatTest: Sendable, Codable, JSONEncodable, Hashable {

static let integerRule = NumericRule<Int>(minimum: 10, exclusiveMinimum: false, maximum: 100, exclusiveMaximum: false, multipleOf: nil)
static let int32Rule = NumericRule<Int>(minimum: 20, exclusiveMinimum: false, maximum: 200, exclusiveMaximum: false, multipleOf: nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct HasOnlyReadOnly: Codable, JSONEncodable, Hashable {
public struct HasOnlyReadOnly: Sendable, Codable, JSONEncodable, Hashable {

public var bar: String?
public var foo: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct List: Codable, JSONEncodable, Hashable {
public struct List: Sendable, Codable, JSONEncodable, Hashable {

public var _123list: String?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import Foundation

public struct MapTest: Codable, JSONEncodable, Hashable {
public struct MapTest: Sendable, Codable, JSONEncodable, Hashable {

public enum MapOfEnumString: String, Codable, CaseIterable {
public enum MapOfEnumString: String, Sendable, Codable, CaseIterable {
case upper = "UPPER"
case lower = "lower"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct MixedPropertiesAndAdditionalPropertiesClass: Codable, JSONEncodable, Hashable {
public struct MixedPropertiesAndAdditionalPropertiesClass: Sendable, Codable, JSONEncodable, Hashable {

public var uuid: UUID?
public var dateTime: Date?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/** Model for testing model name starting with number */
public struct Model200Response: Codable, JSONEncodable, Hashable {
public struct Model200Response: Sendable, Codable, JSONEncodable, Hashable {

public var name: Int?
public var _class: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

/** Model for testing model name same as property name */
public struct Name: Codable, JSONEncodable, Hashable {
public struct Name: Sendable, Codable, JSONEncodable, Hashable {

public var name: Int
public var snakeCase: NullEncodable<Int> = .encodeValue(11033)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct NumberOnly: Codable, JSONEncodable, Hashable {
public struct NumberOnly: Sendable, Codable, JSONEncodable, Hashable {

public var justNumber: Double?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import Foundation

public struct Order: Codable, JSONEncodable, Hashable {
public struct Order: Sendable, Codable, JSONEncodable, Hashable {

public enum Status: String, Codable, CaseIterable {
public enum Status: String, Sendable, Codable, CaseIterable {
case placed = "placed"
case approved = "approved"
case delivered = "delivered"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct OuterComposite: Codable, JSONEncodable, Hashable {
public struct OuterComposite: Sendable, Codable, JSONEncodable, Hashable {

public var myNumber: Double?
public var myString: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public enum OuterEnum: String, Codable, CaseIterable {
public enum OuterEnum: String, Sendable, Codable, CaseIterable {
case placed = "placed"
case approved = "approved"
case delivered = "delivered"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import Foundation

public struct Pet: Codable, JSONEncodable, Hashable {
public struct Pet: Sendable, Codable, JSONEncodable, Hashable {

public enum Status: String, Codable, CaseIterable {
public enum Status: String, Sendable, Codable, CaseIterable {
case available = "available"
case pending = "pending"
case sold = "sold"
Expand Down
Loading

0 comments on commit 00dbe59

Please sign in to comment.