1

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>
Vishal_Kotecha
  • 481
  • 5
  • 19

0 Answers0