Skip to content
Discussion options

You must be logged in to vote

Ah, sorry; your requirements weren't clear to me initially. And I'm still not entirely sure. 😅
It looks like you have to recurse on a field hierarchy, which is tricky if generic types are involved.

But if all @Sharded classes inherit from Parent<ID>, which handles the _id field, and if there are no further generics, something like this might already be good enough:

@ArchTest
ArchRule shardedClassesHaveAvailableShardKeys =
    classes()
        .that().areAnnotatedWith(Sharded.class)
        .should(have(describe("available shardKeys", shardedClass ->
            stream(shardedClass.getAnnotationOfType(Sharded.class).shardKey())
                .allMatch(shardKey -> fieldExists(shardKey, s…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Vignesh413
Comment options

@hankem
Comment options

Answer selected by Vignesh413
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants