I have an API written in Swagger for which I want to generate both the Service implementation and also the client, and they have to be in separate maven modules.
I was thinking of separating them into 3 separate Maven modules (or submodules of the same parent pom).
parent
+- api
+- src/main/resources/api/service.yaml
+- client
+- service
Then in both client and service I would have the swagger-codegen-maven-plugin
. This way both will be in sync and I will only maintain the service from one place. Other clients can also depend on the api
artifact and generate their code from the service.yaml
Swagger API definition.
My difficulty is how do I make the service and client refer to the service.yaml
in another Maven dependency?
This is what I currently have in the service pom.xml
, but it refers to the local resources of the service module, not to the api
maven dependency.
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>${io.swagger.codegen.version}</version>
<executions>
<execution>
<id>api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- can this refer to another maven dependency's resources? -->
<inputSpec>${basedir}/src/main/resources/api/service.yaml</inputSpec>
<language>spring</language>
<library>spring-boot</library>
<modelPackage>com.test.model</modelPackage>
<apiPackage>com.test.api</apiPackage>
<generateSupportingFiles>false</generateSupportingFiles>
<configOptions>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Not sure if this is something I have to do from Maven, to refer to resources from another maven dependency, or something I have to do in the swagger plugin configuration.