Skip to content

Commit

Permalink
Add missing node mapper for document types
Browse files Browse the repository at this point in the history
  • Loading branch information
hpmellema committed Jun 7, 2024
1 parent 25f4023 commit 0b2f8e4
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +83,10 @@ static Stream<Arguments> 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()
Expand All @@ -90,6 +96,11 @@ static Stream<Arguments> 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())),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -115,6 +117,10 @@ static Stream<Arguments> 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",
Expand All @@ -123,6 +129,11 @@ static Stream<Arguments> 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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
@@ -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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public Void floatShape(FloatShape shape) {

@Override
public Void documentShape(DocumentShape shape) {
writer.write("$L.expectObjectNode()", varName);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$version: "2.0"

namespace test.smithy.traitcodegen.lists

@trait
list DocumentListTrait {
member: Document
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$version: "2.0"

namespace test.smithy.traitcodegen.maps

@trait
map StringDocumentMap {
key: String
value: Document
}

0 comments on commit 0b2f8e4

Please sign in to comment.