Swift5 models improvements (#9205)

* [swift5] Add useClasses to use `final class` instead of `struct`

* [swift5] Always include CodingKeys enum

* [swift5] Implement model equals and hash functions

* [swift5] Encode `null` values

* [swift5] Test `useClasses` in urlsessionLibrary

* [swift5] Add a required nullable prop test case to 2_0/swift/petstore*.yaml

* [swift5] Update samples and docs
This commit is contained in:
Ayman Bagabas
2021-04-23 22:04:30 -04:00
committed by GitHub
parent 22950fa2b2
commit 0f5e7d1e3c
414 changed files with 6684 additions and 342 deletions

View File

@@ -10,3 +10,4 @@ additionalProperties:
projectName: PetstoreClient
podHomepage: https://github.com/openapitools/openapi-generator
useSPMFileStructure: true
useClasses: true

View File

@@ -14,7 +14,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|legacyDiscriminatorBehavior|Set to false for generators with better support for discriminators. (Python, Java, Go, PowerShell, C#have this enabled by default).|<dl><dt>**true**</dt><dd>The mapping in the discriminator includes descendent schemas that allOf inherit from self and the discriminator mapping schemas in the OAS document.</dd><dt>**false**</dt><dd>The mapping in the discriminator includes any descendent schemas that allOf inherit from self, any oneOf schemas, any anyOf schemas, any x-discriminator-values, and the discriminator mapping schemas in the OAS document AND Codegen validates that oneOf and anyOf schemas contain the required discriminator and throws an error if the discriminator is missing.</dd></dl>|true|
|lenientTypeCast|Accept and cast values for simple types (string-&gt;bool, string-&gt;int, int-&gt;string)| |false|
|library|Library template (sub-template) to use|<dl><dt>**urlsession**</dt><dd>[DEFAULT] HTTP client: URLSession</dd><dt>**alamofire**</dt><dd>HTTP client: Alamofire</dd><dt>**vapor**</dt><dd>HTTP client: Vapor</dd></dl>|urlsession|
|library|Library template (sub-template) to use|<dl><dt>**urlsession**</dt><dd>[DEFAULT] HTTP client: URLSession</dd><dt>**alamofire**</dt><dd>HTTP client: Alamofire</dd></dl>|urlsession|
|nonPublicApi|Generates code with reduced access modifiers; allows embedding elsewhere without exposing non-public API calls to consumers.(default: false)| |null|
|objcCompatible|Add additional properties and methods for Objective-C compatibility (default: false)| |null|
|podAuthors|Authors used for Podspec| |null|

View File

@@ -1,4 +1,4 @@
{{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} struct {{classname}}: Codable, Hashable {
{{^objcCompatible}}{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} {{#useClasses}}final class{{/useClasses}}{{^useClasses}}struct{{/useClasses}} {{classname}}: Codable, Hashable {
{{/objcCompatible}}{{#objcCompatible}}@objc {{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} class {{classname}}: NSObject, Codable {
{{/objcCompatible}}
@@ -36,6 +36,11 @@
{{/allVars}}
}
{{/hasVars}}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum CodingKeys: {{#hasVars}}String, {{/hasVars}}CodingKey, CaseIterable {
{{#allVars}}
case {{{name}}}{{#vendorExtensions.x-codegen-escaped-property-name}} = "{{{baseName}}}"{{/vendorExtensions.x-codegen-escaped-property-name}}
{{/allVars}}
}
{{#additionalPropertiesType}}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} {{#readonlyProperties}}private(set) {{/readonlyProperties}}var additionalProperties: [String: {{{additionalPropertiesType}}}] = [:]
@@ -51,19 +56,22 @@
additionalProperties[key] = newValue
}
}
{{/additionalPropertiesType}}
// Encodable protocol methods
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: String.self)
var container = encoder.container(keyedBy: CodingKeys.self)
{{#allVars}}
try container.encode{{#required}}{{#isNullable}}IfPresent{{/isNullable}}{{/required}}{{^required}}IfPresent{{/required}}({{{name}}}, forKey: "{{{baseName}}}")
try container.encode{{^required}}IfPresent{{/required}}({{{name}}}, forKey: .{{{name}}})
{{/allVars}}
try container.encodeMap(additionalProperties)
{{#additionalPropertiesType}}
var additionalPropertiesContainer = encoder.container(keyedBy: String.self)
try additionalPropertiesContainer.encodeMap(additionalProperties)
{{/additionalPropertiesType}}
}
{{#additionalPropertiesType}}
// Decodable protocol methods
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}}{{#objcCompatible}} required{{/objcCompatible}} init(from decoder: Decoder) throws {
@@ -79,11 +87,20 @@
additionalProperties = try container.decodeMap({{{additionalPropertiesType}}}.self, excludedKeys: nonAdditionalPropertyKeys)
}
{{/additionalPropertiesType}}
{{^additionalPropertiesType}}{{#vendorExtensions.x-codegen-has-escaped-property-names}}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} enum CodingKeys: String, CodingKey, CaseIterable {
{{^objcCompatible}}{{#useClasses}}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} static func == (lhs: {{classname}}, rhs: {{classname}}) -> Bool {
{{#allVars}}
case {{{name}}}{{#vendorExtensions.x-codegen-escaped-property-name}} = "{{{baseName}}}"{{/vendorExtensions.x-codegen-escaped-property-name}}
lhs.{{{name}}} == rhs.{{{name}}}{{^-last}} &&{{/-last}}
{{/allVars}}
{{#additionalPropertiesType}}{{#hasVars}}&& {{/hasVars}}lhs.additionalProperties == rhs.additionalProperties{{/additionalPropertiesType}}
}
{{/vendorExtensions.x-codegen-has-escaped-property-names}}{{/additionalPropertiesType}}
{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} func hash(into hasher: inout Hasher) {
{{#allVars}}
hasher.combine({{{name}}}{{^required}}?{{/required}}.hashValue)
{{/allVars}}
{{#additionalPropertiesType}}hasher.combine(additionalProperties.hashValue){{/additionalPropertiesType}}
}
{{/useClasses}}{{/objcCompatible}}
}

View File

@@ -1096,6 +1096,7 @@ definitions:
name:
type: string
default: default-name
x-nullable: true
xml:
name: Category
User:

View File

@@ -16,10 +16,19 @@ public struct AdditionalPropertiesClass: Codable, Hashable {
self.mapString = mapString
self.mapMapString = mapMapString
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case mapString = "map_string"
case mapMapString = "map_map_string"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(mapString, forKey: .mapString)
try container.encodeIfPresent(mapMapString, forKey: .mapMapString)
}
}

View File

@@ -16,5 +16,19 @@ public struct Animal: Codable, Hashable {
self.className = className
self.color = color
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case className
case color
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(className, forKey: .className)
try container.encodeIfPresent(color, forKey: .color)
}
}

View File

@@ -18,5 +18,21 @@ public struct ApiResponse: Codable, Hashable {
self.type = type
self.message = message
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case code
case type
case message
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(code, forKey: .code)
try container.encodeIfPresent(type, forKey: .type)
try container.encodeIfPresent(message, forKey: .message)
}
}

View File

@@ -14,9 +14,17 @@ public struct ArrayOfArrayOfNumberOnly: Codable, Hashable {
public init(arrayArrayNumber: [[Double]]? = nil) {
self.arrayArrayNumber = arrayArrayNumber
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case arrayArrayNumber = "ArrayArrayNumber"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(arrayArrayNumber, forKey: .arrayArrayNumber)
}
}

View File

@@ -14,9 +14,17 @@ public struct ArrayOfNumberOnly: Codable, Hashable {
public init(arrayNumber: [Double]? = nil) {
self.arrayNumber = arrayNumber
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case arrayNumber = "ArrayNumber"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(arrayNumber, forKey: .arrayNumber)
}
}

View File

@@ -18,11 +18,21 @@ public struct ArrayTest: Codable, Hashable {
self.arrayArrayOfInteger = arrayArrayOfInteger
self.arrayArrayOfModel = arrayArrayOfModel
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case arrayOfString = "array_of_string"
case arrayArrayOfInteger = "array_array_of_integer"
case arrayArrayOfModel = "array_array_of_model"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(arrayOfString, forKey: .arrayOfString)
try container.encodeIfPresent(arrayArrayOfInteger, forKey: .arrayArrayOfInteger)
try container.encodeIfPresent(arrayArrayOfModel, forKey: .arrayArrayOfModel)
}
}

View File

@@ -25,7 +25,6 @@ public struct Capitalization: Codable, Hashable {
self.sCAETHFlowPoints = sCAETHFlowPoints
self.ATT_NAME = ATT_NAME
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case smallCamel
case capitalCamel = "CapitalCamel"
@@ -35,4 +34,18 @@ public struct Capitalization: Codable, Hashable {
case ATT_NAME
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(smallCamel, forKey: .smallCamel)
try container.encodeIfPresent(capitalCamel, forKey: .capitalCamel)
try container.encodeIfPresent(smallSnake, forKey: .smallSnake)
try container.encodeIfPresent(capitalSnake, forKey: .capitalSnake)
try container.encodeIfPresent(sCAETHFlowPoints, forKey: .sCAETHFlowPoints)
try container.encodeIfPresent(ATT_NAME, forKey: .ATT_NAME)
}
}

View File

@@ -18,5 +18,21 @@ public struct Cat: Codable, Hashable {
self.color = color
self.declawed = declawed
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case className
case color
case declawed
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(className, forKey: .className)
try container.encodeIfPresent(color, forKey: .color)
try container.encodeIfPresent(declawed, forKey: .declawed)
}
}

View File

@@ -14,5 +14,17 @@ public struct CatAllOf: Codable, Hashable {
public init(declawed: Bool? = nil) {
self.declawed = declawed
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case declawed
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(declawed, forKey: .declawed)
}
}

View File

@@ -10,11 +10,25 @@ import Foundation
public struct Category: Codable, Hashable {
public var id: Int64?
public var name: String = "default-name"
public var name: String? = "default-name"
public init(id: Int64? = nil, name: String = "default-name") {
public init(id: Int64? = nil, name: String? = "default-name") {
self.id = id
self.name = name
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case id
case name
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(id, forKey: .id)
try container.encode(name, forKey: .name)
}
}

View File

@@ -15,5 +15,17 @@ public struct ClassModel: Codable, Hashable {
public init(_class: String? = nil) {
self._class = _class
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case _class
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(_class, forKey: ._class)
}
}

View File

@@ -14,5 +14,17 @@ public struct Client: Codable, Hashable {
public init(client: String? = nil) {
self.client = client
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case client
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(client, forKey: .client)
}
}

View File

@@ -18,5 +18,21 @@ public struct Dog: Codable, Hashable {
self.color = color
self.breed = breed
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case className
case color
case breed
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(className, forKey: .className)
try container.encodeIfPresent(color, forKey: .color)
try container.encodeIfPresent(breed, forKey: .breed)
}
}

View File

@@ -14,5 +14,17 @@ public struct DogAllOf: Codable, Hashable {
public init(breed: String? = nil) {
self.breed = breed
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case breed
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(breed, forKey: .breed)
}
}

View File

@@ -24,10 +24,19 @@ public struct EnumArrays: Codable, Hashable {
self.justSymbol = justSymbol
self.arrayEnum = arrayEnum
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case justSymbol = "just_symbol"
case arrayEnum = "array_enum"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(justSymbol, forKey: .justSymbol)
try container.encodeIfPresent(arrayEnum, forKey: .arrayEnum)
}
}

View File

@@ -40,7 +40,6 @@ public struct EnumTest: Codable, Hashable {
self.enumNumber = enumNumber
self.outerEnum = outerEnum
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case enumString = "enum_string"
case enumStringRequired = "enum_string_required"
@@ -49,4 +48,17 @@ public struct EnumTest: Codable, Hashable {
case outerEnum
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(enumString, forKey: .enumString)
try container.encode(enumStringRequired, forKey: .enumStringRequired)
try container.encodeIfPresent(enumInteger, forKey: .enumInteger)
try container.encodeIfPresent(enumNumber, forKey: .enumNumber)
try container.encodeIfPresent(outerEnum, forKey: .outerEnum)
}
}

View File

@@ -16,5 +16,17 @@ public struct File: Codable, Hashable {
public init(sourceURI: String? = nil) {
self.sourceURI = sourceURI
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case sourceURI
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(sourceURI, forKey: .sourceURI)
}
}

View File

@@ -16,5 +16,19 @@ public struct FileSchemaTestClass: Codable, Hashable {
self.file = file
self.files = files
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case file
case files
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(file, forKey: .file)
try container.encodeIfPresent(files, forKey: .files)
}
}

View File

@@ -38,5 +38,41 @@ public struct FormatTest: Codable, Hashable {
self.uuid = uuid
self.password = password
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case integer
case int32
case int64
case number
case float
case double
case string
case byte
case binary
case date
case dateTime
case uuid
case password
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(integer, forKey: .integer)
try container.encodeIfPresent(int32, forKey: .int32)
try container.encodeIfPresent(int64, forKey: .int64)
try container.encode(number, forKey: .number)
try container.encodeIfPresent(float, forKey: .float)
try container.encodeIfPresent(double, forKey: .double)
try container.encodeIfPresent(string, forKey: .string)
try container.encode(byte, forKey: .byte)
try container.encodeIfPresent(binary, forKey: .binary)
try container.encode(date, forKey: .date)
try container.encodeIfPresent(dateTime, forKey: .dateTime)
try container.encodeIfPresent(uuid, forKey: .uuid)
try container.encode(password, forKey: .password)
}
}

View File

@@ -16,5 +16,19 @@ public struct HasOnlyReadOnly: Codable, Hashable {
self.bar = bar
self.foo = foo
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case bar
case foo
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(bar, forKey: .bar)
try container.encodeIfPresent(foo, forKey: .foo)
}
}

View File

@@ -14,9 +14,17 @@ public struct List: Codable, Hashable {
public init(_123list: String? = nil) {
self._123list = _123list
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case _123list = "123-list"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(_123list, forKey: ._123list)
}
}

View File

@@ -24,7 +24,6 @@ public struct MapTest: Codable, Hashable {
self.directMap = directMap
self.indirectMap = indirectMap
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case mapMapOfString = "map_map_of_string"
case mapOfEnumString = "map_of_enum_string"
@@ -32,4 +31,16 @@ public struct MapTest: Codable, Hashable {
case indirectMap = "indirect_map"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(mapMapOfString, forKey: .mapMapOfString)
try container.encodeIfPresent(mapOfEnumString, forKey: .mapOfEnumString)
try container.encodeIfPresent(directMap, forKey: .directMap)
try container.encodeIfPresent(indirectMap, forKey: .indirectMap)
}
}

View File

@@ -18,5 +18,21 @@ public struct MixedPropertiesAndAdditionalPropertiesClass: Codable, Hashable {
self.dateTime = dateTime
self.map = map
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case uuid
case dateTime
case map
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(uuid, forKey: .uuid)
try container.encodeIfPresent(dateTime, forKey: .dateTime)
try container.encodeIfPresent(map, forKey: .map)
}
}

View File

@@ -17,10 +17,19 @@ public struct Model200Response: Codable, Hashable {
self.name = name
self._class = _class
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case name
case _class = "class"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(name, forKey: .name)
try container.encodeIfPresent(_class, forKey: ._class)
}
}

View File

@@ -21,7 +21,6 @@ public struct Name: Codable, Hashable {
self.property = property
self._123number = _123number
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case name
case snakeCase = "snake_case"
@@ -29,4 +28,16 @@ public struct Name: Codable, Hashable {
case _123number = "123Number"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(name, forKey: .name)
try container.encodeIfPresent(snakeCase, forKey: .snakeCase)
try container.encodeIfPresent(property, forKey: .property)
try container.encodeIfPresent(_123number, forKey: ._123number)
}
}

View File

@@ -14,9 +14,17 @@ public struct NumberOnly: Codable, Hashable {
public init(justNumber: Double? = nil) {
self.justNumber = justNumber
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case justNumber = "JustNumber"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(justNumber, forKey: .justNumber)
}
}

View File

@@ -30,5 +30,27 @@ public struct Order: Codable, Hashable {
self.status = status
self.complete = complete
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case id
case petId
case quantity
case shipDate
case status
case complete
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(id, forKey: .id)
try container.encodeIfPresent(petId, forKey: .petId)
try container.encodeIfPresent(quantity, forKey: .quantity)
try container.encodeIfPresent(shipDate, forKey: .shipDate)
try container.encodeIfPresent(status, forKey: .status)
try container.encodeIfPresent(complete, forKey: .complete)
}
}

View File

@@ -18,11 +18,21 @@ public struct OuterComposite: Codable, Hashable {
self.myString = myString
self.myBoolean = myBoolean
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case myNumber = "my_number"
case myString = "my_string"
case myBoolean = "my_boolean"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(myNumber, forKey: .myNumber)
try container.encodeIfPresent(myString, forKey: .myString)
try container.encodeIfPresent(myBoolean, forKey: .myBoolean)
}
}

View File

@@ -30,5 +30,27 @@ public struct Pet: Codable, Hashable {
self.tags = tags
self.status = status
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case id
case category
case name
case photoUrls
case tags
case status
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(id, forKey: .id)
try container.encodeIfPresent(category, forKey: .category)
try container.encode(name, forKey: .name)
try container.encode(photoUrls, forKey: .photoUrls)
try container.encodeIfPresent(tags, forKey: .tags)
try container.encodeIfPresent(status, forKey: .status)
}
}

View File

@@ -16,5 +16,19 @@ public struct ReadOnlyFirst: Codable, Hashable {
self.bar = bar
self.baz = baz
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case bar
case baz
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(bar, forKey: .bar)
try container.encodeIfPresent(baz, forKey: .baz)
}
}

View File

@@ -15,9 +15,17 @@ public struct Return: Codable, Hashable {
public init(_return: Int? = nil) {
self._return = _return
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case _return = "return"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(_return, forKey: ._return)
}
}

View File

@@ -14,9 +14,17 @@ public struct SpecialModelName: Codable, Hashable {
public init(specialPropertyName: Int64? = nil) {
self.specialPropertyName = specialPropertyName
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case specialPropertyName = "$special[property.name]"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(specialPropertyName, forKey: .specialPropertyName)
}
}

View File

@@ -9,6 +9,8 @@ import Foundation
public struct StringBooleanMap: Codable, Hashable {
public enum CodingKeys: CodingKey, CaseIterable {
}
public var additionalProperties: [String: Bool] = [:]
public subscript(key: String) -> Bool? {
@@ -27,10 +29,9 @@ public struct StringBooleanMap: Codable, Hashable {
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: String.self)
try container.encodeMap(additionalProperties)
var container = encoder.container(keyedBy: CodingKeys.self)
var additionalPropertiesContainer = encoder.container(keyedBy: String.self)
try additionalPropertiesContainer.encodeMap(additionalProperties)
}
// Decodable protocol methods
@@ -42,4 +43,5 @@ public struct StringBooleanMap: Codable, Hashable {
additionalProperties = try container.decodeMap(Bool.self, excludedKeys: nonAdditionalPropertyKeys)
}
}

View File

@@ -16,5 +16,19 @@ public struct Tag: Codable, Hashable {
self.id = id
self.name = name
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case id
case name
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(id, forKey: .id)
try container.encodeIfPresent(name, forKey: .name)
}
}

View File

@@ -22,7 +22,6 @@ public struct TypeHolderDefault: Codable, Hashable {
self.boolItem = boolItem
self.arrayItem = arrayItem
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case stringItem = "string_item"
case numberItem = "number_item"
@@ -31,4 +30,17 @@ public struct TypeHolderDefault: Codable, Hashable {
case arrayItem = "array_item"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(stringItem, forKey: .stringItem)
try container.encode(numberItem, forKey: .numberItem)
try container.encode(integerItem, forKey: .integerItem)
try container.encode(boolItem, forKey: .boolItem)
try container.encode(arrayItem, forKey: .arrayItem)
}
}

View File

@@ -22,7 +22,6 @@ public struct TypeHolderExample: Codable, Hashable {
self.boolItem = boolItem
self.arrayItem = arrayItem
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case stringItem = "string_item"
case numberItem = "number_item"
@@ -31,4 +30,17 @@ public struct TypeHolderExample: Codable, Hashable {
case arrayItem = "array_item"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(stringItem, forKey: .stringItem)
try container.encode(numberItem, forKey: .numberItem)
try container.encode(integerItem, forKey: .integerItem)
try container.encode(boolItem, forKey: .boolItem)
try container.encode(arrayItem, forKey: .arrayItem)
}
}

View File

@@ -29,5 +29,31 @@ public struct User: Codable, Hashable {
self.phone = phone
self.userStatus = userStatus
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case id
case username
case firstName
case lastName
case email
case password
case phone
case userStatus
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(id, forKey: .id)
try container.encodeIfPresent(username, forKey: .username)
try container.encodeIfPresent(firstName, forKey: .firstName)
try container.encodeIfPresent(lastName, forKey: .lastName)
try container.encodeIfPresent(email, forKey: .email)
try container.encodeIfPresent(password, forKey: .password)
try container.encodeIfPresent(phone, forKey: .phone)
try container.encodeIfPresent(userStatus, forKey: .userStatus)
}
}

View File

@@ -16,10 +16,19 @@ public struct AdditionalPropertiesClass: Codable, Hashable {
self.mapString = mapString
self.mapMapString = mapMapString
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case mapString = "map_string"
case mapMapString = "map_map_string"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(mapString, forKey: .mapString)
try container.encodeIfPresent(mapMapString, forKey: .mapMapString)
}
}

View File

@@ -16,5 +16,19 @@ public struct Animal: Codable, Hashable {
self.className = className
self.color = color
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case className
case color
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(className, forKey: .className)
try container.encodeIfPresent(color, forKey: .color)
}
}

View File

@@ -18,5 +18,21 @@ public struct ApiResponse: Codable, Hashable {
self.type = type
self.message = message
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case code
case type
case message
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(code, forKey: .code)
try container.encodeIfPresent(type, forKey: .type)
try container.encodeIfPresent(message, forKey: .message)
}
}

View File

@@ -14,9 +14,17 @@ public struct ArrayOfArrayOfNumberOnly: Codable, Hashable {
public init(arrayArrayNumber: [[Double]]? = nil) {
self.arrayArrayNumber = arrayArrayNumber
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case arrayArrayNumber = "ArrayArrayNumber"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(arrayArrayNumber, forKey: .arrayArrayNumber)
}
}

View File

@@ -14,9 +14,17 @@ public struct ArrayOfNumberOnly: Codable, Hashable {
public init(arrayNumber: [Double]? = nil) {
self.arrayNumber = arrayNumber
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case arrayNumber = "ArrayNumber"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(arrayNumber, forKey: .arrayNumber)
}
}

View File

@@ -18,11 +18,21 @@ public struct ArrayTest: Codable, Hashable {
self.arrayArrayOfInteger = arrayArrayOfInteger
self.arrayArrayOfModel = arrayArrayOfModel
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case arrayOfString = "array_of_string"
case arrayArrayOfInteger = "array_array_of_integer"
case arrayArrayOfModel = "array_array_of_model"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(arrayOfString, forKey: .arrayOfString)
try container.encodeIfPresent(arrayArrayOfInteger, forKey: .arrayArrayOfInteger)
try container.encodeIfPresent(arrayArrayOfModel, forKey: .arrayArrayOfModel)
}
}

View File

@@ -25,7 +25,6 @@ public struct Capitalization: Codable, Hashable {
self.sCAETHFlowPoints = sCAETHFlowPoints
self.ATT_NAME = ATT_NAME
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case smallCamel
case capitalCamel = "CapitalCamel"
@@ -35,4 +34,18 @@ public struct Capitalization: Codable, Hashable {
case ATT_NAME
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(smallCamel, forKey: .smallCamel)
try container.encodeIfPresent(capitalCamel, forKey: .capitalCamel)
try container.encodeIfPresent(smallSnake, forKey: .smallSnake)
try container.encodeIfPresent(capitalSnake, forKey: .capitalSnake)
try container.encodeIfPresent(sCAETHFlowPoints, forKey: .sCAETHFlowPoints)
try container.encodeIfPresent(ATT_NAME, forKey: .ATT_NAME)
}
}

View File

@@ -18,5 +18,21 @@ public struct Cat: Codable, Hashable {
self.color = color
self.declawed = declawed
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case className
case color
case declawed
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(className, forKey: .className)
try container.encodeIfPresent(color, forKey: .color)
try container.encodeIfPresent(declawed, forKey: .declawed)
}
}

View File

@@ -14,5 +14,17 @@ public struct CatAllOf: Codable, Hashable {
public init(declawed: Bool? = nil) {
self.declawed = declawed
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case declawed
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(declawed, forKey: .declawed)
}
}

View File

@@ -10,11 +10,25 @@ import Foundation
public struct Category: Codable, Hashable {
public var id: Int64?
public var name: String = "default-name"
public var name: String? = "default-name"
public init(id: Int64? = nil, name: String = "default-name") {
public init(id: Int64? = nil, name: String? = "default-name") {
self.id = id
self.name = name
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case id
case name
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(id, forKey: .id)
try container.encode(name, forKey: .name)
}
}

View File

@@ -15,5 +15,17 @@ public struct ClassModel: Codable, Hashable {
public init(_class: String? = nil) {
self._class = _class
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case _class
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(_class, forKey: ._class)
}
}

View File

@@ -14,5 +14,17 @@ public struct Client: Codable, Hashable {
public init(client: String? = nil) {
self.client = client
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case client
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(client, forKey: .client)
}
}

View File

@@ -18,5 +18,21 @@ public struct Dog: Codable, Hashable {
self.color = color
self.breed = breed
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case className
case color
case breed
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(className, forKey: .className)
try container.encodeIfPresent(color, forKey: .color)
try container.encodeIfPresent(breed, forKey: .breed)
}
}

View File

@@ -14,5 +14,17 @@ public struct DogAllOf: Codable, Hashable {
public init(breed: String? = nil) {
self.breed = breed
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case breed
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(breed, forKey: .breed)
}
}

View File

@@ -24,10 +24,19 @@ public struct EnumArrays: Codable, Hashable {
self.justSymbol = justSymbol
self.arrayEnum = arrayEnum
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case justSymbol = "just_symbol"
case arrayEnum = "array_enum"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(justSymbol, forKey: .justSymbol)
try container.encodeIfPresent(arrayEnum, forKey: .arrayEnum)
}
}

View File

@@ -40,7 +40,6 @@ public struct EnumTest: Codable, Hashable {
self.enumNumber = enumNumber
self.outerEnum = outerEnum
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case enumString = "enum_string"
case enumStringRequired = "enum_string_required"
@@ -49,4 +48,17 @@ public struct EnumTest: Codable, Hashable {
case outerEnum
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(enumString, forKey: .enumString)
try container.encode(enumStringRequired, forKey: .enumStringRequired)
try container.encodeIfPresent(enumInteger, forKey: .enumInteger)
try container.encodeIfPresent(enumNumber, forKey: .enumNumber)
try container.encodeIfPresent(outerEnum, forKey: .outerEnum)
}
}

View File

@@ -16,5 +16,17 @@ public struct File: Codable, Hashable {
public init(sourceURI: String? = nil) {
self.sourceURI = sourceURI
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case sourceURI
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(sourceURI, forKey: .sourceURI)
}
}

View File

@@ -16,5 +16,19 @@ public struct FileSchemaTestClass: Codable, Hashable {
self.file = file
self.files = files
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case file
case files
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(file, forKey: .file)
try container.encodeIfPresent(files, forKey: .files)
}
}

View File

@@ -38,5 +38,41 @@ public struct FormatTest: Codable, Hashable {
self.uuid = uuid
self.password = password
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case integer
case int32
case int64
case number
case float
case double
case string
case byte
case binary
case date
case dateTime
case uuid
case password
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(integer, forKey: .integer)
try container.encodeIfPresent(int32, forKey: .int32)
try container.encodeIfPresent(int64, forKey: .int64)
try container.encode(number, forKey: .number)
try container.encodeIfPresent(float, forKey: .float)
try container.encodeIfPresent(double, forKey: .double)
try container.encodeIfPresent(string, forKey: .string)
try container.encode(byte, forKey: .byte)
try container.encodeIfPresent(binary, forKey: .binary)
try container.encode(date, forKey: .date)
try container.encodeIfPresent(dateTime, forKey: .dateTime)
try container.encodeIfPresent(uuid, forKey: .uuid)
try container.encode(password, forKey: .password)
}
}

View File

@@ -16,5 +16,19 @@ public struct HasOnlyReadOnly: Codable, Hashable {
self.bar = bar
self.foo = foo
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case bar
case foo
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(bar, forKey: .bar)
try container.encodeIfPresent(foo, forKey: .foo)
}
}

View File

@@ -14,9 +14,17 @@ public struct List: Codable, Hashable {
public init(_123list: String? = nil) {
self._123list = _123list
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case _123list = "123-list"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(_123list, forKey: ._123list)
}
}

View File

@@ -24,7 +24,6 @@ public struct MapTest: Codable, Hashable {
self.directMap = directMap
self.indirectMap = indirectMap
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case mapMapOfString = "map_map_of_string"
case mapOfEnumString = "map_of_enum_string"
@@ -32,4 +31,16 @@ public struct MapTest: Codable, Hashable {
case indirectMap = "indirect_map"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(mapMapOfString, forKey: .mapMapOfString)
try container.encodeIfPresent(mapOfEnumString, forKey: .mapOfEnumString)
try container.encodeIfPresent(directMap, forKey: .directMap)
try container.encodeIfPresent(indirectMap, forKey: .indirectMap)
}
}

View File

@@ -18,5 +18,21 @@ public struct MixedPropertiesAndAdditionalPropertiesClass: Codable, Hashable {
self.dateTime = dateTime
self.map = map
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case uuid
case dateTime
case map
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(uuid, forKey: .uuid)
try container.encodeIfPresent(dateTime, forKey: .dateTime)
try container.encodeIfPresent(map, forKey: .map)
}
}

View File

@@ -17,10 +17,19 @@ public struct Model200Response: Codable, Hashable {
self.name = name
self._class = _class
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case name
case _class = "class"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(name, forKey: .name)
try container.encodeIfPresent(_class, forKey: ._class)
}
}

View File

@@ -21,7 +21,6 @@ public struct Name: Codable, Hashable {
self.property = property
self._123number = _123number
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case name
case snakeCase = "snake_case"
@@ -29,4 +28,16 @@ public struct Name: Codable, Hashable {
case _123number = "123Number"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(name, forKey: .name)
try container.encodeIfPresent(snakeCase, forKey: .snakeCase)
try container.encodeIfPresent(property, forKey: .property)
try container.encodeIfPresent(_123number, forKey: ._123number)
}
}

View File

@@ -14,9 +14,17 @@ public struct NumberOnly: Codable, Hashable {
public init(justNumber: Double? = nil) {
self.justNumber = justNumber
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case justNumber = "JustNumber"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(justNumber, forKey: .justNumber)
}
}

View File

@@ -30,5 +30,27 @@ public struct Order: Codable, Hashable {
self.status = status
self.complete = complete
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case id
case petId
case quantity
case shipDate
case status
case complete
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(id, forKey: .id)
try container.encodeIfPresent(petId, forKey: .petId)
try container.encodeIfPresent(quantity, forKey: .quantity)
try container.encodeIfPresent(shipDate, forKey: .shipDate)
try container.encodeIfPresent(status, forKey: .status)
try container.encodeIfPresent(complete, forKey: .complete)
}
}

