openapi - 在 CUE 中定义数组并导出到 OpenAPI
问题描述
对于以下简单的 CUE 代码,它定义了一个match
包含两个团队名称(作为两个字符串的数组)和比赛得分(作为两个整数的数组)的对象:
#match: {
id: int
teams: 2 * [string]
score: 2 * [int]
}
当我运行cue export --out openapi test.cue
(使用 CUE v0.4.0)时,我收到错误消息:
components.schemas.match.properties.score.default.0: incomplete value int
components.schemas.match.properties.score.default.1: incomplete value int
components.schemas.match.properties.teams.default.0: incomplete value string
components.schemas.match.properties.teams.default.1: incomplete value string
如果我更改string
为string | *null
,它可以工作 - 但是我真的不明白为什么数组的元素需要具有默认值才能导出为 OpenAPI(特别是因为对对象属性没有这样的要求)?我在这里错过了什么吗?
解决方案
通常,这看起来与 OpenAPI 不一致且值不完整。解决方法是指定默认元素。
import "list"
#s: string | *null
#match: {
id: int
teams: [#s, #s]
score: list.Repeat([int | *null], 2)
}
请注意,我编写的方式team
和score
此处导致的架构略有不同但等效。
另一方面,数学运算符已被弃用。您应该使用list.Repeat代替该部分。如果需要,您还可以列出元素。
有关更多详细信息,请参阅https://github.com/cue-lang/cue/discussions/1115
推荐阅读
- sumo - 如何在当前的 SUMO 场景中添加额外的路线?
- php - 如何在 wordpress 中定义是否选中帖子的自定义复选框并基于该显示预定义的单词(例如:视频)?
- database - 如何使用 []struct{} 使用 gorm 将数据插入到 postgres 中?
- reporting-services - 如果低于某个值,如何将条形图标签更改为不可见
- python - 以编程方式读取在控制台窗口中选择的当前文本
- wordpress - WordPress自定义目录帖子标题未显示
- javascript - 我如何不触发 Angular 11 中的 onChange 回调反应形式
- reactjs - 从对象数组中获取键值对并放入新数组
- python-3.x - 我的抓取输出有问题,我有 \r 和 \t
- javascript - 一个接一个地合并两个数组Javascript [等长]