Skip to content

Commit

Permalink
Changed scalar removal to WARNING
Browse files Browse the repository at this point in the history
  • Loading branch information
rchache committed Jan 2, 2024
1 parent aa46e55 commit 6dd4e07
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.util.stream.Collectors;
import software.amazon.smithy.diff.Differences;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeType;
import software.amazon.smithy.model.traits.EnumTrait;
import software.amazon.smithy.model.traits.PrivateTrait;
import software.amazon.smithy.model.validation.Severity;
import software.amazon.smithy.model.validation.ValidationEvent;

/**
Expand All @@ -33,8 +35,14 @@ public List<ValidationEvent> evaluate(Differences differences) {
return differences.removedShapes()
.filter(shape -> !shape.hasTrait(PrivateTrait.class))
.filter(shape -> !isMemberOfRemovedShape(shape, differences))
.map(shape -> isScalarType(shape)
? note(shape, String.format("Removed %s `%s`", shape.getType(), shape.getId()))
.map(shape -> isInconsequentialType(shape)
? ValidationEvent.builder()
.severity(Severity.WARNING)
.message(String.format("Removed %s `%s`", shape.getType(), shape.getId()))
.shapeId(shape.getId())
.id(getEventId() + ".ScalarShape")
.sourceLocation(shape.getSourceLocation())
.build()
: error(shape, String.format("Removed %s `%s`", shape.getType(), shape.getId())))
.collect(Collectors.toList());
}
Expand All @@ -45,18 +53,19 @@ private boolean isMemberOfRemovedShape(Shape shape, Differences differences) {
.isPresent();
}

private boolean isScalarType(Shape shape) {
return shape.isBigDecimalShape()
|| shape.isBigIntegerShape()
|| shape.isBlobShape()
|| shape.isBooleanShape()
|| shape.isByteShape()
|| shape.isDoubleShape()
|| shape.isFloatShape()
|| shape.isShortShape()
|| shape.isTimestampShape()
|| shape.isLongShape()
|| (shape.isStringShape() && !shape.hasTrait(EnumTrait.class))
|| (shape.isIntegerShape() && !shape.isIntEnumShape());
private boolean isInconsequentialType(Shape shape) {
ShapeType shapeType = shape.getType();
return shapeType == ShapeType.BIG_DECIMAL
|| shapeType == ShapeType.BIG_INTEGER
|| shapeType == ShapeType.BLOB
|| shapeType == ShapeType.BOOLEAN
|| shapeType == ShapeType.BYTE
|| shapeType == ShapeType.DOUBLE
|| shapeType == ShapeType.FLOAT
|| shapeType == ShapeType.SHORT
|| shapeType == ShapeType.TIMESTAMP
|| shapeType == ShapeType.LONG
|| ((shapeType == ShapeType.STRING) && !shape.hasTrait(EnumTrait.class))
|| (shapeType == ShapeType.INTEGER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void detectsShapeRemoval() {
}

@Test
public void emitsNotesForScalarShapes() {
public void emitsWarningsForScalarShapes() {
Shape[] scalarShapes = new Shape[] {
IntegerShape.builder().id("foo.baz#BazOne").build(),
BigDecimalShape.builder().id("foo.baz#BazTwo").build(),
Expand All @@ -81,9 +81,9 @@ public void emitsNotesForScalarShapes() {
Model modelB = Model.assembler().assemble().unwrap();
List<ValidationEvent> events = ModelDiff.compare(modelA, modelB);

assertThat(TestHelper.findEvents(events, "RemovedShape").size(), equalTo(12));
assertThat("Scalar removals should be NOTE severity",
events.stream().allMatch(event -> Severity.NOTE.equals(event.getSeverity())));
assertThat(TestHelper.findEvents(events, "RemovedShape.ScalarShape").size(), equalTo(12));
assertThat("Scalar removals should be WARNING severity",
events.stream().allMatch(event -> Severity.WARNING.equals(event.getSeverity())));
}

@Test
Expand Down

0 comments on commit 6dd4e07

Please sign in to comment.