Open nbrugger-tgm opened 2 years ago
I found a workaround to get the expected result.
Split your project into 2 parts api
and service
or app
where api
is a micronaut lib that contains all the annotation processed code. And app is ... well, the app and contains the implementation of the api. This is the only reliable way to force annotation processor order, still it would be favorable to work out of the box
Hi, don't want to be inpatient, and i do not ask for this to be fixed, but it would be very kind to get an answer if this is a bug or working as intended.
Can you please create an example project
Sure, sorry for not doing this earlier
here you go: https://github.com/nbrugger-tgm/micronaut-reproductions/ Folder : 6918 (ticket number)
There is a testscript to be executed as soon as the api is started using ./gradlew run
called test.sh
This is the most minimal that i managed to produce
Expected Behavior
When you have an annotation processor that generates files like this:
and then manually add the implementation
The path
/ping
should be:/paths
(if management is added ofc)Actual Behaviour
The path
/ping
path is:/paths
(if management is added ofc)When changing the processor to generate this instead : (Adding the
@Controller
annotation to the interface)the Open API generation works.
In Depth
PingService
interface is in the main src dirsrc/main/java
PingResource$Definition$Exec
file is missing after compilation which is present when the file is "hand written".PingResource$Definition$Exec
re-appears if i add a new method to the class that is annotated with an HTTP annotation. The old methodping()
is still not present within the$Exec
classping()
method in the implementation class with@Get("/ping")
makes the path available via/path
andcurl
but does not include it into the OAS (except the controller annotation is placed on the interface itself)This is what i think is causing the bug :
src/main/java
PingResource
and cant find any anotated method since the interface does not exist yetPingService
$Exec
files for classes (reasonable, also it wouldnt even help).yml
if there is a@Controller
annotationAgain this is just an educated guess but since i did a little tiny bit of debugging i think it might still be valueable to you :)
Steps To Reproduce
management
andopenapi
(gradle)processor_of_death
annotationProcessor(project(":processor_of_death"))
and also for theimplementation
configprocessor_of_death
project (imports omitted)@SupportedAnnotationTypes("io.micronaut.http.annotation.Controller") public class DtoInterfaceGenerator extends AbstractProcessor { @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { try (var writer = processingEnv.getFiler().createSourceFile("com.example.controller.PingService").openWriter()) { writer.append("package com.niton.localadmin.rest.controller;\n" + "\n" + "import io.micronaut.http.annotation.*;\n" + "\n" + "@Controller\n" + "public interface PingService {\n" + "\t@Get(\"/ping\")\n" + "\tString ping();\n" + "}\n"); } catch (IOException e) { e.printStackTrace(); } return false;//false to make the interface processable by others } }
curl -X GET http://localhost:8080/ping
will fail with 404 path not found ....curl -X GET http://localhost:8080/ping
will now workEnvironment Information
Example Application
github.com/nbrugger-tgm
Version
3.3.1