Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate code for multiple swaggers in the same project

How do i generate code for multiple swagger files from within the same module/project in one pom.xml.

In my application client had provided a swagger and we have one of the backend API to be called for which they provided swagger. I want to generate code for both of these in the same project. One way i was thinking is create separate module and execute the plugin separately and have those dependencies called out in main module.

How do i generate code from one build plugin? Please point me to existing one if it is a repost. I couldn't find any.

Here is the plugin i configured in pom.xml

 <plugin>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-codegen-maven-plugin</artifactId>
            <version>2.2.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                      <inputSpec>${project.basedir}/src/main/ resources/Service.json</inputSpec><inputSpec>${project.basedir}/src /main/resources/Client.json</inputSpec>
                        <language>java</language>
                        <configOptions>
                            <dateLibrary>java8</dateLibrary>
                        </configOptions>
                        <modelPackage>com.service.model</modelPackage>
                        <environmentVariables>
                            <models/>
                            <supportingFiles>false</supportingFiles>
                        </environmentVariables>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Also tried *.json. At anytime it is taking only one json file and generating the code.

like image 982
rajanikanth Avatar asked Jan 17 '17 16:01

rajanikanth


People also ask

How does swagger generate code?

Generating CodeThe java command line tool allows us to pass a Java ARchive (JAR) file and execute it in the command line. In this way we can run the Swagger Codegen command line tool. Generate is the command passed to the Swagger Codegen CLI tool.


1 Answers

In order to do this you could declare a different execution for each json file, each one should have a unique id.

Here is an example with two executions, execution-first-json for the file first.json and execution-second-json for the file second.json

<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.2.1</version>
    <executions>
        <execution>
            <id>execution-first-json</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${project.basedir}/src/main/resources/first.json</inputSpec>
                <language>java</language>
                <configOptions>
                    <dateLibrary>java8</dateLibrary>
                </configOptions>
                <modelPackage>com.service.model</modelPackage>
                <environmentVariables>
                    <models/>
                    <supportingFiles>false</supportingFiles>
                </environmentVariables>
            </configuration>
        </execution>
        <execution>
            <id>execution-second-json</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
              <inputSpec>${project.basedir}/src/main/resources/second.json</inputSpec>
                <language>java</language>
                <configOptions>
                    <dateLibrary>java8</dateLibrary>
                </configOptions>
                <modelPackage>com.service.model</modelPackage>
                <environmentVariables>
                    <models/>
                    <supportingFiles>false</supportingFiles>
                </environmentVariables>
            </configuration>
        </execution>
    </executions>
</plugin>
like image 69
moondaisy Avatar answered Oct 15 '22 23:10

moondaisy