32
32
import software .amazon .smithy .diff .ModelDiff ;
33
33
import software .amazon .smithy .go .codegen .AddOperationShapes ;
34
34
import software .amazon .smithy .go .codegen .GoSettings ;
35
+ import software .amazon .smithy .go .codegen .Synthetic ;
35
36
import software .amazon .smithy .go .codegen .integration .GoIntegration ;
36
37
import software .amazon .smithy .model .Model ;
37
38
import software .amazon .smithy .model .loader .ModelAssembler ;
@@ -154,7 +155,7 @@ public Model preprocessModel(Model model, GoSettings settings) {
154
155
}
155
156
throw new CodegenException (sb .toString ());
156
157
}
157
- validateNullabilityExceptions (nullabilityExceptions , model );
158
+ validateNullabilityExceptions (nullabilityExceptions , model , service );
158
159
return model ;
159
160
}
160
161
@@ -318,7 +319,7 @@ private static Model handleApiGateWayExportsNullabilityExceptions(
318
319
return ModelTransformer .create ().replaceShapes (model , shapesToReplace );
319
320
}
320
321
321
- private static void validateNullabilityExceptions (Set <ShapeId > nullabilityExceptions , Model model ) {
322
+ private static void validateNullabilityExceptions (Set <ShapeId > nullabilityExceptions , Model model , ShapeId service ) {
322
323
Map <ShapeId , Shape > nullabilityExceptionMap = new HashMap <>();
323
324
for (ShapeId shapeId : nullabilityExceptions ) {
324
325
if (model .getShape (shapeId ).isPresent ()) {
@@ -327,6 +328,31 @@ private static void validateNullabilityExceptions(Set<ShapeId> nullabilityExcept
327
328
LOGGER .warning ("Shape `" + shapeId + "` nullability exception is not present in the model" );
328
329
}
329
330
}
331
+
332
+ for (BooleanShape shape : model .getBooleanShapesWithTrait (DefaultTrait .class )) {
333
+ ShapeId shapeId = shape .toShapeId ();
334
+ String namespace = shapeId .getNamespace ();
335
+ if (!namespace .equals (service .getNamespace ()) && !namespace .equals (Synthetic .ID .getNamespace ())) {
336
+ continue ;
337
+ }
338
+ if (!nullabilityExceptions .contains (shapeId )) {
339
+ throw new CodegenException ("Shape `" + shapeId + "` should be in nullability exceptions" );
340
+ }
341
+ }
342
+
343
+ for (NumberShape shape : model .toSet (NumberShape .class ).stream ()
344
+ .filter (s -> s .hasTrait (DefaultTrait .class ))
345
+ .collect (Collectors .toList ())) {
346
+ ShapeId shapeId = shape .toShapeId ();
347
+ String namespace = shapeId .getNamespace ();
348
+ if (!namespace .equals (service .getNamespace ()) && !namespace .equals (Synthetic .ID .getNamespace ())) {
349
+ continue ;
350
+ }
351
+ if (!nullabilityExceptions .contains (shapeId )) {
352
+ throw new CodegenException ("Shape `" + shapeId + "` should be in nullability exceptions" );
353
+ }
354
+ }
355
+
330
356
// Existing “defaulted” root boolean or number shapes MUST be backfilled with a
331
357
// default trait.
332
358
for (Map .Entry <ShapeId , Shape > entry : nullabilityExceptionMap .entrySet ()) {
0 commit comments