@Override
    public List<ValidationEvent> validate(Model model) {
        NeighborProvider neighborProvider = NeighborProviderIndex.of(model).getReverseProvider();

        Shape unit = model.getShape(UnitTypeTrait.UNIT).orElse(null);
        if (unit == null) {
            return Collections.emptyList();
        }

        List<ValidationEvent> events = new ArrayList<>();
        for (Relationship relationship : neighborProvider.getNeighbors(unit)) {
            switch (relationship.getRelationshipType()) {
                case INPUT:
                case OUTPUT:
                    break;
                case MEMBER_TARGET:
                    relationship.getShape()
                            .asMemberShape()
                            .map(MemberShape::getContainer)
                            .flatMap(model::getShape)
                            .filter(shape -> !(shape.getType() == ShapeType.UNION
                                    || shape.getType() == ShapeType.ENUM
                                    || shape.getType() == ShapeType.INT_ENUM))
                            .ifPresent(container -> {
                                events.add(error(
                                        relationship.getShape(),
                                        "Only members of a union, enum, or intEnum can reference smithy.api#Unit"));
                            });
                    break;
                default:
                    events.add(error(relationship.getShape(),
                            String.format(
                                    "This shape has an invalid %s reference to smithy.api#Unit",
                                    relationship.getRelationshipType())));
            }
        }

        return events;
    }
Ensures that a unit type can only be referenced as operation
input/output or by a tagged union member.
smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/UnitTypeValidator.java