Skip to content

Commit c26e756

Browse files
Use server symbol provider in protocol test gen
1 parent 1a6a906 commit c26e756

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CodegenVisitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ void execute() {
213213
// Generate protocol tests IFF found in the model.
214214
if (protocolGenerator != null) {
215215
ShapeId protocol = protocolGenerator.getProtocol();
216-
new HttpProtocolTestGenerator(settings, model, protocol, symbolProvider, writers, protocolGenerator).run();
216+
new HttpProtocolTestGenerator(
217+
settings, model, protocol, symbolProvider, serverSymbolProvider, writers, protocolGenerator).run();
217218
}
218219

219220
// Write each pending writer.

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ final class HttpProtocolTestGenerator implements Runnable {
9191
private final ServiceShape service;
9292
private final SymbolProvider symbolProvider;
9393
private final Symbol serviceSymbol;
94+
private final SymbolProvider serverSymbolProvider;
9495
private final Set<String> additionalStubs = new TreeSet<>();
9596
private final ProtocolGenerator protocolGenerator;
9697

@@ -105,6 +106,7 @@ final class HttpProtocolTestGenerator implements Runnable {
105106
Model model,
106107
ShapeId protocol,
107108
SymbolProvider symbolProvider,
109+
SymbolProvider serverSymbolProvider,
108110
TypeScriptDelegator delegator,
109111
ProtocolGenerator protocolGenerator
110112
) {
@@ -113,6 +115,7 @@ final class HttpProtocolTestGenerator implements Runnable {
113115
this.protocol = protocol;
114116
this.service = settings.getService(model);
115117
this.symbolProvider = symbolProvider;
118+
this.serverSymbolProvider = serverSymbolProvider;
116119
this.delegator = delegator;
117120
this.protocolGenerator = protocolGenerator;
118121
serviceSymbol = symbolProvider.toSymbol(service);
@@ -247,7 +250,7 @@ private void generateClientRequestTest(OperationShape operation, HttpRequestTest
247250
}
248251

249252
private void generateServerRequestTest(OperationShape operation, HttpRequestTestCase testCase) {
250-
Symbol operationSymbol = symbolProvider.toSymbol(operation);
253+
Symbol operationSymbol = serverSymbolProvider.toSymbol(operation);
251254

252255
// Lowercase all the headers we're expecting as this is what we'll get.
253256
Map<String, String> headers = testCase.getHeaders().entrySet().stream()
@@ -260,9 +263,8 @@ private void generateServerRequestTest(OperationShape operation, HttpRequestTest
260263
String testName = testCase.getId() + ":ServerRequest";
261264
testCase.getDocumentation().ifPresent(writer::writeDocs);
262265
writer.openBlock("it($S, async () => {", "});\n", testName, () -> {
263-
// TODO: use the symbol provider when it's ready
264-
String serviceName = StringUtils.capitalize(service.getId().getName());
265-
String operationName = StringUtils.capitalize(operation.getId().getName());
266+
Symbol serviceSymbol = serverSymbolProvider.toSymbol(service);
267+
Symbol handlerSymbol = serviceSymbol.expectProperty("handler", Symbol.class);
266268
Symbol inputType = operationSymbol.expectProperty("inputType", Symbol.class);
267269
Symbol outputType = operationSymbol.expectProperty("outputType", Symbol.class);
268270

@@ -274,18 +276,18 @@ private void generateServerRequestTest(OperationShape operation, HttpRequestTest
274276
// We use a partial here so that we don't have to define the entire service, but still get the advantages
275277
// the type checker, including excess property checking. Later on we'll use `as` to cast this to the
276278
// full service so that we can actually use it.
277-
writer.addImport(serviceName + "Service", null, "./server");
278-
writer.openBlock("const testService: Partial<$LService> = {", "};", serviceName, () -> {
279+
writer.openBlock("const testService: Partial<$T> = {", "};", serviceSymbol, () -> {
279280
writer.addImport("Operation", "__Operation", "@aws-smithy/server-common");
280-
writer.write("$L: testFunction as __Operation<$T, $T>,", operationName, inputType, outputType);
281+
writer.write("$L: testFunction as __Operation<$T, $T>,",
282+
operationSymbol.getName(), inputType, outputType);
281283
});
282284

283-
String getHandlerName = String.format("get%sServiceHandler", serviceName);
285+
String getHandlerName = "get" + handlerSymbol.getName();
284286
writer.addImport(getHandlerName, getHandlerName,
285287
"./protocols/" + ProtocolGenerator.getSanitizedName(protocolGenerator.getName()));
286288

287289
// Cast the service as any so TS will ignore the fact that the type being passed in is incomplete.
288-
writer.write("const handler = $L(testService as $LService);", getHandlerName, serviceName);
290+
writer.write("const handler = $L(testService as $T);", getHandlerName, serviceSymbol);
289291

290292
// Construct a new http request according to the test case definition.
291293
writer.openBlock("const request = new HttpRequest({", "});", () -> {

0 commit comments

Comments
 (0)