Skip to content

Commit f022101

Browse files
committed
Add tests for Operation Context Params Identifier and SubExpression
1 parent bb72d3a commit f022101

File tree

2 files changed

+75
-17
lines changed

2 files changed

+75
-17
lines changed

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

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,60 @@ public class CommandGeneratorTest {
1414
public void addsCommandSpecificPlugins() {
1515
testCommmandCodegen(
1616
"output-structure.smithy",
17-
"getSerdePlugin(config, this.serialize, this.deserialize)"
17+
new String[] {"getSerdePlugin(config, this.serialize, this.deserialize)"}
1818
);
1919
}
2020

2121
@Test
2222
public void writesSerializer() {
2323
testCommmandCodegen(
2424
"output-structure.smithy",
25-
".ser("
25+
new String[] {".ser("}
2626
);
2727
}
2828

2929
@Test
3030
public void writesDeserializer() {
3131
testCommmandCodegen(
3232
"output-structure.smithy",
33-
".de("
33+
new String[] {".de("}
3434
);
3535
}
3636

37-
private void testCommmandCodegen(String file, String expectedType) {
38-
Model model = Model.assembler()
39-
.addImport(getClass().getResource(file))
40-
.assemble()
41-
.unwrap();
37+
@Test
38+
public void writesOperationContextParamValues() {
39+
testCommmandCodegen(
40+
"endpointsV2/endpoints-operation-context-params.smithy",
41+
new String[] {
42+
"opContextParamIdentifier: { type: \"operationContextParams\", name: this.input.fooString }",
43+
"opContextParamSubExpression: { type: \"operationContextParams\", name: this.input.fooObj.bar }",
44+
}
45+
);
46+
}
47+
48+
private void testCommmandCodegen(String filename, String[] expectedTypeArray) {
4249
MockManifest manifest = new MockManifest();
4350
PluginContext context = PluginContext.builder()
44-
.model(model)
45-
.fileManifest(manifest)
46-
.settings(Node.objectNodeBuilder()
47-
.withMember("service", Node.from("smithy.example#Example"))
48-
.withMember("package", Node.from("example"))
49-
.withMember("packageVersion", Node.from("1.0.0"))
50-
.build())
51-
.build();
51+
.pluginClassLoader(getClass().getClassLoader())
52+
.model(Model.assembler()
53+
.addImport(getClass().getResource(filename))
54+
.discoverModels()
55+
.assemble()
56+
.unwrap())
57+
.fileManifest(manifest)
58+
.settings(Node.objectNodeBuilder()
59+
.withMember("service", Node.from("smithy.example#Example"))
60+
.withMember("package", Node.from("example"))
61+
.withMember("packageVersion", Node.from("1.0.0"))
62+
.build())
63+
.build();
5264

5365
new TypeScriptCodegenPlugin().execute(context);
5466
String contents = manifest.getFileString(CodegenUtils.SOURCE_FOLDER + "//commands/GetFooCommand.ts").get();
5567

5668
assertThat(contents, containsString("as __MetadataBearer"));
57-
assertThat(contents, containsString(expectedType));
69+
for (String expectedType : expectedTypeArray) {
70+
assertThat(contents, containsString(expectedType));
71+
}
5872
}
5973
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
$version: "2.0"
2+
3+
namespace smithy.example
4+
5+
@smithy.rules#endpointRuleSet({
6+
version: "1.0",
7+
parameters: {
8+
opContextParamIdentifier: {
9+
type: "string",
10+
},
11+
opContextParamSubExpression: {
12+
type: "string",
13+
},
14+
},
15+
rules: []
16+
})
17+
service Example {
18+
version: "1.0.0",
19+
operations: [GetFoo]
20+
}
21+
22+
@smithy.rules#operationContextParams(
23+
"opContextParamIdentifier": { path: "fooString" }
24+
"opContextParamSubExpression": { path: "fooObj.bar" }
25+
)
26+
operation GetFoo {
27+
input: GetFooInput,
28+
output: GetFooOutput,
29+
errors: [GetFooError]
30+
}
31+
32+
structure GetFooInput {
33+
fooString: String,
34+
fooObj: FooObject
35+
}
36+
37+
structure FooObject {
38+
bar: String
39+
}
40+
41+
structure GetFooOutput {}
42+
43+
@error("client")
44+
structure GetFooError {}

0 commit comments

Comments
 (0)