Я использую swagger-codegen для генерации быстрого клиента. Мой файл swagger.yaml содержит следующие определения модели:
RelationshipCollection:
type: object
description: a collection of relationships
required:
- pagination
- relationships
properties:
pagination:
$ref: '#/definitions/PaginationData'
relationships:
type: array
items:
$ref: '#/definitions/Relationship'
Relationship:
type: object
description: Indicates the relationship between a parent and a student.
properties:
relationship_id:
type: integer
format: int32
parent:
$ref: '#/definitions/SwaggerUser'
student:
$ref: '#/definitions/SwaggerUser'
RelationshipCreate:
name: RelationshipCreate
type: object
description: What a student must send to the system to form a `Relationship` with their parent. Cannot be created without an `Invitation`.
required:
- token
- security_answer
properties:
token:
type: string
example: jRMcN645BQyDr67yHR3qjsJF
description: The token from the `Invitation` used to create this relationship
security_answer:
type: string
example: Some kind of answer to a security question
description: The answer to the security question asked in the `Invitation`
Когда я генерирую код, используя swagger-codegen, я получаю следующую модель для Relationship.
open class Relationship: Codable {
public var relationshipCreate: RelationshipCreate
public init(relationshipCreate: RelationshipCreate) {
self.relationshipCreate = relationshipCreate
}
// Encodable protocol methods
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: String.self)
try container.encode(relationshipCreate, forKey: "relationshipCreate")
}
// Decodable protocol methods
public required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: String.self)
relationshipCreate = try container.decode(RelationshipCreate.self, forKey: "relationshipCreate")
}
}
Я ожидаю следующего:
open class Relationship: Codable {
public var relationshipId: Int?
public var parent: SwaggerUser?
public var student: SwaggerUser?
public init(relationshipID: Int?, parent: SwaggerUser?, student: SwaggerUser?) {
self.relationshipID = relationshipID
self.parent = parent
self.student = student
}
...
}