Support object schemas with only additionalProperties. (#6492)

Previously, we had implemented the Codable protocol by simply claiming conformance, and making sure that each of our internal classes also implemented the Codable protocol. So our model classes looked like:

class MyModel: Codable {
   var propInt: Int
   var propString: String
}

class MyOtherModel: Codable {
   var propModel: MyModel
}

Previously, our additionalProperties implementation would have meant an object schema with an additionalProperties of Int type would have looked like:

class MyModelWithAdditionalProperties: Codable {
   var additionalProperties: [String: Int]
}

But the default implementation of Codable would have serialized MyModelWithAdditionalProperties like this:

{
  "additionalProperties": {
    "myInt1": 1,
    "myInt2": 2,
    "myInt3": 3
  }
}

The default implementation would put the additionalProperties in its own dictionary (which would be incorrect), as opposed to the desired serialization of:

{
  "myInt1": 1,
  "myInt2": 2,
  "myInt3": 3
}

So therefore, the only way to support this was to do our own implementation of the Codable protocol. The Codable protocol is actually two protocols: Encodable and Decodable.

So therefore, this change generates implementations of Encodable and Decodable for each generated model class. So the new generated classes look like:

class MyModel: Codable {
   var propInt: Int
   var propString: String

   // Encodable protocol methods

   public func encode(to encoder: Encoder) throws {

        var container = encoder.container(keyedBy: String.self)

        try container.encode(propInt, forKey: "propInt")
        try container.encode(propString, forKey: "propString")
    }

    // Decodable protocol methods

    public required init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: String.self)

        propInt = try container.decode(Int.self, forKey: "propInt")
        propString = try container.decode(String.self, forKey: "propString")
    }

}

class MyOtherModel: Codable {
   var propModel: MyModel

   // Encodable protocol methods

   public func encode(to encoder: Encoder) throws {

        var container = encoder.container(keyedBy: String.self)

        try container.encode(propModel, forKey: "propModel")
    }

    // Decodable protocol methods

    public required init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: String.self)

        propModel = try container.decode(MyModel.self, forKey: "propModel")
    }

}
This commit is contained in:
ehyche
2017-09-18 13:04:50 -04:00
committed by wing328
parent 8067612e06
commit b807f6ff96
40 changed files with 814 additions and 247 deletions

View File

