|
19 | 19 | /// the box trait. All other shapes are always considered boxed. |
20 | 20 | public struct BoxTrait: StaticTrait { |
21 | 21 | public static let staticName: ShapeId = "smithy.api#box" |
22 | | - public var selector: Selector { OrTargetSelector( |
23 | | - OrSelector( |
24 | | - TypeSelector<BooleanShape>(), |
25 | | - TypeSelector<ByteShape>(), |
26 | | - TypeSelector<ShortShape>(), |
27 | | - TypeSelector<IntegerShape>(), |
28 | | - TypeSelector<LongShape>(), |
29 | | - TypeSelector<FloatShape>(), |
30 | | - TypeSelector<DoubleShape>() |
| 22 | + public var selector: Selector { |
| 23 | + OrTargetSelector( |
| 24 | + OrSelector( |
| 25 | + TypeSelector<BooleanShape>(), |
| 26 | + TypeSelector<ByteShape>(), |
| 27 | + TypeSelector<ShortShape>(), |
| 28 | + TypeSelector<IntegerShape>(), |
| 29 | + TypeSelector<LongShape>(), |
| 30 | + TypeSelector<FloatShape>(), |
| 31 | + TypeSelector<DoubleShape>() |
| 32 | + ) |
31 | 33 | ) |
32 | | - ) } |
| 34 | + } |
33 | 35 | public init() {} |
34 | 36 | } |
35 | 37 |
|
@@ -68,10 +70,12 @@ public struct OutputTrait: StaticTrait { |
68 | 70 | /// never allowed to be null. |
69 | 71 | public struct SparseTrait: StaticTrait { |
70 | 72 | public static let staticName: ShapeId = "smithy.api#sparse" |
71 | | - public var selector: Selector { OrSelector( |
72 | | - TypeSelector<ListShape>(), |
73 | | - TypeSelector<MapShape>() |
74 | | - ) } |
| 73 | + public var selector: Selector { |
| 74 | + OrSelector( |
| 75 | + TypeSelector<ListShape>(), |
| 76 | + TypeSelector<MapShape>() |
| 77 | + ) |
| 78 | + } |
75 | 79 | public init() {} |
76 | 80 | } |
77 | 81 |
|
@@ -116,21 +120,31 @@ public struct DefaultTrait: OptionalSingleValueTrait { |
116 | 120 | public func validate(using model: Model, shape: Shape) throws { |
117 | 121 | let targetShape: Shape |
118 | 122 | if let member = shape as? MemberShape { |
119 | | - guard let target = model.shape(for: member.target) else { throw Smithy.ValidationError(reason: "Member of ** references non-existent shape \(member.target)") } |
| 123 | + guard let target = model.shape(for: member.target) else { |
| 124 | + throw Smithy.ValidationError(reason: "Member of ** references non-existent shape \(member.target)") |
| 125 | + } |
120 | 126 | targetShape = target |
121 | 127 | } else { |
122 | 128 | targetShape = shape |
123 | 129 | } |
124 | 130 | switch self.value { |
125 | 131 | case .boolean(let b): |
126 | | - guard targetShape is BooleanShape else { throw Smithy.ValidationError(reason: "Invalid default value \(b) for **") } |
| 132 | + guard targetShape is BooleanShape else { |
| 133 | + throw Smithy.ValidationError(reason: "Invalid default value \(b) for **") |
| 134 | + } |
127 | 135 | case .number(let n): |
128 | 136 | let selector = NumberSelector() |
129 | | - guard selector.select(using: model, shape: targetShape) else { throw Smithy.ValidationError(reason: "Invalid default value \(n) for **") } |
| 137 | + guard selector.select(using: model, shape: targetShape) else { |
| 138 | + throw Smithy.ValidationError(reason: "Invalid default value \(n) for **") |
| 139 | + } |
130 | 140 | case .string(let s): |
131 | | - guard targetShape is StringShape || targetShape is EnumShape || targetShape is BlobShape else { throw Smithy.ValidationError(reason: "Invalid default value \(s) for **") } |
| 141 | + guard targetShape is StringShape || targetShape is EnumShape || targetShape is BlobShape else { |
| 142 | + throw Smithy.ValidationError(reason: "Invalid default value \(s) for **") |
| 143 | + } |
132 | 144 | case .empty: |
133 | | - guard targetShape is ListShape || targetShape is MapShape else { throw Smithy.ValidationError(reason: "Invalid default value for **") } |
| 145 | + guard targetShape is ListShape || targetShape is MapShape || targetShape is DocumentShape else { |
| 146 | + throw Smithy.ValidationError(reason: "Invalid default value for **") |
| 147 | + } |
134 | 148 | case .none: |
135 | 149 | // do nothing |
136 | 150 | break |
|
0 commit comments