View File

@@ -18,11 +18,21 @@ public struct OuterComposite: Codable, Hashable {
self.myString = myString
self.myBoolean = myBoolean
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case myNumber = "my_number"
case myString = "my_string"
case myBoolean = "my_boolean"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(myNumber, forKey: .myNumber)
try container.encodeIfPresent(myString, forKey: .myString)
try container.encodeIfPresent(myBoolean, forKey: .myBoolean)
}
}

View File

@@ -30,5 +30,27 @@ public struct Pet: Codable, Hashable {
self.tags = tags
self.status = status
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case id
case category
case name
case photoUrls
case tags
case status
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(id, forKey: .id)
try container.encodeIfPresent(category, forKey: .category)
try container.encode(name, forKey: .name)
try container.encode(photoUrls, forKey: .photoUrls)
try container.encodeIfPresent(tags, forKey: .tags)
try container.encodeIfPresent(status, forKey: .status)
}
}

View File

@@ -16,5 +16,19 @@ public struct ReadOnlyFirst: Codable, Hashable {
self.bar = bar
self.baz = baz
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case bar
case baz
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(bar, forKey: .bar)
try container.encodeIfPresent(baz, forKey: .baz)
}
}

View File

@@ -15,9 +15,17 @@ public struct Return: Codable, Hashable {
public init(_return: Int? = nil) {
self._return = _return
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case _return = "return"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(_return, forKey: ._return)
}
}

