Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing node mapper for document types #2313

Merged
merged 4 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,13 @@ 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().toNode())
.putValues("b", ObjectNode.builder().withMember("b", "b").build().toNode())
.putValues("string", Node.from("stuff"))
.putValues("number", Node.from(1))
.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,11 @@ 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().toNode(),
ObjectNode.builder().withMember("b", "b").withMember("c", 1).build().toNode(),
Node.from("string")))),
// Maps
Arguments.of("maps/string-string-map-trait.smithy", StringStringMapTrait.class,
MapUtils.of("getValues", MapUtils.of("a", "stuff",
Expand All @@ -123,6 +130,13 @@ 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().toNode(),
"b", ObjectNode.builder().withMember("b", "b").withMember("c", 1).build().toNode(),
"c", Node.from("stuff"),
"d", Node.from(1)
))),
// 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
Expand Up @@ -5,5 +5,4 @@ namespace test.smithy.traitcodegen
use test.smithy.traitcodegen.defaults#StructDefaults

@StructDefaults
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ namespace test.smithy.traitcodegen

use test.smithy.traitcodegen.documents#DocumentTrait

@DocumentTrait({
metadata: "woo"
more: "yay"
})
structure myStruct {
}
@DocumentTrait({ metadata: "woo", more: "yay" })
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ namespace test.smithy.traitcodegen
use test.smithy.traitcodegen.documents#structWithNestedDocument

@structWithNestedDocument(
doc: {
foo: "bar"
fizz: "buzz"
}
doc: { foo: "bar", fizz: "buzz" }
)
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ namespace test.smithy.traitcodegen
use test.smithy.traitcodegen.enums#StringEnum

@StringEnum("yes")
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ namespace test.smithy.traitcodegen
use test.smithy.traitcodegen.enums#Suit

@Suit("club")
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ namespace test.smithy.traitcodegen.numbers
@ShortTrait("bad")
@DoubleTrait("bad")
structure structWithInvalidStringInput {}


Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ namespace test.smithy.traitcodegen.uniqueitems

// Doesnt have unique items. Expect failure
@NumberSetTrait([1, 1, 3, 4])
structure repeatedNumberValues {
}
structure repeatedNumberValues {}

@StringSetTrait(["a", "a", "b"])
structure repeatedStringValues {
}
structure repeatedStringValues {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,15 @@ $version: "2.0"

namespace test.smithy.traitcodegen.structures


@structureTrait(
fieldA: "first"
fieldB: false
fieldC: {
fieldN: "nested"
fieldQ: true
fieldZ: "A"
}
fieldC: { fieldN: "nested", fieldQ: true, fieldZ: "A" }
fieldD: ["a", "b", "c"]
fieldE: {
a: "one"
b: "two"
}
fieldF: 100.01,
fieldG: 100,
extraA: 100,
fieldE: { a: "one", b: "two" }
fieldF: 100.01
fieldG: 100
extraA: 100
extraB: 200
)
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ namespace test.smithy.traitcodegen

use test.smithy.traitcodegen.idref#IdRefMap

@IdRefMap(
a: IdRefTarget1
b: IdRefTarget2
)
@IdRefMap(a: IdRefTarget1, b: IdRefTarget2)
structure myStruct {}

string IdRefTarget1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ namespace test.smithy.traitcodegen
use test.smithy.traitcodegen.idref#IdRefStructWithNestedIds

@IdRefStructWithNestedIds(
idRefHolder: {
id: IdRefTarget1
}
idRefHolder: { id: IdRefTarget1 }
idList: [IdRefTarget1, IdRefTarget2]
idMap: {
a: IdRefTarget1
b: IdRefTarget2
}
idMap: { a: IdRefTarget1, b: IdRefTarget2 }
)
structure myStruct {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$version: "2.0"

namespace test.smithy.traitcodegen

use test.smithy.traitcodegen.lists#DocumentListTrait

@DocumentListTrait([
{
a: "a"
}
{
b: "b"
c: 1
}
"string"
])
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ namespace test.smithy.traitcodegen
use test.smithy.traitcodegen.lists#NumberListTrait

@NumberListTrait([1, 2, 3, 4, 5])
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ namespace test.smithy.traitcodegen
use test.smithy.traitcodegen.lists#StringListTrait

@StringListTrait(["a", "b", "c", "d"])
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use test.smithy.traitcodegen.lists#StructureListTrait
a: "first"
b: 1
c: "other"
} {
}
{
a: "second"
b: 2
c: "more"
}
])
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,5 @@ namespace test.smithy.traitcodegen

use test.smithy.traitcodegen.maps#StringStringMap

@StringStringMap(
a: "stuff"
b: "other"
c: "more!"
)
structure myStruct {
}
@StringStringMap(a: "stuff", b: "other", c: "more!")
structure myStruct {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$version: "2.0"

namespace test.smithy.traitcodegen

use test.smithy.traitcodegen.maps#StringDocumentMap

@StringDocumentMap(
a: { a: "a" }
b: { b: "b", c: 1 }
c: "stuff"
d: 1
)
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ namespace test.smithy.traitcodegen
use test.smithy.traitcodegen.maps#StringToStructMap

@StringToStructMap(
one: {
a: "foo"
b: 2
}
two: {
a: "bar"
b: 4
}
one: { a: "foo", b: 2 }
two: { a: "bar", b: 4 }
)
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use test.smithy.traitcodegen.mixins#structureListWithMixinMember
b: 1
c: "other"
d: "mixed-in"
} {
}
{
a: "second"
b: 2
c: "more"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ namespace test.smithy.traitcodegen

use test.smithy.traitcodegen.mixins#structWithMixin

@structWithMixin(
d: "mixed-in"
)
structure myStruct {
}
@structWithMixin(d: "mixed-in")
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ namespace test.smithy.traitcodegen

use test.smithy.traitcodegen.names#snake_case_structure

@snake_case_structure(
snake_case_member: "stuff"
)
structure myStruct {
}
@snake_case_structure(snake_case_member: "stuff")
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,10 @@ use test.smithy.traitcodegen.structures#structureTrait
@structureTrait(
fieldA: "first"
fieldB: false
fieldC: {
fieldN: "nested"
fieldQ: true
fieldZ: "A"
}
fieldC: { fieldN: "nested", fieldQ: true, fieldZ: "A" }
fieldD: ["a", "b", "c"]
fieldE: {
a: "one"
b: "two"
}
fieldF: 100.01,
fieldE: { a: "one", b: "two" }
fieldF: 100.01
fieldG: 100
)
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ use test.smithy.traitcodegen.structures#structureTrait
@structureTrait(
fieldA: "first"
fieldB: false
fieldC: {
fieldN: "nested"
fieldQ: true
fieldZ: "A"
}
fieldC: { fieldN: "nested", fieldQ: true, fieldZ: "A" }
)
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ namespace test.smithy.traitcodegen
use test.smithy.traitcodegen.uniqueitems#NumberSetTrait

@NumberSetTrait([1, 2, 3, 4])
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ namespace test.smithy.traitcodegen
use test.smithy.traitcodegen.uniqueitems#StringSetTrait

@StringSetTrait(["a", "b", "c", "d"])
structure myStruct {
}
structure myStruct {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use test.smithy.traitcodegen.uniqueitems#StructureSetTrait
a: "first"
b: 1
c: "other"
} {
}
{
a: "second"
b: 2
c: "more"
}
])
structure myStruct {
}
structure myStruct {}
Loading
Loading