From facb30871e5cedcdb875835a9434974282ebaf30 Mon Sep 17 00:00:00 2001 From: George Fu Date: Wed, 8 Mar 2023 15:10:24 -0500 Subject: [PATCH] model bucketing: special case for smithy.api#Unit (#714) * model bucketing: special case for smithy.api#Unit * update UnitTypeTrait equality check --- .../typescript/codegen/SymbolVisitor.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) 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 723d7e89cf8..0a478152036 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 @@ -67,6 +67,7 @@ import software.amazon.smithy.model.traits.EnumTrait; import software.amazon.smithy.model.traits.MediaTypeTrait; import software.amazon.smithy.model.traits.StreamingTrait; +import software.amazon.smithy.model.traits.UnitTypeTrait; import software.amazon.smithy.utils.SmithyInternalApi; import software.amazon.smithy.utils.StringUtils; @@ -458,13 +459,20 @@ public String formatModuleName(Shape shape, String name) { return visitedModels.get(shape); } // Add models into buckets no bigger than chunk size. - String path = String.join("/", ".", SHAPE_NAMESPACE_PREFIX, "models_" + bucketCount); - visitedModels.put(shape, path); - currentBucketSize++; - if (currentBucketSize == chunkSize) { - bucketCount++; - currentBucketSize = 0; + String path; + if (shape.getId().equals(UnitTypeTrait.UNIT)) { + // Unit should only be put in the zero bucket, since it does not + // generate anything. It also does not contribute to bucket size. + path = String.join("/", ".", SHAPE_NAMESPACE_PREFIX, "models_0"); + } else { + path = String.join("/", ".", SHAPE_NAMESPACE_PREFIX, "models_" + bucketCount); + currentBucketSize++; + if (currentBucketSize == chunkSize) { + bucketCount++; + currentBucketSize = 0; + } } + visitedModels.put(shape, path); return path; }