View File

@@ -14,9 +14,17 @@ public struct SpecialModelName: Codable, Hashable {
public init(specialPropertyName: Int64? = nil) {
self.specialPropertyName = specialPropertyName
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case specialPropertyName = "$special[property.name]"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(specialPropertyName, forKey: .specialPropertyName)
}
}

View File

@@ -9,6 +9,8 @@ import Foundation
public struct StringBooleanMap: Codable, Hashable {
public enum CodingKeys: CodingKey, CaseIterable {
}
public var additionalProperties: [String: Bool] = [:]
public subscript(key: String) -> Bool? {
@@ -27,10 +29,9 @@ public struct StringBooleanMap: Codable, Hashable {
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: String.self)
try container.encodeMap(additionalProperties)
var container = encoder.container(keyedBy: CodingKeys.self)
var additionalPropertiesContainer = encoder.container(keyedBy: String.self)
try additionalPropertiesContainer.encodeMap(additionalProperties)
}
// Decodable protocol methods
@@ -42,4 +43,5 @@ public struct StringBooleanMap: Codable, Hashable {
additionalProperties = try container.decodeMap(Bool.self, excludedKeys: nonAdditionalPropertyKeys)
}
}

View File

@@ -16,5 +16,19 @@ public struct Tag: Codable, Hashable {
self.id = id
self.name = name
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case id
case name
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(id, forKey: .id)
try container.encodeIfPresent(name, forKey: .name)
}
}