@@ -30,60 +30,85 @@ open class Swift4TestAPI {
- This endpoint tests get a dictionary which contains examples of all of the models.
- examples: [{contentType=application/json, example={
"myPrimitive" : {
"myDateTimeArray" : [ "2000-01-23T04:56:07.000+00:00" ],
"myStringArray" : [ "aeiou" ],
"myDateTimeArray" : [ "2000-01-23T04:56:07.000+00:00", "2000-01-23T04:56:07.000+00:00" ],
"myStringArray" : [ "myStringArray", "myStringArray" ],
"myFile" : "",
"myFloatArray" : [ 2.302136 ],
"myBytes" : "aeiou",
"myFloatArray" : [ 2.302136, 2.302136 ],
"myBytes" : "myBytes",
"myLong" : 1,
"myBooleanArray" : [ true ],
"myDoubleArray" : [ 9.301444243932576 ],
"myBooleanArray" : [ true, true ],
"myDoubleArray" : [ 9.301444243932576, 9.301444243932576 ],
"myInteger" : 0,
"myString" : "aeiou",
"myBytesArray" : [ "aeiou" ],
"myString" : "myString",
"myBytesArray" : [ "myBytesArray", "myBytesArray" ],
"myDouble" : 7.061401241503109,
"myDate" : "2000-01-23",
"myDateArray" : [ "2000-01-23" ],
"myDateArray" : [ "2000-01-23", "2000-01-23" ],
"myDateTime" : "2000-01-23T04:56:07.000+00:00",
"myLongArray" : [ 5 ],
"myIntegerArray" : [ 6 ],
"myLongArray" : [ 5, 5 ],
"myIntegerArray" : [ 6, 6 ],
"myUUID" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"myBoolean" : true,
"myFileArray" : [ "" ],
"myFileArray" : [ "", "" ],
"myStringEnum" : { },
"myFloat" : 5.637377,
"myStringEnumArray" : [ null ],
"myUUIDArray" : [ "046b6c7f-0b8a-43b9-b35d-6489e6daee91" ]
"myStringEnumArray" : [ null, null ],
"myUUIDArray" : [ "046b6c7f-0b8a-43b9-b35d-6489e6daee91", "046b6c7f-0b8a-43b9-b35d-6489e6daee91" ]
},
"myVariableNameTest" : {
"for" : "aeiou",
"example_name" : "aeiou"
"for" : "for",
"example_name" : "example_name"
},
"myPrimitiveArray" : [ {
"myDateTimeArray" : [ "2000-01-23T04:56:07.000+00:00" ],
"myStringArray" : [ "aeiou" ],
"myDateTimeArray" : [ "2000-01-23T04:56:07.000+00:00", "2000-01-23T04:56:07.000+00:00" ],
"myStringArray" : [ "myStringArray", "myStringArray" ],
"myFile" : "",
"myFloatArray" : [ 2.302136 ],
"myBytes" : "aeiou",
"myFloatArray" : [ 2.302136, 2.302136 ],
"myBytes" : "myBytes",
"myLong" : 1,
"myBooleanArray" : [ true ],
"myDoubleArray" : [ 9.301444243932576 ],
"myBooleanArray" : [ true, true ],
"myDoubleArray" : [ 9.301444243932576, 9.301444243932576 ],
"myInteger" : 0,
"myString" : "aeiou",
"myBytesArray" : [ "aeiou" ],
"myString" : "myString",
"myBytesArray" : [ "myBytesArray", "myBytesArray" ],
"myDouble" : 7.061401241503109,
"myDate" : "2000-01-23",
"myDateArray" : [ "2000-01-23" ],
"myDateArray" : [ "2000-01-23", "2000-01-23" ],
"myDateTime" : "2000-01-23T04:56:07.000+00:00",
"myLongArray" : [ 5 ],
"myIntegerArray" : [ 6 ],
"myLongArray" : [ 5, 5 ],
"myIntegerArray" : [ 6, 6 ],
"myUUID" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"myBoolean" : true,
"myFileArray" : [ "" ],
"myFileArray" : [ "", "" ],
"myStringEnum" : { },
"myFloat" : 5.637377,
"myStringEnumArray" : [ null ],
"myUUIDArray" : [ "046b6c7f-0b8a-43b9-b35d-6489e6daee91" ]
"myStringEnumArray" : [ null, null ],
"myUUIDArray" : [ "046b6c7f-0b8a-43b9-b35d-6489e6daee91", "046b6c7f-0b8a-43b9-b35d-6489e6daee91" ]
}, {
"myDateTimeArray" : [ "2000-01-23T04:56:07.000+00:00", "2000-01-23T04:56:07.000+00:00" ],
"myStringArray" : [ "myStringArray", "myStringArray" ],
"myFile" : "",
"myFloatArray" : [ 2.302136, 2.302136 ],
"myBytes" : "myBytes",
"myLong" : 1,
"myBooleanArray" : [ true, true ],
"myDoubleArray" : [ 9.301444243932576, 9.301444243932576 ],
"myInteger" : 0,
"myString" : "myString",
"myBytesArray" : [ "myBytesArray", "myBytesArray" ],
"myDouble" : 7.061401241503109,
"myDate" : "2000-01-23",
"myDateArray" : [ "2000-01-23", "2000-01-23" ],
"myDateTime" : "2000-01-23T04:56:07.000+00:00",
"myLongArray" : [ 5, 5 ],
"myIntegerArray" : [ 6, 6 ],
"myUUID" : "046b6c7f-0b8a-43b9-b35d-6489e6daee91",
"myBoolean" : true,
"myFileArray" : [ "", "" ],
"myStringEnum" : { },
"myFloat" : 5.637377,
"myStringEnumArray" : [ null, null ],
"myUUIDArray" : [ "046b6c7f-0b8a-43b9-b35d-6489e6daee91", "046b6c7f-0b8a-43b9-b35d-6489e6daee91" ]
} ]
}}]

View File

@@ -16,7 +16,7 @@ open class CodableHelper {
var returnedError: Error? = nil
let decoder = JSONDecoder()
decoder.dataDecodingStrategy = .base64Decode
decoder.dataDecodingStrategy = .base64
if #available(iOS 10.0, *) {
decoder.dateDecodingStrategy = .iso8601
}
@@ -38,7 +38,7 @@ open class CodableHelper {
if prettyPrint {
encoder.outputFormatting = .prettyPrinted
}
encoder.dataEncodingStrategy = .base64Encode
encoder.dataEncodingStrategy = .base64
if #available(iOS 10.0, *) {
encoder.dateEncodingStrategy = .iso8601
}

View File

@@ -84,4 +84,90 @@ extension UUID: JSONEncodable {
}
}
extension String: CodingKey {
public var stringValue: String {
return self
}
public init?(stringValue: String) {
self.init(stringLiteral: stringValue)
}
public var intValue: Int? {
return nil
}
public init?(intValue: Int) {
return nil
}
}
extension KeyedEncodingContainerProtocol {
public mutating func encodeArray<T>(_ values: [T], forKey key: Self.Key) throws where T : Encodable {
var arrayContainer = nestedUnkeyedContainer(forKey: key)
try arrayContainer.encode(contentsOf: values)
}
public mutating func encodeArrayIfPresent<T>(_ values: [T]?, forKey key: Self.Key) throws where T : Encodable {
if let values = values {
try encodeArray(values, forKey: key)
}
}
public mutating func encodeMap<T>(_ pairs: [Self.Key: T]) throws where T : Encodable {
for (key, value) in pairs {
try encode(value, forKey: key)
}
}
public mutating func encodeMapIfPresent<T>(_ pairs: [Self.Key: T]?) throws where T : Encodable {
if let pairs = pairs {
try encodeMap(pairs)
}
}
}
extension KeyedDecodingContainerProtocol {
public func decodeArray<T>(_ type: T.Type, forKey key: Self.Key) throws -> [T] where T : Decodable {
var tmpArray = [T]()
var nestedContainer = try nestedUnkeyedContainer(forKey: key)
while !nestedContainer.isAtEnd {
let arrayValue = try nestedContainer.decode(T.self)
tmpArray.append(arrayValue)
}
return tmpArray
}
public func decodeArrayIfPresent<T>(_ type: T.Type, forKey key: Self.Key) throws -> [T]? where T : Decodable {
var tmpArray: [T]? = nil
if contains(key) {
tmpArray = try decodeArray(T.self, forKey: key)
}
return tmpArray
}
public func decodeMap<T>(_ type: T.Type, excludedKeys: Set<Self.Key>) throws -> [Self.Key: T] where T : Decodable {
var map: [Self.Key : T] = [:]
for key in allKeys {
if !excludedKeys.contains(key) {
let value = try decode(T.self, forKey: key)
map[key] = value
}
}
return map
}
}

