为同一个项目中的多个swaggers生成代码

raj*_*nth 8 json swagger swagger-codegen

我如何从一个 pom.xml 中的同一个模块/项目中为多个 swagger 文件生成代码。

在我的应用程序中,客户端提供了一个 swagger,我们有一个后端 API 被调用,他们提供了 swagger。我想在同一个项目中为这两个生成代码。我想的一种方法是创建单独的模块并单独执行插件,并在主模块中调用这些依赖项。

如何从一个构建插件生成代码?如果是转贴,请指出现有的。我找不到任何。

这是我在 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>
Run Code Online (Sandbox Code Playgroud)

也试过*.json。在任何时候它只需要一个 json 文件并生成代码。

moo*_*isy 8

为了做到这一点,你可以为每个 json 文件声明不同的执行,每个文件都应该有一个唯一的 id。

这是一个包含两次执行的示例,分别execution-first-json是文件first.jsonexecution-second-json文件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>
Run Code Online (Sandbox Code Playgroud)