public ResolvedType getTypeConsideringHierarchyMatching(ResolvedType targetType, Predicate<ResolvedType> check) {
        ResolvedType targetSuperType = targetType;
        while (targetSuperType != null) {
            if (check.test(targetSuperType)) {
                return targetSuperType;
            }
            Optional<ResolvedType> interfaceWithAnnotation = targetSuperType.getImplementedInterfaces().stream()
                    .filter(check)
                    .findFirst();
            if (interfaceWithAnnotation.isPresent()) {
                return interfaceWithAnnotation.get();
            }
            targetSuperType = targetSuperType.getParentClass();
        }
        return null;
    }
Find the (super) type, including interfaces, that fulfils the given condition/check..

@param targetType type to check for the annotation, potentially iterating over its declared interfaces and super types
@param check condition to be fulfilled
@return (super) type fulfilling the given condition (or {@code null} if the condition wasn't fulfilled by any of its interfaces or super types)

@since 4.30.0
jsonschema-generator/src/main/java/com/github/victools/jsonschema/generator/TypeContext.java