View File

@@ -22,7 +22,6 @@ public struct TypeHolderDefault: Codable, Hashable {
self.boolItem = boolItem
self.arrayItem = arrayItem
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case stringItem = "string_item"
case numberItem = "number_item"
@@ -31,4 +30,17 @@ public struct TypeHolderDefault: Codable, Hashable {
case arrayItem = "array_item"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(stringItem, forKey: .stringItem)
try container.encode(numberItem, forKey: .numberItem)
try container.encode(integerItem, forKey: .integerItem)
try container.encode(boolItem, forKey: .boolItem)
try container.encode(arrayItem, forKey: .arrayItem)
}
}

View File

@@ -22,7 +22,6 @@ public struct TypeHolderExample: Codable, Hashable {
self.boolItem = boolItem
self.arrayItem = arrayItem
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case stringItem = "string_item"
case numberItem = "number_item"
@@ -31,4 +30,17 @@ public struct TypeHolderExample: Codable, Hashable {
case arrayItem = "array_item"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(stringItem, forKey: .stringItem)
try container.encode(numberItem, forKey: .numberItem)
try container.encode(integerItem, forKey: .integerItem)
try container.encode(boolItem, forKey: .boolItem)
try container.encode(arrayItem, forKey: .arrayItem)
}
}

View File