View File

@@ -9,6 +9,7 @@ import Foundation
/** Object which contains lots of different primitive Swagger types */
open class AllPrimitives: Codable {
public var myInteger: Int?
@@ -36,34 +37,68 @@ open class AllPrimitives: Codable {
public var myStringEnum: StringEnum?
public var myStringEnumArray: [StringEnum]?
public init() {}
// Encodable protocol methods
private enum CodingKeys: String, CodingKey {
case myInteger = "myInteger"
case myIntegerArray = "myIntegerArray"
case myLong = "myLong"
case myLongArray = "myLongArray"
case myFloat = "myFloat"
case myFloatArray = "myFloatArray"
case myDouble = "myDouble"
case myDoubleArray = "myDoubleArray"
case myString = "myString"
case myStringArray = "myStringArray"
case myBytes = "myBytes"
case myBytesArray = "myBytesArray"
case myBoolean = "myBoolean"
case myBooleanArray = "myBooleanArray"
case myDate = "myDate"
case myDateArray = "myDateArray"
case myDateTime = "myDateTime"
case myDateTimeArray = "myDateTimeArray"
case myFile = "myFile"
case myFileArray = "myFileArray"
case myUUID = "myUUID"
case myUUIDArray = "myUUIDArray"
case myStringEnum = "myStringEnum"
case myStringEnumArray = "myStringEnumArray"
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: String.self)
try container.encodeIfPresent(myInteger, forKey: "myInteger")
try container.encodeArrayIfPresent(myIntegerArray, forKey: "myIntegerArray")
try container.encodeIfPresent(myLong, forKey: "myLong")
try container.encodeArrayIfPresent(myLongArray, forKey: "myLongArray")
try container.encodeIfPresent(myFloat, forKey: "myFloat")
try container.encodeArrayIfPresent(myFloatArray, forKey: "myFloatArray")
try container.encodeIfPresent(myDouble, forKey: "myDouble")
try container.encodeArrayIfPresent(myDoubleArray, forKey: "myDoubleArray")
try container.encodeIfPresent(myString, forKey: "myString")
try container.encodeArrayIfPresent(myStringArray, forKey: "myStringArray")
try container.encodeIfPresent(myBytes, forKey: "myBytes")
try container.encodeArrayIfPresent(myBytesArray, forKey: "myBytesArray")
try container.encodeIfPresent(myBoolean, forKey: "myBoolean")
try container.encodeArrayIfPresent(myBooleanArray, forKey: "myBooleanArray")
try container.encodeIfPresent(myDate, forKey: "myDate")
try container.encodeArrayIfPresent(myDateArray, forKey: "myDateArray")
try container.encodeIfPresent(myDateTime, forKey: "myDateTime")
try container.encodeArrayIfPresent(myDateTimeArray, forKey: "myDateTimeArray")
try container.encodeIfPresent(myFile, forKey: "myFile")
try container.encodeArrayIfPresent(myFileArray, forKey: "myFileArray")
try container.encodeIfPresent(myUUID, forKey: "myUUID")
try container.encodeArrayIfPresent(myUUIDArray, forKey: "myUUIDArray")
try container.encodeIfPresent(myStringEnum, forKey: "myStringEnum")
try container.encodeArrayIfPresent(myStringEnumArray, forKey: "myStringEnumArray")
}
// Decodable protocol methods
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)
myInteger = try container.decodeIfPresent(Int.self, forKey: "myInteger")
myIntegerArray = try container.decodeArrayIfPresent(Int.self, forKey: "myIntegerArray")
myLong = try container.decodeIfPresent(Int64.self, forKey: "myLong")
myLongArray = try container.decodeArrayIfPresent(Int64.self, forKey: "myLongArray")
myFloat = try container.decodeIfPresent(Float.self, forKey: "myFloat")
myFloatArray = try container.decodeArrayIfPresent(Float.self, forKey: "myFloatArray")
myDouble = try container.decodeIfPresent(Double.self, forKey: "myDouble")
myDoubleArray = try container.decodeArrayIfPresent(Double.self, forKey: "myDoubleArray")
myString = try container.decodeIfPresent(String.self, forKey: "myString")
myStringArray = try container.decodeArrayIfPresent(String.self, forKey: "myStringArray")
myBytes = try container.decodeIfPresent(Data.self, forKey: "myBytes")
myBytesArray = try container.decodeArrayIfPresent(Data.self, forKey: "myBytesArray")
myBoolean = try container.decodeIfPresent(Bool.self, forKey: "myBoolean")
myBooleanArray = try container.decodeArrayIfPresent(Bool.self, forKey: "myBooleanArray")
myDate = try container.decodeIfPresent(Date.self, forKey: "myDate")
myDateArray = try container.decodeArrayIfPresent(Date.self, forKey: "myDateArray")
myDateTime = try container.decodeIfPresent(Date.self, forKey: "myDateTime")
myDateTimeArray = try container.decodeArrayIfPresent(Date.self, forKey: "myDateTimeArray")
myFile = try container.decodeIfPresent(URL.self, forKey: "myFile")
myFileArray = try container.decodeArrayIfPresent(URL.self, forKey: "myFileArray")
myUUID = try container.decodeIfPresent(UUID.self, forKey: "myUUID")
myUUIDArray = try container.decodeArrayIfPresent(UUID.self, forKey: "myUUIDArray")
myStringEnum = try container.decodeIfPresent(StringEnum.self, forKey: "myStringEnum")
myStringEnumArray = try container.decodeArrayIfPresent(StringEnum.self, forKey: "myStringEnumArray")
}
}

