From c10a5e693df9a24fe5b2ce3131ac777202da5b29 Mon Sep 17 00:00:00 2001 From: Liam Nichols Date: Tue, 27 Jul 2021 10:33:27 +0100 Subject: [PATCH] Update TestSpec to include example demonstrated in #267 --- .../generated/Swift/Sources/Models/Zoo.swift | 69 ++++++++++++++++++- Specs/TestSpec/spec.yml | 11 +++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/Specs/TestSpec/generated/Swift/Sources/Models/Zoo.swift b/Specs/TestSpec/generated/Swift/Sources/Models/Zoo.swift index dd871319c..9b211a85e 100644 --- a/Specs/TestSpec/generated/Swift/Sources/Models/Zoo.swift +++ b/Specs/TestSpec/generated/Swift/Sources/Models/Zoo.swift @@ -15,6 +15,8 @@ public class Zoo: APIModel { public var inlineAnimals: [InlineAnimals]? + public var manager: Manager? + public var oneOfDog: Dog? public var schemaAnimals: [SingleAnimal]? @@ -47,11 +49,73 @@ public class Zoo: APIModel { } } - public init(allOfDog: Dog? = nil, anyOfDog: Dog? = nil, inlineAnimal: Animal? = nil, inlineAnimals: [InlineAnimals]? = nil, oneOfDog: Dog? = nil, schemaAnimals: [SingleAnimal]? = nil) { + public class Manager: User { + + public var value: Value? + + public class Value: APIModel { + + public var id: String + + public init(id: String) { + self.id = id + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: StringCodingKey.self) + + id = try container.decode("id") + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: StringCodingKey.self) + + try container.encode(id, forKey: "id") + } + + public func isEqual(to object: Any?) -> Bool { + guard let object = object as? Value else { return false } + guard self.id == object.id else { return false } + return true + } + + public static func == (lhs: Value, rhs: Value) -> Bool { + return lhs.isEqual(to: rhs) + } + } + + public init(id: Int? = nil, name: String? = nil, value: Value? = nil) { + self.value = value + super.init(id: id, name: name) + } + + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: StringCodingKey.self) + + value = try container.decodeIfPresent("value") + try super.init(from: decoder) + } + + public override func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: StringCodingKey.self) + + try container.encodeIfPresent(value, forKey: "value") + try super.encode(to: encoder) + } + + override public func isEqual(to object: Any?) -> Bool { + guard let object = object as? Manager else { return false } + guard self.value == object.value else { return false } + return super.isEqual(to: object) + } + } + + public init(allOfDog: Dog? = nil, anyOfDog: Dog? = nil, inlineAnimal: Animal? = nil, inlineAnimals: [InlineAnimals]? = nil, manager: Manager? = nil, oneOfDog: Dog? = nil, schemaAnimals: [SingleAnimal]? = nil) { self.allOfDog = allOfDog self.anyOfDog = anyOfDog self.inlineAnimal = inlineAnimal self.inlineAnimals = inlineAnimals + self.manager = manager self.oneOfDog = oneOfDog self.schemaAnimals = schemaAnimals } @@ -63,6 +127,7 @@ public class Zoo: APIModel { anyOfDog = try container.decodeIfPresent("anyOfDog") inlineAnimal = try container.decodeIfPresent("inlineAnimal") inlineAnimals = try container.decodeArrayIfPresent("inlineAnimals") + manager = try container.decodeIfPresent("manager") oneOfDog = try container.decodeIfPresent("oneOfDog") schemaAnimals = try container.decodeArrayIfPresent("schemaAnimals") } @@ -74,6 +139,7 @@ public class Zoo: APIModel { try container.encodeIfPresent(anyOfDog, forKey: "anyOfDog") try container.encodeIfPresent(inlineAnimal, forKey: "inlineAnimal") try container.encodeIfPresent(inlineAnimals, forKey: "inlineAnimals") + try container.encodeIfPresent(manager, forKey: "manager") try container.encodeIfPresent(oneOfDog, forKey: "oneOfDog") try container.encodeIfPresent(schemaAnimals, forKey: "schemaAnimals") } @@ -84,6 +150,7 @@ public class Zoo: APIModel { guard self.anyOfDog == object.anyOfDog else { return false } guard self.inlineAnimal == object.inlineAnimal else { return false } guard self.inlineAnimals == object.inlineAnimals else { return false } + guard self.manager == object.manager else { return false } guard self.oneOfDog == object.oneOfDog else { return false } guard self.schemaAnimals == object.schemaAnimals else { return false } return true diff --git a/Specs/TestSpec/spec.yml b/Specs/TestSpec/spec.yml index 228b52ad8..e8b39bd85 100644 --- a/Specs/TestSpec/spec.yml +++ b/Specs/TestSpec/spec.yml @@ -337,6 +337,17 @@ components: allOfDog: allOf: - $ref: '#/components/schemas/Dog' + manager: + allOf: + - $ref: "#/components/schemas/User" + - properties: + value: + type: object + required: + - id + properties: + id: + type: string SingleAnimal: oneOf: - $ref: "#/components/schemas/Cat"