@@ -29,5 +29,31 @@ public struct User: Codable, Hashable {
self.phone = phone
self.userStatus = userStatus
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case id
case username
case firstName
case lastName
case email
case password
case phone
case userStatus
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(id, forKey: .id)
try container.encodeIfPresent(username, forKey: .username)
try container.encodeIfPresent(firstName, forKey: .firstName)
try container.encodeIfPresent(lastName, forKey: .lastName)
try container.encodeIfPresent(email, forKey: .email)
try container.encodeIfPresent(password, forKey: .password)
try container.encodeIfPresent(phone, forKey: .phone)
try container.encodeIfPresent(userStatus, forKey: .userStatus)
}
}

View File

@@ -16,10 +16,19 @@ public struct AdditionalPropertiesClass: Codable, Hashable {
self.mapString = mapString
self.mapMapString = mapMapString
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case mapString = "map_string"
case mapMapString = "map_map_string"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(mapString, forKey: .mapString)
try container.encodeIfPresent(mapMapString, forKey: .mapMapString)
}
}

View File

@@ -16,5 +16,19 @@ public struct Animal: Codable, Hashable {
self.className = className
self.color = color
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case className
case color
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(className, forKey: .className)
try container.encodeIfPresent(color, forKey: .color)
}
}

View File

@@ -18,5 +18,21 @@ public struct ApiResponse: Codable, Hashable {
self.type = type
self.message = message
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case code
case type
case message
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(code, forKey: .code)
try container.encodeIfPresent(type, forKey: .type)
try container.encodeIfPresent(message, forKey: .message)
}
}

