![](/img/trans.png)
[英]OpenAPI Custom Generator - How do I prevent "AllOf" Class Generation in OpenApi
[英]How do I fix OpenAPI error in seemingly correct 'inputSpec' for code generation?
我正在尝试运行 OpenAPI 生成器,但我不断收到一条没有意义的错误消息。
Failed to execute goal org.openapitools:openapi-generator-maven-plugin:5.0.0-SNAPSHOT:generate (default-cli) on project miguelmunoz.challenge: The parameters 'inputSpec' for goal org.openapitools:openapi-generator-maven-plugin:5.0.0-SNAPSHOT:generate are missing or invalid
问题是我的inputSpec
值指向一个有效的.yaml 文件。 该文件位于src/main/resources/yaml/pizzeria.yaml
并且我使用复制和粘贴来确保该路径中没有拼写错误。 您可以在https://github.com/SwingGuy1024/OpenAPI_inputSpec_Bug下载最小可重现测试用例。
这是我的插件规范:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<!-- RELEASE_VERSION -->
<version>5.0.0-SNAPSHOT</version>
<!-- /RELEASE_VERSION -->
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!-- General Configuration properties taken from -->
<!-- https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator-maven-plugin/README.md -->
<!--Changed to https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin-->
<!-- Modifications from https://stackoverflow.com/questions/64304049/how-to-create-a-spring-boot-rest-server-using-openapitools/64363872#64363872 -->
<ignoreFileOverride>${project.basedir}/my-springboot.ignores</ignoreFileOverride> <!--Added-->
<inputSpec>${project.basedir}/src/main/resources/yaml/pizzeria.yaml</inputSpec>
<!--the language tag was replaced by the generatorName tag:-->
<generatorName>spring</generatorName>
<!--<templateDirectory>${project.basedir}/src/gen/templates/</templateDirectory>-->
<!--<templateResourcePath>${project.basedir}/src/gen/templates/</templateResourcePath>-->
<!-- <output>${project.basedir}</output>-->
<!-- Defaults to ${project.build.directory}/generated-sources/openapi -->
<apiPackage>com.dummy.pizzeria.api</apiPackage>
<modelPackage>com.dummy.pizzeria.model</modelPackage>
<invokerPackage>com.dummy.pizzeria</invokerPackage>
<packageName>com.dummy.pizzeria.objects</packageName>
<groupId>neptunedreams</groupId>
<artifactId>pizzeria</artifactId>
<library>spring-boot</library>
<generateModelTests>false</generateModelTests>
<!--<output>${project.basedir}/my-springboot</output> <!– Added –>-->
<!--<generateSupportingFiles>false</generateSupportingFiles>-->
<configOptions>
<!-- configOptions are specific to the spring generator. These are taken from -->
<!-- https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/spring.md -->
<sourceFolder>gen</sourceFolder>
<bigDecimalAsString>true</bigDecimalAsString>
<dateLibrary>java8</dateLibrary> <!-- Default-->
<delegatePattern>false</delegatePattern>
<performBeanValidation>true</performBeanValidation>
<useBeanValidation>true</useBeanValidation>
<skipDefaultInterface>false</skipDefaultInterface>
<library>spring-boot</library>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
使用 maven 的编译阶段
mvn clean compile
而不是直接使用插件
mvn openapi-generator:generate
解释:
诀窍是,不要直接调用插件,而是调用“mvn clean compile”。 maven 有点令人困惑,但对我来说还可以。 对不起大家。
从这里: OpenAPI 生成器 | 问题跟踪器
例如:
api.yaml
比,您必须将文件传递到/resources/
所以,你的文件将进入
/src/main/resources/api.yaml
...
<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
...
mvn clean compile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.