Swagger-Codegen-Maven-Plugin V3问题

发布于 2025-02-04 01:22:46 字数 2278 浏览 4 评论 0原文

我们从Springfox 2.0迁移到OpenAPI 3.0。客户生成插件有两个挑战-API,

  1. API符合FormData,consect =“应用程序/x-www-form-urlenceded”正在转换为queryparams。以下是V2版本生成的代码,
String path = UriComponentsBuilder.fromPath("/api/myApi/getByFileName").build().toUriString();
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap();
HttpHeaders headerParams = new HttpHeaders();
MultiValueMap<String, Object> formParams = new LinkedMultiValueMap();
if (fileName != null) {
 formParams.add("fileName", fileName);
}

-Codegen-Maven-Plugin v3

String path = UriComponentsBuilder.fromPath("/api/myApi/getByFileName").build().toUriString();
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap();
HttpHeaders headerParams = new HttpHeaders();
MultiValueMap<String, Object> formParams = new LinkedMultiValueMap();
queryParams.putAll(this.apiClient.parameterToMultiValueMap((CollectionFormat)null, "fileName", fileName));

现在使用

  1. Swagger 生成使用2.0版本CodeGen插件,API客户端使用的API客户端在API方法名称中具有后缀,例如getByFileNamesingPost and v3,其生成API方法名称而没有此类post fix:getbybyfilename

这是V2的Maven插件,

<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
            ....
           </configuration>
        </execution>
    </executions>
</plugin>

这是V3的Maven插件

<plugin>
    <groupId>io.swagger.codegen.v3</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>3.0.20</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
            ....
           </configuration>
        </execution>
    </executions>
</plugin>

We are migrating from springfox 2.0 to openAPI 3.0. The client generation plugin has two challenges -

  1. The APIs which are acceping formdata, having consumes = "application/x-www-form-urlencoded" are getting converted into queryParams. Following is the code generated by the plugin of v2 version
String path = UriComponentsBuilder.fromPath("/api/myApi/getByFileName").build().toUriString();
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap();
HttpHeaders headerParams = new HttpHeaders();
MultiValueMap<String, Object> formParams = new LinkedMultiValueMap();
if (fileName != null) {
 formParams.add("fileName", fileName);
}

now with swagger-codegen-maven-plugin v3

String path = UriComponentsBuilder.fromPath("/api/myApi/getByFileName").build().toUriString();
MultiValueMap<String, String> queryParams = new LinkedMultiValueMap();
HttpHeaders headerParams = new HttpHeaders();
MultiValueMap<String, Object> formParams = new LinkedMultiValueMap();
queryParams.putAll(this.apiClient.parameterToMultiValueMap((CollectionFormat)null, "fileName", fileName));

So, when using the the API client generated with v3,no longer supports formdata and throws Response 415 UNSUPPORTED_MEDIA_TYPE

  1. Earlier with 2.0 version codegen plugin, the api client generated used to have the postfix in the api method name like getByFileNameUsingPOSTand with v3, its generating the api method name without such post fix: getByFileName

Here's the maven plugin of v2

<plugin>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>2.3.1</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
            ....
           </configuration>
        </execution>
    </executions>
</plugin>

Here's the maven plugin of v3

<plugin>
    <groupId>io.swagger.codegen.v3</groupId>
    <artifactId>swagger-codegen-maven-plugin</artifactId>
    <version>3.0.20</version>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
            ....
           </configuration>
        </execution>
    </executions>
</plugin>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文