From 95dc978eb2477926cf6fdc0fc6bae15e5605f6dd Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Thu, 25 Mar 2021 13:03:42 -0400 Subject: [PATCH] Bugfix: Documents are inherently boxed --- .../amazon/smithy/model/knowledge/NullableIndex.java | 5 +++-- .../amazon/smithy/model/knowledge/NullableIndexTest.java | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/NullableIndex.java b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/NullableIndex.java index 28f7eb7a76f..4c135006426 100644 --- a/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/NullableIndex.java +++ b/smithy-model/src/main/java/software/amazon/smithy/model/knowledge/NullableIndex.java @@ -42,7 +42,8 @@ public class NullableIndex implements KnowledgeIndex { ShapeType.SET, ShapeType.MAP, ShapeType.STRUCTURE, - ShapeType.UNION); + ShapeType.UNION, + ShapeType.DOCUMENT); private final Set nullableShapes = new HashSet<>(); @@ -105,7 +106,7 @@ private static boolean isShapeBoxed(Shape shape) { * return false. When given any other shape, this method will return * true if the shape is inherently boxed, meaning the shape is either * marked with the {@code box} trait, or the shape is a string, blob, - * timestamp, bigDecimal, bigInteger, list, set, map, structure, or union. + * timestamp, bigDecimal, bigInteger, list, set, map, structure, union or document. * * @param shape Shape or shape ID to check. * @return Returns true if the shape can be set to null. diff --git a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/NullableIndexTest.java b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/NullableIndexTest.java index f567d68a74f..d6e855d9da8 100644 --- a/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/NullableIndexTest.java +++ b/smithy-model/src/test/java/software/amazon/smithy/model/knowledge/NullableIndexTest.java @@ -91,6 +91,7 @@ public static Collection data() { .addMember("c", ShapeId.from("smithy.api#PrimitiveBoolean"), b -> b.addTrait(new BoxTrait())) // Not nullable. .addMember("d", ShapeId.from("smithy.api#PrimitiveBoolean")) + .addMember("e", ShapeId.from("smithy.api#Document")) .build(); Model model = Model.assembler() @@ -150,6 +151,8 @@ public static Collection data() { {model, structure.getMember("b").get().getId().toString(), true}, {model, structure.getMember("c").get().getId().toString(), true}, {model, structure.getMember("d").get().getId().toString(), false}, + // documents are nullable as structure members + {model, structure.getMember("e").get().getId().toString(), true}, }); } }