Skip to content

Commit 15133ec

Browse files
committed
Use a delegate file writer for protocol gen
1 parent e494cbd commit 15133ec

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -262,21 +262,20 @@ public Void serviceShape(ServiceShape shape) {
262262

263263
if (protocolGenerator != null) {
264264
LOGGER.info("Generating serde for protocol " + protocolGenerator.getName() + " on " + shape.getId());
265-
String fileRoot = "protocols/" + ProtocolGenerator.getSanitizedName(protocolGenerator.getName());
266-
String namespace = "./" + fileRoot;
267-
TypeScriptWriter writer = new TypeScriptWriter(namespace);
268-
ProtocolGenerator.GenerationContext context = new ProtocolGenerator.GenerationContext();
269-
context.setProtocolName(protocolGenerator.getName());
270-
context.setIntegrations(integrations);
271-
context.setModel(model);
272-
context.setService(shape);
273-
context.setSettings(settings);
274-
context.setSymbolProvider(symbolProvider);
275-
context.setWriter(writer);
276-
protocolGenerator.generateRequestSerializers(context);
277-
protocolGenerator.generateResponseDeserializers(context);
278-
protocolGenerator.generateSharedComponents(context);
279-
fileManifest.writeFile(fileRoot + ".ts", writer.toString());
265+
String fileName = "protocols/" + ProtocolGenerator.getSanitizedName(protocolGenerator.getName()) + ".ts";
266+
writers.useFileWriter(fileName, writer -> {
267+
ProtocolGenerator.GenerationContext context = new ProtocolGenerator.GenerationContext();
268+
context.setProtocolName(protocolGenerator.getName());
269+
context.setIntegrations(integrations);
270+
context.setModel(model);
271+
context.setService(shape);
272+
context.setSettings(settings);
273+
context.setSymbolProvider(symbolProvider);
274+
context.setWriter(writer);
275+
protocolGenerator.generateRequestSerializers(context);
276+
protocolGenerator.generateResponseDeserializers(context);
277+
protocolGenerator.generateSharedComponents(context);
278+
});
280279
}
281280

282281
return null;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
* module paths against the moduleName of the writer. Module names that
4848
* start with anything other than "." (e.g., "@", "/", etc.) are never
4949
* relativized.
50+
*
51+
* <p>Dependencies introduced via a TypeScriptWriter are added to the package.json
52+
* file if the writer is a part of the {@link TypeScriptDelegator} of the {@link CodegenVisitor}.
5053
*/
5154
public final class TypeScriptWriter extends CodeWriter {
5255

@@ -224,8 +227,8 @@ boolean writeMemberDocs(Model model, MemberShape member) {
224227
/**
225228
* Adds one or more dependencies to the generated code.
226229
*
227-
* <p>The dependencies of all writers are merged together to eventually generate
228-
* a package.json file.
230+
* <p>The dependencies of all writers created by the {@link TypeScriptDelegator}
231+
* are merged together to eventually generate a package.json file.
229232
*
230233
* @param dependencies TypeScriptDependency to add.
231234
* @return Returns the writer.

0 commit comments

Comments
 (0)