Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KSP with micronaut 4.2.2: @Client annotated class not introspected when use also @Generated annotation #10277

Closed
altro3 opened this issue Dec 16, 2023 · 7 comments · Fixed by #10282

Comments

@altro3
Copy link
Contributor

altro3 commented Dec 16, 2023

look to the screenshot:

изображение

At the top you see what kapt generated: 2 packages - io.micronaut.openapi.test.api and io.micronaut.openapi.test.model

Next you see generated sources yt micronaut openapi and introspected class by KSP. As you see, generated 2 packages, but introspected only one - io.micronaut.openapi.test.model.

That's because introspection lost all interfaces from package io.micronaut.openapi.test.api

With micronaut 4.2.1 all works fine

Sample interface which lost:

@Generated("io.micronaut.openapi.generator.KotlinMicronautClientCodegen")
@Client("\${openapi-micronaut-client-base-path}")
interface PetApi {

    @Post("/pet")
    fun addPet(
        @Body @Nullable @Valid body: Pet?
    ): Mono<Void>
}

Version

4.2.2

@altro3
Copy link
Contributor Author

altro3 commented Dec 16, 2023

@dstepanov hi! Look to this, pls. This is critical bug for micronaut with KSP

@dstepanov
Copy link
Contributor

No sure what would cause that, going to check next week

@altro3
Copy link
Contributor Author

altro3 commented Dec 17, 2023

@dstepanov Hi! You know, this is certainly a strange error, but I was able to figure it out.

So, the problem is NOT with the interfaces, but with... the @Generated annotation!!!

To reproduce it you need to create an interface, for example:

@Generated("io.micronaut.openapi.generator.KotlinMicronautClientCodegen")
@Client("openapi-micronaut-client-base-path")
interface PetApi {

    /**
     * {@summary Add a new pet to the store}
     *
     * @param body Pet object that needs to be added to the store (optional)
     * @return Mono&lt;Void&gt;
     */
    @Post("/pet")
    fun addPet(
        @Body @Nullable @Valid body: Pet?
    ): Mono<Void>
}

We run the build and see this:
изображение
As you can see, there is no class for PetApi in the generated folder, it’s as if the @client annotation was simply ignored

Next, remove the Generated annotation and run clean build again:
изображение
As you can see, we now see the generated classes PetApi$Intercepted, $PetApi$Intercepted$Definition and others.

@altro3
Copy link
Contributor Author

altro3 commented Dec 17, 2023

To reproduce this bug you just can add @Generated annotation to PetClient in test-suite-kotlin-ksp:
изображение

@altro3 altro3 changed the title KSP with micronaut 4.2.2: interface introspection doesn't work KSP with micronaut 4.2.2: @Client annotated class not introspected when use also @Generated annotation Dec 17, 2023
@dstepanov
Copy link
Contributor

Ah right, we have a check that was skipping processing classes with Generated annotations. And I have noticed that it was incorrect and fixed it, now we have this. I guess it needs to be removed

@dstepanov
Copy link
Contributor

What is the full name of that @Generated annotation?

@altro3
Copy link
Contributor Author

altro3 commented Dec 18, 2023

@dstepanov jakarta.annotation.Generated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants