我正在尝试使用 Swagger Codegen 为我的 Spring Boot 项目生成模型类。我在网上找到了一些参考资料,并在我的 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>
我运行mvn install并在目录中生成类/target/generated-sources/openapi。但我无法在我的 REST 控制器类中导入这些生成的类。
我的理解是该<modelPackage>字段用于标识必须放置生成的类的包。我是对的吗?
即使这些生成的类在正确的包中,由于它们不在src/main/java,我可能无法将它们导入到其他类中。
有没有办法在src/main/java目录下获取这些生成的类,或者我是否在 maven 配置中遗漏了一些东西,因为这些文件对其他类不可用?