java - OpenAPI3:如何在查询中传递 json 对象数组
问题描述
我应该在休息操作中通过学生名单。学生列表定义如下:
- name: student-list
in: query
description: Id of the Student of the target NF
content:
application/json:
schema:
type: array
items:
$ref: 'TS29571_CommonData.yaml#/components/schemas/StudentId'
minItems: 1
其中每个项目定义如下:
StudentId:
type: object
properties:
class:
type: string
rollno:
type: integer
根据上述表示,我应该传递 StudentId json 数组(带有 style = form 和 explode = true )。
根据 OpenAPI Generator 生成的代码,需要 Student 列表的操作会遍历列表中的每个 StudentId。对于每个 StudentId,它调用 toString 方法生成 json 表示 StudentId 对象
StudentId 对象有以下 toString 方法:
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class StudentId {\n");
sb.append(" class: ").append(toIndentedString(mcc)).append("\n");
sb.append(" rollno: ").append(toIndentedString(mnc)).append("\n");
sb.append("}");
return sb.toString();
}
并且 toIndentedString 方法定义如下:
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
我的问题是:为什么 OpenAPI 没有生成正确的代码。toString 方法没有生成有效的 json (因为 jSON 以“class StudentId”开头并且它与“\n”杂乱无章}。
这个问题与现有问题不重复在这里,我问的是发送带有样式 = 的 json 对象数组form and explode = false. 现有问题没有为我的问题提供解决方案。
解决方案
推荐阅读
- python - 解析python字典中相同键的值
- python - 从字典键、子键和值的列表构造字典
- java - Spring Data Mongo:处理字段名称中的“$”字符
- python - 附加上一个单词 Python
- python - 从 Spyder 但不是从 Anaconda 加载 DLL 时出错
- python - 我正在尝试从文件(tasks.txt)中打印所有登录用户的任务。这是我到目前为止所拥有的,但它只打印出一项任务
- c# - 在gridview中隐藏一些图像
- python - 分配给数组更改 dtype
- ktor - 如何以编程方式启动 ktor-server 以进行集成测试
- css - Edge浏览器中的滚动条css问题