I am trying to use Swagger Codegen to generate model classes for my spring boot project. I found some references online and included the following plugin in my pom.xml:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>
${project.basedir}/src/main/resources/Contract-v1.yml
</inputSpec>
<generatorName>spring</generatorName>
<apiPackage>${project.groupId}.swagger.api</apiPackage>
<modelPackage>${project.groupId}.swagger.model</modelPackage>
<supportingFilesToGenerate>
ApiUtil.java
</supportingFilesToGenerate>
<configOptions>
<sourceFolder>src/main/java/</sourceFolder>
<delegatePattern>true</delegatePattern>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
I run mvn install
and the classes are generated in the directory /target/generated-sources/openapi
. But I am unable to import these generated classes in my REST controller class.
My understanding is that the <modelPackage>
field is used to identify the package in which the generated classes have to be placed. Am I right about this?
Even though these generated classes are in the right package, since they are not in the src/main/java
, i am probably not able to import them in other classes.
Is there way to get these generated classes under the src/main/java
directory or am I missing something in the maven config due to which these files are unavailable to other classes ?