View File

@@ -14,9 +14,17 @@ public struct ArrayOfArrayOfNumberOnly: Codable, Hashable {
public init(arrayArrayNumber: [[Double]]? = nil) {
self.arrayArrayNumber = arrayArrayNumber
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case arrayArrayNumber = "ArrayArrayNumber"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(arrayArrayNumber, forKey: .arrayArrayNumber)
}
}

View File

@@ -14,9 +14,17 @@ public struct ArrayOfNumberOnly: Codable, Hashable {
public init(arrayNumber: [Double]? = nil) {
self.arrayNumber = arrayNumber
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case arrayNumber = "ArrayNumber"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(arrayNumber, forKey: .arrayNumber)
}
}

View File

@@ -18,11 +18,21 @@ public struct ArrayTest: Codable, Hashable {
self.arrayArrayOfInteger = arrayArrayOfInteger
self.arrayArrayOfModel = arrayArrayOfModel
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case arrayOfString = "array_of_string"
case arrayArrayOfInteger = "array_array_of_integer"
case arrayArrayOfModel = "array_array_of_model"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(arrayOfString, forKey: .arrayOfString)
try container.encodeIfPresent(arrayArrayOfInteger, forKey: .arrayArrayOfInteger)
try container.encodeIfPresent(arrayArrayOfModel, forKey: .arrayArrayOfModel)
}
}

