Skip to content

Commit

Permalink
model bucketing: special case for smithy.api#Unit (smithy-lang#714)
Browse files Browse the repository at this point in the history
* model bucketing: special case for smithy.api#Unit

* update UnitTypeTrait equality check
  • Loading branch information
kuhe authored and srchase committed Mar 17, 2023
1 parent 584e032 commit facb308
Showing 1 changed file with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit facb308

Please sign in to comment.