We're using the openapi-generator-maven-plugin
to generate the interface layer and DTOs for our Spring Boot application.
Additionally we use Spring Modulith and domain driven application modules to structure our application.
src/main/java/my.app/
...target/generated-sources/my/app/restinterfaces/..
(Example package structure below)
We have the generated API-interfaces and models in a package restinterfaces
and we want to allow access to this package from our domainA
and domainB
packages.
Normally, we would do this via @org.springframework.modulith.NamedInterface
in the package-info.java
- files. How would we solve this in our case where a package only exists in a generated package-structure.
From an architectural perspective, the ideal way to tweak this is to make sure that OpenAPI generates the API and DTO classes into the modules they belong, as a web API logically belongs to the module.
A (rather ugly) workaround would be to declare a package-info.java
in my.app.restinterfaces
within src/main/java
and annotate that with @ApplicationModule(type = Type.OPEN)
. This would cause any code inside that package to be accessibly to other application modules.
That said, this kind of violates the idea that a module is self-contained, i.e., any kind of technology adapters would reside within modules, and not outside of it in a global bucket.