简体   繁体   中英

How do I fix OpenAPI error in seemingly correct 'inputSpec' for code generation?

I'm trying to run the OpenAPI generator, but I keep getting an error message that doesn't make sense.

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

The trouble is that my inputSpec value points to a valid.yaml file. The file is at src/main/resources/yaml/pizzeria.yaml and I've used copy and paste to ensure there are no spelling errors in that path. You can download a minimum reproducible test case at https://github.com/SwingGuy1024/OpenAPI_inputSpec_Bug .

Here's my plugin spec:

        <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> &lt;!&ndash; Added &ndash;&gt;-->
                        <!--<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>

Use the compile phase of maven

mvn clean compile

instead of using the plugin directly

mvn openapi-generator:generate

Explanation:

The trick is, not to call the plugin directly, but instead call "mvn clean compile". It´sa little but confusing about maven, but okay for me. Sorry guys.

from here: OpenAPI Generator | Issue tracker

  • You must rename the rules for OpenApi.

For example:

api.yaml
  • than, you must pass the file into /resources/

  • So, Your file will be into

/src/main/resources/api.yaml

  • After, you must change pom.xml into:
...
 <inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
...

  • Now, perform a command:
mvn clean compile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM