diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CodegenVisitor.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CodegenVisitor.java index d4df91ccfea..5ee7341ffc7 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CodegenVisitor.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CodegenVisitor.java @@ -15,6 +15,7 @@ package software.amazon.smithy.typescript.codegen; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; @@ -373,8 +374,8 @@ public Void serviceShape(ServiceShape shape) { if (protocolGenerator != null) { LOGGER.info("Generating serde for protocol " + protocolGenerator.getName() + " on " + shape.getId()); - String fileName = CodegenUtils.SOURCE_FOLDER + "/protocols/" - + ProtocolGenerator.getSanitizedName(protocolGenerator.getName()) + ".ts"; + String fileName = Paths.get(CodegenUtils.SOURCE_FOLDER, ProtocolGenerator.PROTOCOLS_FOLDER, + ProtocolGenerator.getSanitizedName(protocolGenerator.getName()) + ".ts").toString(); writers.useFileWriter(fileName, writer -> { ProtocolGenerator.GenerationContext context = new ProtocolGenerator.GenerationContext(); context.setProtocolName(protocolGenerator.getName()); diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java index 01b2f8fae48..09bfc673113 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java @@ -18,6 +18,7 @@ import static software.amazon.smithy.typescript.codegen.CodegenUtils.getBlobStreamingMembers; import static software.amazon.smithy.typescript.codegen.CodegenUtils.writeStreamingMemberType; +import java.nio.file.Paths; import java.util.List; import java.util.Map; import java.util.Optional; @@ -45,6 +46,7 @@ @SmithyInternalApi final class CommandGenerator implements Runnable { + static final String COMMANDS_FOLDER = "commands"; static final String COMMAND_PROPERTIES_SECTION = "command_properties"; static final String COMMAND_BODY_EXTRA_SECTION = "command_body_extra"; static final String COMMAND_CONSTRUCTOR_SECTION = "command_constructor"; @@ -299,8 +301,8 @@ private void writeSerdeDispatcher(boolean isInput) { ? ProtocolGenerator.getSerFunctionName(symbol, protocolGenerator.getName()) : ProtocolGenerator.getDeserFunctionName(symbol, protocolGenerator.getName()); writer.addImport(serdeFunctionName, serdeFunctionName, - "./" + CodegenUtils.SOURCE_FOLDER + "/protocols/" - + ProtocolGenerator.getSanitizedName(protocolGenerator.getName())); + Paths.get(".", CodegenUtils.SOURCE_FOLDER, ProtocolGenerator.PROTOCOLS_FOLDER, + ProtocolGenerator.getSanitizedName(protocolGenerator.getName())).toString()); writer.write("return $L($L, context);", serdeFunctionName, isInput ? "input" : "output"); } } @@ -319,6 +321,8 @@ static void writeIndex( writer.write("export * from \"./$L\";", symbolProvider.toSymbol(operation).getName()); } - fileManifest.writeFile(CodegenUtils.SOURCE_FOLDER + "/commands/index.ts", writer.toString()); + fileManifest.writeFile( + Paths.get(CodegenUtils.SOURCE_FOLDER, CommandGenerator.COMMANDS_FOLDER, "index.ts").toString(), + writer.toString()); } } diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java index 650796abb3b..af55e09f933 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/HttpProtocolTestGenerator.java @@ -20,6 +20,7 @@ import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; +import java.nio.file.Paths; import java.util.List; import java.util.Locale; import java.util.Map; @@ -407,7 +408,8 @@ private void setupStubService(Symbol operationSymbol, }); String getHandlerName = "get" + handlerSymbol.getName(); - writer.addImport(getHandlerName, null, "./" + CodegenUtils.SOURCE_FOLDER + "/server/"); + writer.addImport(getHandlerName, null, + Paths.get(".", CodegenUtils.SOURCE_FOLDER, ServerSymbolVisitor.SERVER_FOLDER).toString()); if (!usesDefaultValidation) { writer.addImport("ValidationFailure", "__ValidationFailure", "@aws-smithy/server-common"); @@ -745,8 +747,8 @@ private void writeServerResponseTest(OperationShape operation, HttpResponseTestC + " { return new TestSerializer(); };", serviceOperationsSymbol, serviceSymbol); writer.addImport("serializeFrameworkException", null, - "./" + CodegenUtils.SOURCE_FOLDER + "/protocols/" - + ProtocolGenerator.getSanitizedName(protocolGenerator.getName())); + Paths.get(".", CodegenUtils.SOURCE_FOLDER, ProtocolGenerator.PROTOCOLS_FOLDER, + ProtocolGenerator.getSanitizedName(protocolGenerator.getName())).toString()); writer.addImport("ValidationFailure", "__ValidationFailure", "@aws-smithy/server-common"); writer.write("const handler = new $T(service, testMux, serFn, serializeFrameworkException, " + "(ctx: {}, f: __ValidationFailure[]) => { if (f) { throw f; } return undefined;});", handlerSymbol); diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/IndexGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/IndexGenerator.java index 558d62589df..4d5bf382594 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/IndexGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/IndexGenerator.java @@ -15,6 +15,7 @@ package software.amazon.smithy.typescript.codegen; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import software.amazon.smithy.build.FileManifest; @@ -59,7 +60,7 @@ static void writeIndex( // write export statement for models writer.write("export * from \"./models\";"); - fileManifest.writeFile(CodegenUtils.SOURCE_FOLDER + "/index.ts", writer.toString()); + fileManifest.writeFile(Paths.get(CodegenUtils.SOURCE_FOLDER, "index.ts").toString(), writer.toString()); } private static void writeProtocolExports(ProtocolGenerator protocolGenerator, TypeScriptWriter writer) { @@ -81,7 +82,9 @@ static void writeServerIndex( writer.write("export * from \"./operations\";"); writer.write("export * from \"./$L\"", symbol.getName()); - fileManifest.writeFile(CodegenUtils.SOURCE_FOLDER + "/server/index.ts", writer.toString()); + fileManifest.writeFile( + Paths.get(CodegenUtils.SOURCE_FOLDER, ServerSymbolVisitor.SERVER_FOLDER, "index.ts").toString(), + writer.toString()); } private static void writeClientExports( @@ -123,6 +126,6 @@ private static void writeClientExports( for (TypeScriptIntegration integration : integrations) { integration.writeAdditionalExports(settings, model, symbolProvider, writer); } - fileManifest.writeFile(CodegenUtils.SOURCE_FOLDER + "/index.ts", writer.toString()); + fileManifest.writeFile(Paths.get(CodegenUtils.SOURCE_FOLDER, "index.ts").toString(), writer.toString()); } } diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/LanguageTarget.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/LanguageTarget.java index 431ef48f69c..0039e74155f 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/LanguageTarget.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/LanguageTarget.java @@ -15,6 +15,7 @@ package software.amazon.smithy.typescript.codegen; +import java.nio.file.Paths; import software.amazon.smithy.utils.SmithyUnstableApi; /** @@ -68,6 +69,6 @@ String getTemplateFileName() { abstract String getTemplateFileName(); String getTargetFilename() { - return CodegenUtils.SOURCE_FOLDER + "/" + getTemplateFileName().replace(".template", ""); + return Paths.get(CodegenUtils.SOURCE_FOLDER, getTemplateFileName().replace(".template", "")).toString(); } } diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/PaginationGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/PaginationGenerator.java index e4f235ccde2..e50df865418 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/PaginationGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/PaginationGenerator.java @@ -16,6 +16,7 @@ package software.amazon.smithy.typescript.codegen; +import java.nio.file.Paths; import java.util.Optional; import java.util.Set; import java.util.TreeSet; @@ -35,7 +36,9 @@ @SmithyInternalApi final class PaginationGenerator implements Runnable { - static final String PAGINATION_INTERFACE_FILE = CodegenUtils.SOURCE_FOLDER + "/pagination/Interfaces.ts"; + static final String PAGINATION_FOLDER = "pagination"; + static final String PAGINATION_INTERFACE_FILE = + Paths.get(CodegenUtils.SOURCE_FOLDER, PAGINATION_FOLDER, "Interfaces.ts").toString(); private final TypeScriptWriter writer; private final PaginationInfo paginatedInfo; @@ -99,7 +102,8 @@ public void run() { // Import Pagination types writer.addImport("Paginator", "Paginator", "@aws-sdk/types"); - writer.addImport(paginationType, paginationType, "./" + PAGINATION_INTERFACE_FILE.replace(".ts", "")); + writer.addImport(paginationType, paginationType, + Paths.get(".", PAGINATION_INTERFACE_FILE.replace(".ts", "")).toString()); writeCommandRequest(); writeMethodRequest(); @@ -107,7 +111,8 @@ public void run() { } static String getOutputFilelocation(OperationShape operation) { - return CodegenUtils.SOURCE_FOLDER + "/pagination/" + operation.getId().getName() + "Paginator.ts"; + return Paths.get(CodegenUtils.SOURCE_FOLDER, PAGINATION_FOLDER, + operation.getId().getName() + "Paginator.ts").toString(); } static void generateServicePaginationInterfaces( @@ -150,7 +155,9 @@ static void writeIndex( } } - fileManifest.writeFile(CodegenUtils.SOURCE_FOLDER + "/pagination/index.ts", writer.toString()); + fileManifest.writeFile( + Paths.get(CodegenUtils.SOURCE_FOLDER, PAGINATION_FOLDER, "index.ts").toString(), + writer.toString()); } private String destructurePath(String path) { diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServerCommandGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServerCommandGenerator.java index d788248a5e1..5782b7ce9d9 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServerCommandGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServerCommandGenerator.java @@ -18,6 +18,7 @@ import static software.amazon.smithy.typescript.codegen.CodegenUtils.getBlobStreamingMembers; import static software.amazon.smithy.typescript.codegen.CodegenUtils.writeStreamingMemberType; +import java.nio.file.Paths; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -43,6 +44,8 @@ @SmithyInternalApi final class ServerCommandGenerator implements Runnable { + static final String COMMANDS_FOLDER = "operations"; + private final TypeScriptSettings settings; private final Model model; private final OperationShape operation; @@ -175,12 +178,14 @@ private void writeOperationSerializer() { serializerName, serverSymbol, operationSymbol.getName(), errorsType, () -> { String serializerFunction = ProtocolGenerator.getGenericSerFunctionName(operationSymbol) + "Response"; String deserializerFunction = ProtocolGenerator.getGenericDeserFunctionName(operationSymbol) + "Request"; + writer.addImport(serializerFunction, null, - "./" + CodegenUtils.SOURCE_FOLDER + "/protocols/" - + ProtocolGenerator.getSanitizedName(protocolGenerator.getName())); + Paths.get(".", CodegenUtils.SOURCE_FOLDER, ProtocolGenerator.PROTOCOLS_FOLDER, + ProtocolGenerator.getSanitizedName(protocolGenerator.getName())).toString()); writer.addImport(deserializerFunction, null, - "./" + CodegenUtils.SOURCE_FOLDER + "/protocols/" - + ProtocolGenerator.getSanitizedName(protocolGenerator.getName())); + Paths.get(".", CodegenUtils.SOURCE_FOLDER, ProtocolGenerator.PROTOCOLS_FOLDER, + ProtocolGenerator.getSanitizedName(protocolGenerator.getName())).toString()); + writer.write("serialize = $L;", serializerFunction); writer.write("deserialize = $L;", deserializerFunction); writer.write(""); @@ -231,8 +236,8 @@ private void writeErrorHandlerCase(StructureShape error) { Symbol errorSymbol = symbolProvider.toSymbol(error); String serializerFunction = ProtocolGenerator.getGenericSerFunctionName(errorSymbol) + "Error"; writer.addImport(serializerFunction, null, - "./" + CodegenUtils.SOURCE_FOLDER + "/protocols/" - + ProtocolGenerator.getSanitizedName(protocolGenerator.getName())); + Paths.get(".", CodegenUtils.SOURCE_FOLDER, ProtocolGenerator.PROTOCOLS_FOLDER, + ProtocolGenerator.getSanitizedName(protocolGenerator.getName())).toString()); writer.openBlock("case $S: {", "}", error.getId().getName(), () -> { writer.write("return $L(error, ctx);", serializerFunction); }); @@ -252,6 +257,9 @@ static void writeIndex( writer.write("export * from \"./$L\";", symbolProvider.toSymbol(operation).getName()); } - fileManifest.writeFile(CodegenUtils.SOURCE_FOLDER + "/server/operations/index.ts", writer.toString()); + fileManifest.writeFile( + Paths.get(CodegenUtils.SOURCE_FOLDER, ServerSymbolVisitor.SERVER_FOLDER, COMMANDS_FOLDER, "index.ts") + .toString(), + writer.toString()); } } diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServerSymbolVisitor.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServerSymbolVisitor.java index d8ee4a8badb..746c4338273 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServerSymbolVisitor.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServerSymbolVisitor.java @@ -17,6 +17,7 @@ import static software.amazon.smithy.typescript.codegen.TypeScriptDependency.SERVER_COMMON; +import java.nio.file.Paths; import java.util.logging.Logger; import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider; import software.amazon.smithy.codegen.core.ReservedWords; @@ -38,6 +39,7 @@ */ @SmithyInternalApi final class ServerSymbolVisitor extends ShapeVisitor.Default implements SymbolProvider { + static final String SERVER_FOLDER = "server"; private static final Logger LOGGER = Logger.getLogger(ServerSymbolVisitor.class.getName()); private final Model model; @@ -118,8 +120,8 @@ private String flattenShapeName(ToShapeId id) { } private Symbol.Builder createGeneratedSymbolBuilder(Shape shape, String typeName, String namespace) { - String prefixedNamespace = "./" + CodegenUtils.SOURCE_FOLDER - + (namespace.startsWith(".") ? namespace.substring(1) : namespace); + String prefixedNamespace = Paths.get(".", CodegenUtils.SOURCE_FOLDER, + (namespace.startsWith(".") ? namespace.substring(1) : namespace)).toString(); return createSymbolBuilder(shape, typeName, prefixedNamespace) .definitionFile(toFilename(prefixedNamespace)); } @@ -139,9 +141,9 @@ static final class ModuleNameDelegator { public String formatModuleName(Shape shape, String name) { if (shape.getType() == ShapeType.SERVICE) { - return "/server/" + name; + return Paths.get(SERVER_FOLDER, name).toString(); } else if (shape.getType() == ShapeType.OPERATION) { - return "/server/operations/" + name; + return Paths.get(SERVER_FOLDER, ServerCommandGenerator.COMMANDS_FOLDER, name).toString(); } throw new IllegalArgumentException("Unsupported shape type: " + shape.getType()); diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServiceBareBonesClientGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServiceBareBonesClientGenerator.java index cefb4436247..4ebfe2bac5d 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServiceBareBonesClientGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/ServiceBareBonesClientGenerator.java @@ -15,6 +15,7 @@ package software.amazon.smithy.typescript.codegen; +import java.nio.file.Paths; import java.util.Comparator; import java.util.List; import java.util.Map; @@ -93,7 +94,7 @@ static String getResolvedConfigTypeName(Symbol symbol) { public void run() { writer.addImport("Client", "__Client", "@aws-sdk/smithy-client"); writer.addImport("getRuntimeConfig", "__getRuntimeConfig", - "./" + CodegenUtils.SOURCE_FOLDER + "/runtimeConfig"); + Paths.get(".", CodegenUtils.SOURCE_FOLDER, "runtimeConfig").toString()); // Normalize the input and output types of the command to account for // things like an operation adding input where there once wasn't any diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java index 1f9d15ac602..127c93ad6e7 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/SymbolVisitor.java @@ -17,6 +17,7 @@ import static java.lang.String.format; +import java.nio.file.Paths; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; @@ -407,8 +408,8 @@ private Symbol.Builder createSymbolBuilder(Shape shape, String typeName, String } private Symbol.Builder createGeneratedSymbolBuilder(Shape shape, String typeName, String namespace) { - String prefixedNamespace = "./" + CodegenUtils.SOURCE_FOLDER - + (namespace.startsWith(".") ? namespace.substring(1) : namespace); + String prefixedNamespace = Paths.get(".", CodegenUtils.SOURCE_FOLDER, + (namespace.startsWith(".") ? namespace.substring(1) : namespace)).toString(); return createSymbolBuilder(shape, typeName, prefixedNamespace) .definitionFile(toFilename(prefixedNamespace)); } @@ -423,7 +424,7 @@ private String toFilename(String namespace) { */ static final class ModuleNameDelegator { static final int DEFAULT_CHUNK_SIZE = 300; - static final String SHAPE_NAMESPACE_PREFIX = "/models/"; + static final String SHAPE_NAMESPACE_PREFIX = "models"; private final Map visitedModels = new HashMap<>(); private int bucketCount = 0; @@ -437,14 +438,14 @@ static final class ModuleNameDelegator { public String formatModuleName(Shape shape, String name) { // All shapes except for the service and operations are stored in models. if (shape.getType() == ShapeType.SERVICE) { - return "./" + name; + return Paths.get(".", name).toString(); } else if (shape.getType() == ShapeType.OPERATION) { - return "./commands/" + name; + return Paths.get(".", CommandGenerator.COMMANDS_FOLDER, name).toString(); } else if (visitedModels.containsKey(shape)) { return visitedModels.get(shape); } // Add models into buckets no bigger than chunk size. - String path = "." + SHAPE_NAMESPACE_PREFIX + "models_" + bucketCount; + String path = Paths.get(".", SHAPE_NAMESPACE_PREFIX, "models_" + bucketCount).toString(); visitedModels.put(shape, path); currentBucketSize++; if (currentBucketSize == chunkSize) { @@ -456,15 +457,17 @@ public String formatModuleName(Shape shape, String name) { static void writeModelIndex(Model model, SymbolProvider symbolProvider, FileManifest fileManifest) { TypeScriptWriter writer = new TypeScriptWriter(""); - String modelPrefix = "./" + CodegenUtils.SOURCE_FOLDER + SHAPE_NAMESPACE_PREFIX; + String modelPrefix = Paths.get(".", CodegenUtils.SOURCE_FOLDER, SHAPE_NAMESPACE_PREFIX).toString(); model.shapes() .map(shape -> symbolProvider.toSymbol(shape).getNamespace()) .filter(namespace -> namespace.startsWith(modelPrefix)) .distinct() .sorted(Comparator.naturalOrder()) .forEach(namespace -> writer.write( - "export * from $S;", namespace.replaceFirst(modelPrefix, "./"))); - fileManifest.writeFile(CodegenUtils.SOURCE_FOLDER + "/models/index.ts", writer.toString()); + "export * from $S;", namespace.replaceFirst(modelPrefix, "."))); + fileManifest.writeFile( + Paths.get(CodegenUtils.SOURCE_FOLDER, SHAPE_NAMESPACE_PREFIX, "index.ts").toString(), + writer.toString()); } } } diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDelegator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDelegator.java index 5383c8666ee..ac183a9ca3e 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDelegator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/TypeScriptDelegator.java @@ -90,8 +90,8 @@ void useShapeWriter(Shape shape, SymbolProvider provider, Consumer