private Optional<ValidationEvent> detectCycles(Model model, ResourceShape resource, Set<ShapeId> visited) {
        if (visited.contains(resource.getId())) {
            return Optional.of(cycle(resource, visited));
        }

        visited.add(resource.getId());
        for (ShapeId child : resource.getResources()) {
            ResourceShape childResource = model.getShape(child).flatMap(Shape::asResourceShape).orElse(null);
            if (childResource != null) {
                Optional<ValidationEvent> error = detectCycles(model, childResource, visited);
                if (error.isPresent()) {
                    return error;
                }
            }
        }

        return Optional.empty();
    }
Validates that resource references do not introduce circular hierarchies.
smithy-model/src/main/java/software/amazon/smithy/model/validation/validators/ResourceCycleValidator.java