Search code examples
javamavenswagger-codegen

generate code via several yaml file using swagger codegen plugin


I have several swagger yaml files and I want to generate code at compile time using maven.

here is my code:

 <plugins>
        <plugin>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>2.3.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <inputSpec>${project.basedir}/src/main/resources/*.yaml</inputSpec>
                        <language>java</language>
                        <configOptions>
                            <sourceFolder>src/gen/java/main</sourceFolder>
                        </configOptions>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

I'm trying to get all the yaml files I have in the resources as input :

<inputSpec>${project.basedir}/src/main/resources/*.yaml</inputSpec>

but this do not work, I've got this error:

failed to read resource listing
java.io.FileNotFoundException: C:\Projets\www\codegen\src\main\resources\*.yaml (La syntaxe du nom de fichier, de répertoire ou de volume est incorrecte)

Any Idea ?


Solution

  • My problem was resolved by using multiple executions as follow :

             <plugin>
                <groupId>io.swagger</groupId>
                <artifactId>swagger-codegen-maven-plugin</artifactId>
                <version>2.4.5</version>
                <executions>
                    <execution>
                        <id>a</id> .....
                    </execution>
                    <execution>
                        <id>b</id> .....
                    </execution>
                    <execution>
                        <id>c</id> .....
                    </execution>
                 </executions>
              </plugin>