View File

@@ -25,7 +25,6 @@ public struct Capitalization: Codable, Hashable {
self.sCAETHFlowPoints = sCAETHFlowPoints
self.ATT_NAME = ATT_NAME
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case smallCamel
case capitalCamel = "CapitalCamel"
@@ -35,4 +34,18 @@ public struct Capitalization: Codable, Hashable {
case ATT_NAME
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(smallCamel, forKey: .smallCamel)
try container.encodeIfPresent(capitalCamel, forKey: .capitalCamel)
try container.encodeIfPresent(smallSnake, forKey: .smallSnake)
try container.encodeIfPresent(capitalSnake, forKey: .capitalSnake)
try container.encodeIfPresent(sCAETHFlowPoints, forKey: .sCAETHFlowPoints)
try container.encodeIfPresent(ATT_NAME, forKey: .ATT_NAME)
}
}

View File

@@ -18,5 +18,21 @@ public struct Cat: Codable, Hashable {
self.color = color
self.declawed = declawed
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case className
case color
case declawed
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(className, forKey: .className)
try container.encodeIfPresent(color, forKey: .color)
try container.encodeIfPresent(declawed, forKey: .declawed)
}
}

View File

@@ -14,5 +14,17 @@ public struct CatAllOf: Codable, Hashable {
public init(declawed: Bool? = nil) {
self.declawed = declawed
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case declawed
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(declawed, forKey: .declawed)
}
}

