Search code examples
javadependency-injectionresteasyopenapi-generator

java dependency inject ambiguous overwrite


I'm using openapi generator to generate java-resteasy server stub code template, my idea is that use the generator generate some interface that I will never modify, and I will implement that interface with my own code.

However, the generator already generated implementation class, I write my own implementation class which extends the generated one. So now there're two implementation classes, so CDI complains about the ambiguouty:

javax.enterprise.inject.AmbiguousResolutionException: Ambiguous dependencies for type openapidemo.gen.FruitsApiService and qualifiers [@Default]

is there any way to mark my own implementation class as first priority when CDI try to discover bean? so as to overwrite the one generated by openapi.

edit:

Per @Negi answer, @Alternative might be a way to indicate a class as low priority when CDI searching bean, however, in my case, I want to hide the generated code without modifying it since I will check it in my repo, and I expect the code generation is idempotent. So is there any way to annotate a class as "prioritize" with my own implementation class, as opposite to @Alternative?


Solution

  • You can create a file named .openapi-generator-ignore and mention the files you would like not to generate.

    https://openapi-generator.tech/docs/faq-extending/#how-do-i-skip-files-during-code-generation