View File

@@ -9,19 +9,33 @@ import Foundation
/** Example Error object */
open class ErrorInfo: Codable {
public var code: Int?
public var message: String?
public var details: [String]?
public init() {}
// Encodable protocol methods
private enum CodingKeys: String, CodingKey {
case code = "code"
case message = "message"
case details = "details"
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: String.self)
try container.encodeIfPresent(code, forKey: "code")
try container.encodeIfPresent(message, forKey: "message")
try container.encodeArrayIfPresent(details, forKey: "details")
}
// Decodable protocol methods
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)
code = try container.decodeIfPresent(Int.self, forKey: "code")
message = try container.decodeIfPresent(String.self, forKey: "message")
details = try container.decodeArrayIfPresent(String.self, forKey: "details")
}
}

View File

@@ -9,19 +9,33 @@ import Foundation
/** Response object containing AllPrimitives object */
open class GetAllModelsResult: Codable {
public var myPrimitiveArray: [AllPrimitives]?
public var myPrimitive: AllPrimitives?
public var myVariableNameTest: VariableNameTest?
public init() {}
// Encodable protocol methods
private enum CodingKeys: String, CodingKey {
case myPrimitiveArray = "myPrimitiveArray"
case myPrimitive = "myPrimitive"
case myVariableNameTest = "myVariableNameTest"
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: String.self)
try container.encodeArrayIfPresent(myPrimitiveArray, forKey: "myPrimitiveArray")
try container.encodeIfPresent(myPrimitive, forKey: "myPrimitive")
try container.encodeIfPresent(myVariableNameTest, forKey: "myVariableNameTest")
}
// Decodable protocol methods
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)
myPrimitiveArray = try container.decodeArrayIfPresent(AllPrimitives.self, forKey: "myPrimitiveArray")
myPrimitive = try container.decodeIfPresent(AllPrimitives.self, forKey: "myPrimitive")
myVariableNameTest = try container.decodeIfPresent(VariableNameTest.self, forKey: "myVariableNameTest")
}
}

