Skip to content

Commit

Permalink
Update TestSpec to include example demonstrated in yonaskolb#267
Browse files Browse the repository at this point in the history
  • Loading branch information
liamnichols committed Jul 27, 2021
1 parent 8c55b3a commit c10a5e6
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
69 changes: 68 additions & 1 deletion Specs/TestSpec/generated/Swift/Sources/Models/Zoo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class Zoo: APIModel {

public var inlineAnimals: [InlineAnimals]?

public var manager: Manager?

public var oneOfDog: Dog?

public var schemaAnimals: [SingleAnimal]?
Expand Down Expand Up @@ -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
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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
Expand Down
11 changes: 11 additions & 0 deletions Specs/TestSpec/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c10a5e6

Please sign in to comment.