From 0b2f8e46c62997035af35f1722e3fc91d42ce333 Mon Sep 17 00:00:00 2001 From: Hunter Mellema Date: Fri, 7 Jun 2024 06:48:09 -0600 Subject: [PATCH] Add missing node mapper for document types --- .../traitcodegen/test/CreatesTraitTest.java | 11 +++++++++++ .../traitcodegen/test/LoadsFromModelTest.java | 11 +++++++++++ .../test/lists/document-list-trait.smithy | 16 ++++++++++++++++ .../maps/string-to-document-map-trait.smithy | 15 +++++++++++++++ .../generators/FromNodeMapperVisitor.java | 1 + .../traitcodegen/TraitCodegenPluginTest.java | 2 +- .../smithy/lists/document-list-trait.smithy | 8 ++++++++ .../src/test/resources/META-INF/smithy/manifest | 2 ++ .../maps/string-to-document-map-trait.smithy | 9 +++++++++ 9 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 smithy-trait-codegen/src/it/resources/software/amazon/smithy/traitcodegen/test/lists/document-list-trait.smithy create mode 100644 smithy-trait-codegen/src/it/resources/software/amazon/smithy/traitcodegen/test/maps/string-to-document-map-trait.smithy create mode 100644 smithy-trait-codegen/src/test/resources/META-INF/smithy/lists/document-list-trait.smithy create mode 100644 smithy-trait-codegen/src/test/resources/META-INF/smithy/maps/string-to-document-map-trait.smithy diff --git a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/CreatesTraitTest.java b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/CreatesTraitTest.java index 0aa918b88cb..e10f8dbcfb3 100644 --- a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/CreatesTraitTest.java +++ b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/CreatesTraitTest.java @@ -9,11 +9,13 @@ import com.example.traits.enums.IntEnumTrait; import com.example.traits.enums.StringEnumTrait; import com.example.traits.enums.SuitTrait; +import com.example.traits.lists.DocumentListTrait; import com.example.traits.lists.ListMember; import com.example.traits.lists.NumberListTrait; import com.example.traits.lists.StringListTrait; import com.example.traits.lists.StructureListTrait; import com.example.traits.maps.MapValue; +import com.example.traits.maps.StringDocumentMapTrait; import com.example.traits.maps.StringStringMapTrait; import com.example.traits.maps.StringToStructMapTrait; import com.example.traits.mixins.StructWithMixinTrait; @@ -81,6 +83,10 @@ static Stream createTraitTests() { ListMember.builder().a("first").b(1).c("other").build().toNode(), ListMember.builder().a("second").b(2).c("more").build().toNode() )), + Arguments.of(DocumentListTrait.ID, ArrayNode.fromNodes( + ObjectNode.builder().withMember("a", "b").build(), + ObjectNode.builder().withMember("c", "d").withMember("e", "f").build() + )), // Maps Arguments.of(StringStringMapTrait.ID, StringStringMapTrait.builder() .putValues("a", "first").putValues("b", "other").build().toNode() @@ -90,6 +96,11 @@ static Stream createTraitTests() { .putValues("two", MapValue.builder().a("bar").b(4).build()) .build().toNode() ), + Arguments.of(StringDocumentMapTrait.ID, StringDocumentMapTrait.builder() + .putValues("a", ObjectNode.builder().withMember("a", "a").build()) + .putValues("b", ObjectNode.builder().withMember("b", "b").build()) + .build().toNode() + ), // Mixins Arguments.of(StructureListWithMixinMemberTrait.ID, ArrayNode.fromNodes(ObjectNode.builder().withMember("a", "a").withMember("d", "d").build())), diff --git a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java index 377b4953f34..61d332dfcad 100644 --- a/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java +++ b/smithy-trait-codegen/src/it/java/software/amazon/smithy/traitcodegen/test/LoadsFromModelTest.java @@ -16,10 +16,12 @@ import com.example.traits.idref.IdRefStructTrait; import com.example.traits.idref.IdRefStructWithNestedIdsTrait; import com.example.traits.idref.NestedIdRefHolder; +import com.example.traits.lists.DocumentListTrait; import com.example.traits.lists.ListMember; import com.example.traits.lists.NumberListTrait; import com.example.traits.lists.StructureListTrait; import com.example.traits.maps.MapValue; +import com.example.traits.maps.StringDocumentMapTrait; import com.example.traits.maps.StringStringMapTrait; import com.example.traits.maps.StringToStructMapTrait; import com.example.traits.mixins.ListMemberWithMixin; @@ -115,6 +117,10 @@ static Stream loadsModelTests() { MapUtils.of("getValues", ListUtils.of( ListMember.builder().a("first").b(1).c("other").build(), ListMember.builder().a("second").b(2).c("more").build()))), + Arguments.of("lists/document-list-trait.smithy", DocumentListTrait.class, + MapUtils.of("getValues", ListUtils.of( + ObjectNode.builder().withMember("a", "a").build(), + ObjectNode.builder().withMember("b", "b").withMember("c", "c").build()))), // Maps Arguments.of("maps/string-string-map-trait.smithy", StringStringMapTrait.class, MapUtils.of("getValues", MapUtils.of("a", "stuff", @@ -123,6 +129,11 @@ static Stream loadsModelTests() { MapUtils.of("getValues", MapUtils.of( "one", MapValue.builder().a("foo").b(2).build(), "two", MapValue.builder().a("bar").b(4).build()))), + Arguments.of("maps/string-to-document-map-trait.smithy", StringDocumentMapTrait.class, + MapUtils.of("getValues", MapUtils.of( + "a", ObjectNode.builder().withMember("a", "a").build(), + "b", ObjectNode.builder().withMember("b", "b").withMember("c", "c").build() + ))), // Mixins Arguments.of("mixins/struct-with-mixin-member.smithy", StructureListWithMixinMemberTrait.class, MapUtils.of("getValues", ListUtils.of( diff --git a/smithy-trait-codegen/src/it/resources/software/amazon/smithy/traitcodegen/test/lists/document-list-trait.smithy b/smithy-trait-codegen/src/it/resources/software/amazon/smithy/traitcodegen/test/lists/document-list-trait.smithy new file mode 100644 index 00000000000..88f56a6592b --- /dev/null +++ b/smithy-trait-codegen/src/it/resources/software/amazon/smithy/traitcodegen/test/lists/document-list-trait.smithy @@ -0,0 +1,16 @@ +$version: "2.0" + +namespace test.smithy.traitcodegen + +use test.smithy.traitcodegen.lists#DocumentListTrait + + +@DocumentListTrait([ + { a : "a"}, + { + b : "b" + c : "c" + } +]) +structure myStruct { +} diff --git a/smithy-trait-codegen/src/it/resources/software/amazon/smithy/traitcodegen/test/maps/string-to-document-map-trait.smithy b/smithy-trait-codegen/src/it/resources/software/amazon/smithy/traitcodegen/test/maps/string-to-document-map-trait.smithy new file mode 100644 index 00000000000..4724b7f1a05 --- /dev/null +++ b/smithy-trait-codegen/src/it/resources/software/amazon/smithy/traitcodegen/test/maps/string-to-document-map-trait.smithy @@ -0,0 +1,15 @@ +$version: "2.0" + +namespace test.smithy.traitcodegen + +use test.smithy.traitcodegen.maps#StringDocumentMap + +@StringDocumentMap( + a: { a : "a" } + b: { + b : "b" + c : "c" + } +) +structure myStruct { +} diff --git a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeMapperVisitor.java b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeMapperVisitor.java index 3b0f2bd145b..3206282c726 100644 --- a/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeMapperVisitor.java +++ b/smithy-trait-codegen/src/main/java/software/amazon/smithy/traitcodegen/generators/FromNodeMapperVisitor.java @@ -112,6 +112,7 @@ public Void floatShape(FloatShape shape) { @Override public Void documentShape(DocumentShape shape) { + writer.write("$L.expectObjectNode()", varName); return null; } diff --git a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/TraitCodegenPluginTest.java b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/TraitCodegenPluginTest.java index 916faabb073..1d3bbcc00c4 100644 --- a/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/TraitCodegenPluginTest.java +++ b/smithy-trait-codegen/src/test/java/software/amazon/smithy/traitcodegen/TraitCodegenPluginTest.java @@ -28,7 +28,7 @@ public class TraitCodegenPluginTest { - private static final int EXPECTED_NUMBER_OF_FILES = 56; + private static final int EXPECTED_NUMBER_OF_FILES = 58; private MockManifest manifest; private Model model; diff --git a/smithy-trait-codegen/src/test/resources/META-INF/smithy/lists/document-list-trait.smithy b/smithy-trait-codegen/src/test/resources/META-INF/smithy/lists/document-list-trait.smithy new file mode 100644 index 00000000000..b606dba7b18 --- /dev/null +++ b/smithy-trait-codegen/src/test/resources/META-INF/smithy/lists/document-list-trait.smithy @@ -0,0 +1,8 @@ +$version: "2.0" + +namespace test.smithy.traitcodegen.lists + +@trait +list DocumentListTrait { + member: Document +} diff --git a/smithy-trait-codegen/src/test/resources/META-INF/smithy/manifest b/smithy-trait-codegen/src/test/resources/META-INF/smithy/manifest index e1e57d9efee..8e659e2ba7e 100644 --- a/smithy-trait-codegen/src/test/resources/META-INF/smithy/manifest +++ b/smithy-trait-codegen/src/test/resources/META-INF/smithy/manifest @@ -13,8 +13,10 @@ ignored.smithy lists/number-list-trait.smithy lists/string-list-trait.smithy lists/struct-list-trait.smithy +lists/document-list-trait.smithy maps/string-string-map-trait.smithy maps/string-to-struct-map-trait.smithy +maps/string-to-document-map-trait.smithy mixins/struct-with-mixin-member.smithy mixins/struct-with-only-mixin-member.smithy names/snake-case-structure.smithy diff --git a/smithy-trait-codegen/src/test/resources/META-INF/smithy/maps/string-to-document-map-trait.smithy b/smithy-trait-codegen/src/test/resources/META-INF/smithy/maps/string-to-document-map-trait.smithy new file mode 100644 index 00000000000..867f9a95a3b --- /dev/null +++ b/smithy-trait-codegen/src/test/resources/META-INF/smithy/maps/string-to-document-map-trait.smithy @@ -0,0 +1,9 @@ +$version: "2.0" + +namespace test.smithy.traitcodegen.maps + +@trait +map StringDocumentMap { + key: String + value: Document +}