View File

@@ -0,0 +1,49 @@
//
// ModelWithIntAdditionalPropertiesOnly.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//
import Foundation
/** This is an empty model with no properties and only additionalProperties of type int32 */
open class ModelWithIntAdditionalPropertiesOnly: Codable {
public var additionalProperties: [String:Int] = [:]
public subscript(key: String) -> Int? {
get {
if let value = additionalProperties[key] {
return value
}
return nil
}
set {
additionalProperties[key] = newValue
}
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: String.self)
try container.encodeMap(additionalProperties)
}
// Decodable protocol methods
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)
var nonAdditionalPropertyKeys = Set<String>()
additionalProperties = try container.decodeMap(Int.self, excludedKeys: nonAdditionalPropertyKeys)
}
}

View File

@@ -0,0 +1,81 @@
//
// ModelWithPropertiesAndAdditionalProperties.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//
import Foundation
/** This is an empty model with no properties and only additionalProperties of type int32 */
open class ModelWithPropertiesAndAdditionalProperties: Codable {
public var myIntegerReq: Int
public var myIntegerOpt: Int?
public var myPrimitiveReq: AllPrimitives
public var myPrimitiveOpt: AllPrimitives?
public var myStringArrayReq: [String]
public var myStringArrayOpt: [String]?
public var myPrimitiveArrayReq: [AllPrimitives]
public var myPrimitiveArrayOpt: [AllPrimitives]?
public var additionalProperties: [String:String] = [:]
public subscript(key: String) -> String? {
get {
if let value = additionalProperties[key] {
return value
}
return nil
}
set {
additionalProperties[key] = newValue
}
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: String.self)
try container.encode(myIntegerReq, forKey: "myIntegerReq")
try container.encodeIfPresent(myIntegerOpt, forKey: "myIntegerOpt")
try container.encode(myPrimitiveReq, forKey: "myPrimitiveReq")
try container.encodeIfPresent(myPrimitiveOpt, forKey: "myPrimitiveOpt")
try container.encodeArray(myStringArrayReq, forKey: "myStringArrayReq")
try container.encodeArrayIfPresent(myStringArrayOpt, forKey: "myStringArrayOpt")
try container.encodeArray(myPrimitiveArrayReq, forKey: "myPrimitiveArrayReq")
try container.encodeArrayIfPresent(myPrimitiveArrayOpt, forKey: "myPrimitiveArrayOpt")
try container.encodeMap(additionalProperties)
}
// Decodable protocol methods
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)
myIntegerReq = try container.decode(Int.self, forKey: "myIntegerReq")
myIntegerOpt = try container.decodeIfPresent(Int.self, forKey: "myIntegerOpt")
myPrimitiveReq = try container.decode(AllPrimitives.self, forKey: "myPrimitiveReq")
myPrimitiveOpt = try container.decodeIfPresent(AllPrimitives.self, forKey: "myPrimitiveOpt")
myStringArrayReq = try container.decodeArray(String.self, forKey: "myStringArrayReq")
myStringArrayOpt = try container.decodeArrayIfPresent(String.self, forKey: "myStringArrayOpt")
myPrimitiveArrayReq = try container.decodeArray(AllPrimitives.self, forKey: "myPrimitiveArrayReq")
myPrimitiveArrayOpt = try container.decodeArrayIfPresent(AllPrimitives.self, forKey: "myPrimitiveArrayOpt")
var nonAdditionalPropertyKeys = Set<String>()
nonAdditionalPropertyKeys.insert("myIntegerReq")
nonAdditionalPropertyKeys.insert("myIntegerOpt")
nonAdditionalPropertyKeys.insert("myPrimitiveReq")
nonAdditionalPropertyKeys.insert("myPrimitiveOpt")
nonAdditionalPropertyKeys.insert("myStringArrayReq")
nonAdditionalPropertyKeys.insert("myStringArrayOpt")
nonAdditionalPropertyKeys.insert("myPrimitiveArrayReq")
nonAdditionalPropertyKeys.insert("myPrimitiveArrayOpt")
additionalProperties = try container.decodeMap(String.self, excludedKeys: nonAdditionalPropertyKeys)
}
}

