Search code examples
spring-bootswagger-2.0openapi-generator

open api 3 default Array generation


My API definition is as follows:

/api:
  get:
  ...
  parameters:
     - name: "tags"
       in: "query"
       description: "some description"
       required: false
       schema:
         type: "array"
         items:
           type: "string"
  ....

We are using openapi-generator-maven-plugin:3.3.5 for code generation.

The API param that is generated: @ApiParam(value = "description", defaultValue = "new ArrayList<>()")

The actual param that the Controller receives is not empty and contains the literal new ArrayList<>() as the first element:

String first = tags.get(0);
assert "new ArrayList<>()".equals(first) //true

I couldn't find any param value that controls this behaviour (like defaultValue). How can I make the param to be null or at least, an empty list?

using sagger in a Spring boot app:

 <dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger2</artifactId>
  <version>${io.springfox.swagger.version}</version>
</dependency>

openapitools generator config options

  <configOptions>
      <dateLibrary>java8</dateLibrary>
      <serializationLibrary>jackson</serializationLibrary>
      <interfaceOnly>true</interfaceOnly>
      <delegatePattern>true</delegatePattern>
      <useTags>true</useTags>
  </configOptions>

Solution

  • Newer generator version already fixes this issue:

    <plugin>
        <groupId>org.openapitools</groupId>
        <artifactId>openapi-generator-maven-plugin</artifactId>
        <version>4.3.0</version>
        ...
    </plugin>
    

    Also, add Jackson databind-nullable

     <dependency>
      <groupId>org.openapitools</groupId>
      <artifactId>jackson-databind-nullable</artifactId>
      <version>0.2.1</version>
    </dependency>