Swagger-Codegen-Maven-Plugin V3问题
我们从Springfox 2.0迁移到OpenAPI 3.0。客户生成插件有两个挑战-API,
- 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));
现在使用
- 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 -
- 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
- Earlier with 2.0 version codegen plugin, the api client generated used to have the postfix in the api method name like
getByFileNameUsingPOST
and 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论