Skip to content

Commit 060f0d0

Browse files
committed
Make property name optional, add document to shapes that can have empty default
1 parent fcbbf56 commit 060f0d0

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

Sources/SotoSmithy/Traits/Types/ResourceTraits.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ public struct ReferencesTrait: SingleValueTrait {
4242
/// Indicates that the targeted structure member provides an identifier for a resource.
4343
public struct ResourceIdentifierTrait: SingleValueTrait {
4444
public static let staticName: ShapeId = "smithy.api#resourceIdentifier"
45-
public static var selector: Selector { AndSelector(
46-
TypeSelector<MemberShape>(),
47-
TraitSelector<RequiredTrait>(),
48-
TargetSelector(TypeSelector<StringShape>())
49-
) }
45+
public static var selector: Selector {
46+
AndSelector(
47+
TypeSelector<MemberShape>(),
48+
TraitSelector<RequiredTrait>(),
49+
TargetSelector(TypeSelector<StringShape>())
50+
)
51+
}
5052
public var value: String
5153
public init(value: String) {
5254
self.value = value
@@ -73,9 +75,9 @@ public struct PropertyTrait: StaticTrait {
7375
public static let staticName: ShapeId = "smithy.api#property"
7476
public static var selector: Selector = TypeSelector<MemberShape>()
7577

76-
public let name: String
78+
public let name: String?
7779

78-
public init(name: String) {
80+
public init(name: String?) {
7981
self.name = name
8082
}
8183
}

Sources/SotoSmithy/Traits/Types/TypeRefinementTraits.swift

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@
1919
/// the box trait. All other shapes are always considered boxed.
2020
public struct BoxTrait: StaticTrait {
2121
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+
)
3133
)
32-
) }
34+
}
3335
public init() {}
3436
}
3537

@@ -68,10 +70,12 @@ public struct OutputTrait: StaticTrait {
6870
/// never allowed to be null.
6971
public struct SparseTrait: StaticTrait {
7072
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+
}
7579
public init() {}
7680
}
7781

@@ -116,21 +120,31 @@ public struct DefaultTrait: OptionalSingleValueTrait {
116120
public func validate(using model: Model, shape: Shape) throws {
117121
let targetShape: Shape
118122
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+
}
120126
targetShape = target
121127
} else {
122128
targetShape = shape
123129
}
124130
switch self.value {
125131
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+
}
127135
case .number(let n):
128136
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+
}
130140
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+
}
132144
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+
}
134148
case .none:
135149
// do nothing
136150
break

0 commit comments

Comments
 (0)