3

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>

2 Answers 2

1

Have the same problem here, but could not get it to work. But you can maybe add some validation to see if list contains at least one element, e.g.

/api:
  get:
  ...
  parameters:
   - name: "tags"
     in: "query"
     description: "some description"
     required: false
     schema:
       type: "array"
       minItems: 1
       items:
         type: "string"
  ....
Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.