swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.98k stars 6.03k forks source link

[swagger-codegen-maven-plugin] Unable to process multiple inputSpecs #9953

Open eamell opened 4 years ago

eamell commented 4 years ago
Description

Using version 3 of the Swagger Codegen Maven plugin I am unable to run multiple executions each using a different inputSpec. When I do this I get the following error:

[INFO] --- swagger-codegen-maven-plugin:3.0.13:generate (default) @ my-project ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  13.445 s
[INFO] Finished at: 2020-01-02T20:24:38-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.swagger.codegen.v3:swagger-codegen-maven-plugin:3.0.13:generate (default) on project my-project: The parameters 'inputSpec', 'language' for goal io.swagger.codegen.v3:swagger-codegen-maven-plugin:3.0.13:generate are missing or invalid -> [Help 1]

For both executions I have an ID specified and its own configuration as follows:

<plugin>
    <groupId>io.swagger.codegen.v3</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>content-push</id>

            <configuration>
                <inputSpec>${project.basedir}/src/main/swagger/contentPush/swagger.yaml</inputSpec>
                <language>java</language>
                <modelPackage>${content.push.default.client.package}.model</modelPackage>
                <apiPackage>${content.push.default.client.package}.api</apiPackage>
                <invokerPackage>${content.push.default.client.package}</invokerPackage>
                <modelNamePrefix>ContentPush</modelNamePrefix>
                <configOptions>
                    <dateLibrary>java8</dateLibrary>
                </configOptions>
            </configuration>
        </execution>
        <execution>
            <id>distribution</id>

            <configuration>
                <inputSpec>${project.basedir}../cpr/xxx-cpr-distribution/src/main/swagger/distribution/swagger.yaml</inputSpec>
                <language>java</language>
                <modelPackage>${distribution.client.package}.model</modelPackage>
                <apiPackage>${distribution.client.package}.api</apiPackage>
                <invokerPackage>${distribution.client.package}</invokerPackage>
                <modelNamePrefix>Dist</modelNamePrefix>
                <configOptions>
                    <dateLibrary>java8</dateLibrary>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>

If I run either one of them without the ID it works, however if I run just one with the ID specified I get the same error. This leads me to believe the issue is more with the ID being specified, however if I leave out the ID I get the following error:

[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'dependencies.dependency.version' for org.junit.jupiter:junit-jupiter:jar is either LATEST or RELEASE (both of them are being deprecated) @ xxx:my-project:[unknown-version], location\to\the\pom.xml, line 80, column 22
[ERROR] 'build.plugins.plugin[io.swagger.codegen.v3:swagger-codegen-maven-plugin].executions.execution.id' must be unique but found duplicate execution with id default @ xxx:my-project:[unknown-version], location\to\the\pom.xml, line 108, column 32
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project xxx:my-project:1.0.49-SNAPSHOT (location\to\the\pom.xml) has 1 error
[ERROR]     'build.plugins.plugin[io.swagger.codegen.v3:swagger-codegen-maven-plugin].executions.execution.id' must be unique but found duplicate execution with id default @ xxx:my-project:[unknown-version], location\to\the\pom.xml, line 108, column 32
Swagger-codegen version

3.0.13 and 3.0.14

Swagger declaration file content or url

N/A

Command line used for generation

N/A

Steps to reproduce

This assumes two valid OpenAPI YAML or JSON files.

  1. Create a Maven project that will be used to generate the source.
  2. Add the io.swagger.codegen.v3:swagger-codegen-maven-plugin plugin with one execution to validate everything works.
  3. Add the second execution and populate and ID for both executions.
Related issues/PRs
Suggest a fix/enhancement
Ivansamara109 commented 3 years ago

I met this problem, In my case the decision was to add tag into second execution. Like this:

<plugin>
    <groupId>io.swagger.codegen.v3</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <executions>
        <execution>
            <configuration>
                <inputSpec>${project.basedir}\src\main\resources\schema\cod.json</inputSpec>
                <language>spring</language>
                <library>spring-cloud</library>
                <output>${project.build.directory}\generated-sources\</output>
                <generateApiDocumentation>false</generateApiDocumentation>
                <generateModelDocumentation>false</generateModelDocumentation>
                <generateSupportingFiles>false</generateSupportingFiles>
                <generateApiTests>false</generateApiTests>
                <generateModelTests>false</generateModelTests>
                <generateSupportingFiles>false</generateSupportingFiles>
                <apiPackage>${base-package}.client.cod.api</apiPackage>
                <modelPackage>${base-package}.client.cod.model</modelPackage>
                <configOptions>
                    <interfaceOnly>true</interfaceOnly>
                    <dateLibrary>java8</dateLibrary>
                    <java8>true</java8>
                    <defaultInterfaces>false</defaultInterfaces>
                    <bigDecimalAsString>true</bigDecimalAsString>
                    <serializableModel>true</serializableModel>
                    <reactive>false</reactive>
                </configOptions>
            </configuration>
        </execution>
        <execution>
            <id>limits-client</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <inputSpec>${project.basedir}\src\main\resources\schema\Limits_v1.yaml</inputSpec>
                <language>spring</language>
                <library>spring-cloud</library>
                <output>${project.build.directory}\generated-sources\</output>
                <generateApiDocumentation>false</generateApiDocumentation>
                <generateModelDocumentation>false</generateModelDocumentation>
                <generateSupportingFiles>false</generateSupportingFiles>
                <generateApiTests>false</generateApiTests>
                <generateModelTests>false</generateModelTests>
                <generateSupportingFiles>false</generateSupportingFiles>
                <apiPackage>${base-package}.client.limits.api</apiPackage>
                <modelPackage>${base-package}.client.limits.model</modelPackage>
                <configOptions>
                    <interfaceOnly>true</interfaceOnly>
                    <dateLibrary>java8</dateLibrary>
                    <java8>true</java8>
                    <defaultInterfaces>false</defaultInterfaces>
                    <bigDecimalAsString>true</bigDecimalAsString>
                    <serializableModel>true</serializableModel>
                    <reactive>false</reactive>
                </configOptions>
            </configuration>
        </execution>
    </executions>
</plugin>