Skip to content

Commit 7e62b08

Browse files
committed
Add tests for complex shapes inside Union
1 parent 4fbbd93 commit 7e62b08

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/StructureGeneratorTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,39 @@ public void callsFilterInUnionWithoutSensitiveData() {
179179
+ " }\n");
180180
}
181181

182+
@Test
183+
public void callsFilterInUnionWithStructure() {
184+
testStructureCodegen("test-union-with-structure.smithy",
185+
" export const filterSensitiveLog = (obj: TestUnion): any => {\n"
186+
+ " if (obj.fooUser !== undefined) return {fooUser:\n"
187+
+ " User.filterSensitiveLog(obj.fooUser)\n"
188+
+ " };\n"
189+
+ " if (obj.$unknown !== undefined) return {[obj.$unknown[0]]: 'UNKNOWN'};\n"
190+
+ " }\n");
191+
}
192+
193+
@Test
194+
public void callsFilterInUnionWithList() {
195+
testStructureCodegen("test-union-with-list.smithy",
196+
" export const filterSensitiveLog = (obj: TestUnion): any => {\n"
197+
+ " if (obj.list !== undefined) return {list:\n"
198+
+ " obj.list\n"
199+
+ " };\n"
200+
+ " if (obj.$unknown !== undefined) return {[obj.$unknown[0]]: 'UNKNOWN'};\n"
201+
+ " }\n");
202+
}
203+
204+
@Test
205+
public void callsFilterInUnionWithMap() {
206+
testStructureCodegen("test-union-with-map.smithy",
207+
" export const filterSensitiveLog = (obj: TestUnion): any => {\n"
208+
+ " if (obj.map !== undefined) return {map:\n"
209+
+ " obj.map\n"
210+
+ " };\n"
211+
+ " if (obj.$unknown !== undefined) return {[obj.$unknown[0]]: 'UNKNOWN'};\n"
212+
+ " }\n");
213+
}
214+
182215
@Test
183216
public void filtersStreamingUnion() {
184217
testStructureCodegen("test-streaming-union.smithy",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
namespace smithy.example
2+
3+
service Example {
4+
version: "1.0.0",
5+
operations: [GetFoo]
6+
}
7+
8+
operation GetFoo {
9+
input: GetFooInput
10+
}
11+
12+
structure GetFooInput {
13+
foo: TestUnion
14+
}
15+
16+
union TestUnion {
17+
list: NamesList
18+
}
19+
20+
list NamesList {
21+
member: String
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace smithy.example
2+
3+
service Example {
4+
version: "1.0.0",
5+
operations: [GetFoo]
6+
}
7+
8+
operation GetFoo {
9+
input: GetFooInput
10+
}
11+
12+
structure GetFooInput {
13+
foo: TestUnion
14+
}
15+
16+
union TestUnion {
17+
map: NamesMap
18+
}
19+
20+
map NamesMap {
21+
key: String,
22+
value: String
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace smithy.example
2+
3+
service Example {
4+
version: "1.0.0",
5+
operations: [GetFoo]
6+
}
7+
8+
operation GetFoo {
9+
input: GetFooInput
10+
}
11+
12+
structure GetFooInput {
13+
foo: TestUnion
14+
}
15+
16+
union TestUnion {
17+
fooUser: User
18+
}
19+
20+
structure User {
21+
firstname: String,
22+
lastname: String
23+
}

0 commit comments

Comments
 (0)