View File

@@ -10,11 +10,25 @@ import Foundation
public struct Category: Codable, Hashable {
public var id: Int64?
public var name: String = "default-name"
public var name: String? = "default-name"
public init(id: Int64? = nil, name: String = "default-name") {
public init(id: Int64? = nil, name: String? = "default-name") {
self.id = id
self.name = name
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case id
case name
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(id, forKey: .id)
try container.encode(name, forKey: .name)
}
}

View File

@@ -15,5 +15,17 @@ public struct ClassModel: Codable, Hashable {
public init(_class: String? = nil) {
self._class = _class
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case _class
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(_class, forKey: ._class)
}
}

View File

@@ -14,5 +14,17 @@ public struct Client: Codable, Hashable {
public init(client: String? = nil) {
self.client = client
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case client
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(client, forKey: .client)
}
}

View File

@@ -18,5 +18,21 @@ public struct Dog: Codable, Hashable {
self.color = color
self.breed = breed
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case className
case color
case breed
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(className, forKey: .className)
try container.encodeIfPresent(color, forKey: .color)
try container.encodeIfPresent(breed, forKey: .breed)
}
}

View File

@@ -14,5 +14,17 @@ public struct DogAllOf: Codable, Hashable {
public init(breed: String? = nil) {
self.breed = breed
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case breed
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(breed, forKey: .breed)
}
}

View File

@@ -24,10 +24,19 @@ public struct EnumArrays: Codable, Hashable {
self.justSymbol = justSymbol
self.arrayEnum = arrayEnum
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case justSymbol = "just_symbol"
case arrayEnum = "array_enum"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(justSymbol, forKey: .justSymbol)
try container.encodeIfPresent(arrayEnum, forKey: .arrayEnum)
}
}

View File

@@ -40,7 +40,6 @@ public struct EnumTest: Codable, Hashable {
self.enumNumber = enumNumber
self.outerEnum = outerEnum
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case enumString = "enum_string"
case enumStringRequired = "enum_string_required"
@@ -49,4 +48,17 @@ public struct EnumTest: Codable, Hashable {
case outerEnum
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(enumString, forKey: .enumString)
try container.encode(enumStringRequired, forKey: .enumStringRequired)
try container.encodeIfPresent(enumInteger, forKey: .enumInteger)
try container.encodeIfPresent(enumNumber, forKey: .enumNumber)
try container.encodeIfPresent(outerEnum, forKey: .outerEnum)
}
}

View File

@@ -16,5 +16,17 @@ public struct File: Codable, Hashable {
public init(sourceURI: String? = nil) {
self.sourceURI = sourceURI
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case sourceURI
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(sourceURI, forKey: .sourceURI)
}
}

View File

@@ -16,5 +16,19 @@ public struct FileSchemaTestClass: Codable, Hashable {
self.file = file
self.files = files
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case file
case files
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(file, forKey: .file)
try container.encodeIfPresent(files, forKey: .files)
}
}

View File

@@ -38,5 +38,41 @@ public struct FormatTest: Codable, Hashable {
self.uuid = uuid
self.password = password
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case integer
case int32
case int64
case number
case float
case double
case string
case byte
case binary
case date
case dateTime
case uuid
case password
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(integer, forKey: .integer)
try container.encodeIfPresent(int32, forKey: .int32)
try container.encodeIfPresent(int64, forKey: .int64)
try container.encode(number, forKey: .number)
try container.encodeIfPresent(float, forKey: .float)
try container.encodeIfPresent(double, forKey: .double)
try container.encodeIfPresent(string, forKey: .string)
try container.encode(byte, forKey: .byte)
try container.encodeIfPresent(binary, forKey: .binary)
try container.encode(date, forKey: .date)
try container.encodeIfPresent(dateTime, forKey: .dateTime)
try container.encodeIfPresent(uuid, forKey: .uuid)
try container.encode(password, forKey: .password)
}
}

View File

@@ -16,5 +16,19 @@ public struct HasOnlyReadOnly: Codable, Hashable {
self.bar = bar
self.foo = foo
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case bar
case foo
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(bar, forKey: .bar)
try container.encodeIfPresent(foo, forKey: .foo)
}
}

View File

@@ -14,9 +14,17 @@ public struct List: Codable, Hashable {
public init(_123list: String? = nil) {
self._123list = _123list
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case _123list = "123-list"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(_123list, forKey: ._123list)
}
}

View File

@@ -24,7 +24,6 @@ public struct MapTest: Codable, Hashable {
self.directMap = directMap
self.indirectMap = indirectMap
}
public enum CodingKeys: String, CodingKey, CaseIterable {
case mapMapOfString = "map_map_of_string"
case mapOfEnumString = "map_of_enum_string"
@@ -32,4 +31,16 @@ public struct MapTest: Codable, Hashable {
case indirectMap = "indirect_map"
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(mapMapOfString, forKey: .mapMapOfString)
try container.encodeIfPresent(mapOfEnumString, forKey: .mapOfEnumString)
try container.encodeIfPresent(directMap, forKey: .directMap)
try container.encodeIfPresent(indirectMap, forKey: .indirectMap)
}
}

Some files were not shown because too many files have changed in this diff Show More