View File

@@ -0,0 +1,49 @@
//
// ModelWithStringAdditionalPropertiesOnly.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//
import Foundation
/** This is an empty model with no properties and only additionalProperties of type string */
open class ModelWithStringAdditionalPropertiesOnly: Codable {
public var additionalProperties: [String:String] = [:]
public subscript(key: String) -> String? {
get {
if let value = additionalProperties[key] {
return value
}
return nil
}
set {
additionalProperties[key] = newValue
}
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: String.self)
try container.encodeMap(additionalProperties)
}
// Decodable protocol methods
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)
var nonAdditionalPropertyKeys = Set<String>()
additionalProperties = try container.decodeMap(String.self, excludedKeys: nonAdditionalPropertyKeys)
}
}

View File

@@ -9,6 +9,7 @@ import Foundation
/** This object contains property names which we know will be different from their variable name. Examples of this include snake case property names and property names which are Swift 4 reserved words. */
open class VariableNameTest: Codable {
/** This snake-case examle_name property name should be converted to a camelCase variable name like exampleName */
@@ -16,12 +17,24 @@ open class VariableNameTest: Codable {
/** This property name is a reserved word in most languages, including Swift 4. */
public var _for: String?
public init() {}
// Encodable protocol methods
private enum CodingKeys: String, CodingKey {
case exampleName = "example_name"
case _for = "for"
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: String.self)
try container.encodeIfPresent(exampleName, forKey: "example_name")
try container.encodeIfPresent(_for, forKey: "for")
}
// Decodable protocol methods
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)
exampleName = try container.decodeIfPresent(String.self, forKey: "example_name")
_for = try container.decodeIfPresent(String.self, forKey: "for")
}
}