我的API定义如下:
/api:
get:
...
parameters:
- name: "tags"
in: "query"
description: "some description"
required: false
schema:
type: "array"
items:
type: "string"
....
我们正在使用 openapi-generator-maven-plugin:3.3.5
用于代码生成。
生成的 API 参数:@ApiParam(value = "description", defaultValue = "new ArrayList<>()")
Controller 收到的实际参数不为空,包含文字 new ArrayList<>()
作为第一个元素:
String first = tags.get(0);
assert "new ArrayList<>()".equals(first) //true
我找不到任何控制此行为的参数值(如 defaultValue)。 如何使参数为空或至少为空列表?
在 Spring boot 应用中使用 sagger:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${io.springfox.swagger.version}</version>
</dependency>
openapitools 生成器配置选项
<configOptions>
<dateLibrary>java8</dateLibrary>
<serializationLibrary>jackson</serializationLibrary>
<interfaceOnly>true</interfaceOnly>
<delegatePattern>true</delegatePattern>
<useTags>true</useTags>
</configOptions>
最佳答案
这里有同样的问题,但无法让它工作。 但是您可以添加一些验证来查看列表是否包含至少一个元素,例如
/api:
get:
...
parameters:
- name: "tags"
in: "query"
description: "some description"
required: false
schema:
type: "array"
minItems: 1
items:
type: "string"
....
关于spring-boot - 打开 api 3 默认数组生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61634809/