Skip to content

Commit

Permalink
minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
rchache committed Nov 27, 2024
1 parent 8c5e45d commit e70266f
Showing 1 changed file with 10 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import software.amazon.smithy.model.shapes.ShapeType;
import software.amazon.smithy.model.shapes.ShapeVisitor;
import software.amazon.smithy.model.shapes.StructureShape;
import software.amazon.smithy.model.shapes.TimestampShape;
import software.amazon.smithy.model.shapes.UnionShape;
import software.amazon.smithy.model.validation.AbstractValidator;
import software.amazon.smithy.model.validation.ValidationEvent;
Expand Down Expand Up @@ -114,25 +113,20 @@ public List<ValidationEvent> validate(Model model) {
@Override
protected List<ValidationEvent> getDefault(Shape shape) {
if (shape.isStringShape() || shape instanceof NumberShape) {
return validateSimpleShape(shape, patterns);
return validateSimpleShape(shape);
} else {
return Collections.emptyList();
}
}

@Override
public List<ValidationEvent> structureShape(StructureShape shape) {
return validateStructure(shape, model, patterns);
return validateStructure(shape, model);
}

@Override
public List<ValidationEvent> unionShape(UnionShape shape) {
return validateUnion(shape, model, patterns);
}

@Override
public List<ValidationEvent> timestampShape(TimestampShape shape) {
return Collections.emptyList();
return validateUnion(shape, model);
}

@Override
Expand All @@ -146,43 +140,39 @@ public List<ValidationEvent> enumShape(EnumShape shape) {

private List<ValidationEvent> validateStructure(
StructureShape structure,
Model model,
List<Pattern> patterns
Model model
) {
return structure
.getAllMembers()
.entrySet()
.stream()
.flatMap(entry -> validateTargetShape(entry.getKey(), entry.getValue(), model, patterns))
.flatMap(entry -> validateTargetShape(entry.getKey(), entry.getValue(), model))
.collect(Collectors.toList());
}

private List<ValidationEvent> validateUnion(
UnionShape union,
Model model,
List<Pattern> patterns
Model model
) {
return union
.getAllMembers()
.entrySet()
.stream()
.flatMap(entry -> validateTargetShape(entry.getKey(), entry.getValue(), model, patterns))
.flatMap(entry -> validateTargetShape(entry.getKey(), entry.getValue(), model))
.collect(Collectors.toList());
}

private Stream<ValidationEvent> validateTargetShape(
String name,
MemberShape memberShape,
Model model,
List<Pattern> patterns
Model model
) {
return OptionalUtils.stream(model.getShape(memberShape.getTarget())
.flatMap(targetShape -> validateName(name, targetShape, memberShape, patterns, model)));
}

private List<ValidationEvent> validateSimpleShape(
Shape shape,
List<Pattern> patterns
Shape shape
) {
String name = shape.getId().getName();

Expand All @@ -201,9 +191,7 @@ private Optional<ValidationEvent> validateName(
Model model
) {
ShapeType type = targetShape.getType();
if (type == ShapeType.TIMESTAMP) {
return Optional.empty();
} else if (type == ShapeType.ENUM) {
if (type == ShapeType.TIMESTAMP || type == ShapeType.ENUM) {
return Optional.empty();
} else if (type == ShapeType.STRUCTURE || type == ShapeType.LIST) {
if (this.onlyContainsTimestamps(targetShape, model)) {
Expand Down

0 comments on commit e70266f

Please sign in to comment.