19
19
import java .util .List ;
20
20
import java .util .Objects ;
21
21
import java .util .Optional ;
22
+ import java .util .stream .Collectors ;
22
23
import software .amazon .smithy .model .node .ArrayNode ;
23
24
import software .amazon .smithy .model .node .Node ;
24
25
import software .amazon .smithy .model .node .ObjectNode ;
25
26
import software .amazon .smithy .model .node .ToNode ;
26
27
import software .amazon .smithy .model .shapes .ShapeId ;
28
+ import software .amazon .smithy .model .validation .NodeValidationVisitor ;
27
29
import software .amazon .smithy .model .validation .validators .ExamplesTraitValidator ;
30
+ import software .amazon .smithy .utils .BuilderRef ;
28
31
import software .amazon .smithy .utils .SmithyBuilder ;
29
32
import software .amazon .smithy .utils .ToSmithyBuilder ;
30
33
@@ -55,6 +58,24 @@ protected Node createNode() {
55
58
return examples .stream ().map (Example ::toNode ).collect (ArrayNode .collect (getSourceLocation ()));
56
59
}
57
60
61
+ @ Override
62
+ public boolean equals (Object other ) {
63
+ if (!(other instanceof ExamplesTrait )) {
64
+ return false ;
65
+ } else if (other == this ) {
66
+ return true ;
67
+ } else {
68
+ ExamplesTrait trait = (ExamplesTrait ) other ;
69
+ return this .examples .size () == trait .examples .size () && this .examples .containsAll (trait .examples );
70
+ }
71
+ }
72
+
73
+ @ Override
74
+ public int hashCode () {
75
+ return Objects .hash (toShapeId (), examples );
76
+ }
77
+
78
+
58
79
@ Override
59
80
public Builder toBuilder () {
60
81
Builder builder = new Builder ().sourceLocation (getSourceLocation ());
@@ -70,7 +91,7 @@ public static Builder builder() {
70
91
}
71
92
72
93
/**
73
- * Builds and examples trait.
94
+ * Builds an examples trait.
74
95
*/
75
96
public static final class Builder extends AbstractTraitBuilder <ExamplesTrait , Builder > {
76
97
private final List <Example > examples = new ArrayList <>();
@@ -100,13 +121,15 @@ public static final class Example implements ToNode, ToSmithyBuilder<Example> {
100
121
private final ObjectNode input ;
101
122
private final ObjectNode output ;
102
123
private final ErrorExample error ;
124
+ private final List <NodeValidationVisitor .Feature > lowerInputValidationSeverity ;
103
125
104
126
private Example (Builder builder ) {
105
127
this .title = Objects .requireNonNull (builder .title , "Example title must not be null" );
106
128
this .documentation = builder .documentation ;
107
129
this .input = builder .input ;
108
130
this .output = builder .output ;
109
131
this .error = builder .error ;
132
+ this .lowerInputValidationSeverity = builder .lowerInputValidationSeverity .get ();
110
133
}
111
134
112
135
/**
@@ -144,6 +167,13 @@ public Optional<ErrorExample> getError() {
144
167
return Optional .ofNullable (error );
145
168
}
146
169
170
+ /**
171
+ * @return Gets the list of lowered input validation severities.
172
+ */
173
+ public Optional <List <NodeValidationVisitor .Feature >> getLowerInputValidationSeverity () {
174
+ return Optional .ofNullable (lowerInputValidationSeverity );
175
+ }
176
+
147
177
@ Override
148
178
public Node toNode () {
149
179
ObjectNode .Builder builder = Node .objectNodeBuilder ()
@@ -157,13 +187,20 @@ public Node toNode() {
157
187
if (this .getOutput ().isPresent ()) {
158
188
builder .withMember ("output" , output );
159
189
}
190
+ if (this .getLowerInputValidationSeverity ().isPresent ()) {
191
+ builder .withMember ("lowerInputValidationSeverity" , ArrayNode .fromNodes (lowerInputValidationSeverity
192
+ .stream ()
193
+ .map (NodeValidationVisitor .Feature ::toNode )
194
+ .collect (Collectors .toList ())));
195
+ }
160
196
161
197
return builder .build ();
162
198
}
163
199
164
200
@ Override
165
201
public Builder toBuilder () {
166
- return new Builder ().documentation (documentation ).title (title ).input (input ).output (output ).error (error );
202
+ return new Builder ().documentation (documentation ).title (title ).input (input ).output (output ).error (error )
203
+ .lowerInputValidationSeverity (lowerInputValidationSeverity );
167
204
}
168
205
169
206
public static Builder builder () {
@@ -179,6 +216,7 @@ public static final class Builder implements SmithyBuilder<Example> {
179
216
private ObjectNode input = Node .objectNode ();
180
217
private ObjectNode output ;
181
218
private ErrorExample error ;
219
+ private BuilderRef <List <NodeValidationVisitor .Feature >> lowerInputValidationSeverity = BuilderRef .forList ();
182
220
183
221
@ Override
184
222
public Example build () {
@@ -209,6 +247,14 @@ public Builder error(ErrorExample error) {
209
247
this .error = error ;
210
248
return this ;
211
249
}
250
+
251
+ public Builder lowerInputValidationSeverity (
252
+ List <NodeValidationVisitor .Feature > lowerInputValidationSeverity
253
+ ) {
254
+ this .lowerInputValidationSeverity .clear ();
255
+ this .lowerInputValidationSeverity .get ().addAll (lowerInputValidationSeverity );
256
+ return this ;
257
+ }
212
258
}
213
259
}
214
260
@@ -302,7 +348,9 @@ private static Example exampleFromNode(ObjectNode node) {
302
348
.getStringMember ("documentation" , builder ::documentation )
303
349
.getObjectMember ("input" , builder ::input )
304
350
.getObjectMember ("output" , builder ::output )
305
- .getMember ("error" , ErrorExample ::fromNode , builder ::error );
351
+ .getMember ("error" , ErrorExample ::fromNode , builder ::error )
352
+ .getArrayMember ("lowerInputValidationSeverity" , NodeValidationVisitor .Feature ::fromNode ,
353
+ builder ::lowerInputValidationSeverity );
306
354
return builder .build ();
307
355
}
308
356
}
0 commit comments