-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathArrayMetadata.swift
More file actions
42 lines (33 loc) · 1.23 KB
/
ArrayMetadata.swift
File metadata and controls
42 lines (33 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
public struct ArrayMetadata {
/// The minimum number of items in the array. Must be greater than or equal to zero.
public let minItems: Int?
/// The maximum number of items in the array. Must be greater than or equal to zero.
public let maxItems: Int?
/// Items must have unique values.
public let uniqueItems: Bool
}
struct ArrayMetadataBuilder: Codable {
let minItems: Int?
let maxItems: Int?
let uniqueItems: Bool
enum CodingKeys: String, CodingKey {
case minItems
case maxItems
case uniqueItems
}
init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
self.minItems = try values.decodeIfPresent(Int.self, forKey: .minItems)
self.maxItems = try values.decodeIfPresent(Int.self, forKey: .maxItems)
self.uniqueItems = try values.decodeIfPresent(Bool.self, forKey: .uniqueItems) ?? false
}
}
extension ArrayMetadataBuilder: Builder {
typealias Building = ArrayMetadata
func build(_ swagger: SwaggerBuilder) throws -> ArrayMetadata {
return ArrayMetadata(
minItems: self.minItems,
maxItems: self.maxItems,
uniqueItems: self.uniqueItems)
}
}