Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift4: Fix inline enum issue #6640

Merged
merged 4 commits into from
Oct 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ open class {{classname}}: {{#parent}}{{{parent}}}{{/parent}}{{^parent}}Codable{{
}

// Decodable protocol methods

public {{#parent}}override {{/parent}}required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)

{{#vars}}
{{name}} = try container.decode{{#isListContainer}}Array{{/isListContainer}}{{^required}}IfPresent{{/required}}({{#isListContainer}}{{{items.datatype}}}{{/isListContainer}}{{^isListContainer}}{{{datatype}}}{{/isListContainer}}.self, forKey: "{{{baseName}}}")
{{name}} = try container.decode{{#isListContainer}}Array{{/isListContainer}}{{^required}}IfPresent{{/required}}({{#isListContainer}}{{{items.datatype}}}{{/isListContainer}}{{^isListContainer}}{{{datatypeWithEnum}}}{{/isListContainer}}.self, forKey: "{{{baseName}}}")
{{/vars}}
{{#additionalPropertiesType}}
var nonAdditionalPropertyKeys = Set<String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,14 @@
"items": {
"$ref": "#/definitions/StringEnum"
}
},
"myInlineStringEnum": {
"type": "string",
"enum": [
"inlineStringEnumValue1",
"inlineStringEnumValue2",
"inlineStringEnumValue3"
]
}
},
"description": "Object which contains lots of different primitive Swagger types"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,27 @@ open class Swift4TestAPI {
"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,
"myIntegerArray" : [ 6, 6 ],
"myInlineStringEnum" : "inlineStringEnumValue1",
"myFileArray" : [ "", "" ],
"myFloat" : 5.637377,
"myStringEnumArray" : [ null, null ],
"myFloatArray" : [ 2.302136, 2.302136 ],
"myDoubleArray" : [ 9.301444243932576, 9.301444243932576 ],
"myString" : "myString",
"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" ]
},
"myVariableNameTest" : {
Expand All @@ -63,51 +64,53 @@ open class Swift4TestAPI {
"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,
"myIntegerArray" : [ 6, 6 ],
"myInlineStringEnum" : "inlineStringEnumValue1",
"myFileArray" : [ "", "" ],
"myFloat" : 5.637377,
"myStringEnumArray" : [ null, null ],
"myFloatArray" : [ 2.302136, 2.302136 ],
"myDoubleArray" : [ 9.301444243932576, 9.301444243932576 ],
"myString" : "myString",
"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" ]
}, {
"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,
"myIntegerArray" : [ 6, 6 ],
"myInlineStringEnum" : "inlineStringEnumValue1",
"myFileArray" : [ "", "" ],
"myFloat" : 5.637377,
"myStringEnumArray" : [ null, null ],
"myFloatArray" : [ 2.302136, 2.302136 ],
"myDoubleArray" : [ 9.301444243932576, 9.301444243932576 ],
"myString" : "myString",
"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" ]
} ]
}}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import Foundation

open class AllPrimitives: Codable {

public enum MyInlineStringEnum: String, Codable {
case inlinestringenumvalue1 = "inlineStringEnumValue1"
case inlinestringenumvalue2 = "inlineStringEnumValue2"
case inlinestringenumvalue3 = "inlineStringEnumValue3"
}
public var myInteger: Int?
public var myIntegerArray: [Int]?
public var myLong: Int64?
Expand All @@ -36,6 +41,7 @@ open class AllPrimitives: Codable {
public var myUUIDArray: [UUID]?
public var myStringEnum: StringEnum?
public var myStringEnumArray: [StringEnum]?
public var myInlineStringEnum: MyInlineStringEnum?


// Encodable protocol methods
Expand Down Expand Up @@ -68,10 +74,11 @@ open class AllPrimitives: Codable {
try container.encodeArrayIfPresent(myUUIDArray, forKey: "myUUIDArray")
try container.encodeIfPresent(myStringEnum, forKey: "myStringEnum")
try container.encodeArrayIfPresent(myStringEnumArray, forKey: "myStringEnumArray")
try container.encodeIfPresent(myInlineStringEnum, forKey: "myInlineStringEnum")
}

// Decodable protocol methods

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

Expand Down Expand Up @@ -99,6 +106,7 @@ open class AllPrimitives: Codable {
myUUIDArray = try container.decodeArrayIfPresent(UUID.self, forKey: "myUUIDArray")
myStringEnum = try container.decodeIfPresent(StringEnum.self, forKey: "myStringEnum")
myStringEnumArray = try container.decodeArrayIfPresent(StringEnum.self, forKey: "myStringEnumArray")
myInlineStringEnum = try container.decodeIfPresent(MyInlineStringEnum.self, forKey: "myInlineStringEnum")
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ open class ErrorInfo: Codable {
}

// Decodable protocol methods

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ open class GetAllModelsResult: Codable {
}

// Decodable protocol methods

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ open class ModelWithIntAdditionalPropertiesOnly: Codable {
}

// Decodable protocol methods

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ open class ModelWithPropertiesAndAdditionalProperties: Codable {
}

// Decodable protocol methods

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ open class ModelWithStringAdditionalPropertiesOnly: Codable {
}

// Decodable protocol methods

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ open class VariableNameTest: Codable {
}

// Decodable protocol methods

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

Expand Down