gpt4 book ai didi

json - 为同一项目中的多个 swagger 生成代码

转载 作者:行者123 更新时间:2023-12-02 01:42:27 25 4
gpt4 key购买 nike

如何在一个 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>

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

最佳答案

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

这是一个包含两次执行的示例,first.jsonexecution-first-jsonfirst.json 文件的 execution-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>

关于json - 为同一项目中的多个 swagger 生成代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41702500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com