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 9ece50ab13e..6efd9c0f2c8 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 @@ -22,6 +22,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; @@ -486,13 +487,23 @@ static void writeModelIndex(Collection shapes, SymbolProvider symbolProvi FileManifest fileManifest) { TypeScriptWriter writer = new TypeScriptWriter(""); String modelPrefix = String.join("/", ".", CodegenUtils.SOURCE_FOLDER, SHAPE_NAMESPACE_PREFIX); - shapes.stream() + List collectedModelNamespaces = shapes.stream() .map(shape -> symbolProvider.toSymbol(shape).getNamespace()) .filter(namespace -> namespace.startsWith(modelPrefix)) .distinct() .sorted(Comparator.naturalOrder()) .map(namespace -> namespace.replaceFirst(Matcher.quoteReplacement(modelPrefix), ".")) - .forEach(namespace -> writer.write("export * from $S;", namespace)); + .toList(); + + // Export empty model index if no models_* files are present + if (collectedModelNamespaces.isEmpty()) { + writer.write("export {};"); + } else { + for (String namespace : collectedModelNamespaces) { + writer.write("export * from $S;", namespace); + } + } + fileManifest.writeFile( Paths.get(CodegenUtils.SOURCE_FOLDER, SHAPE_NAMESPACE_PREFIX, "index.ts").toString(), writer.toString());