在我的模式定义中,我有一个类型,它有一个整型属性,它应该是一组“固定”数字中的任何一个。问题是,这个“固定集合”可能会经常改变。
"person": {
"type": "object",
"properties": {
"aproperty": {
"type": "integer",
"enum": [1, 12, 30 ... , 1000]
},
}
},有没有办法从远程服务引用这个数组(它将拥有最新的集合)?
"person": {
"type": "object",
"properties": {
"aproperty": {
"type": "integer",
"$ref": "http://localhost:8080/fixed_set"
},
}
},我试过$ref,但没成功。如果"ref“是解决方案的一部分,那么de backend应该返回什么?
{
"enum": [1, 12, 30 ... , 1000]
}或
"enum": [1, 12, 30 ... , 1000]或
[1, 12, 30 ... , 1000]发布于 2020-08-05 03:57:59
主模式:
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"properties": {
"aproperty": {
"type": "integer",
"$ref": "http://localhost:8080/fixed_set"
},
}
}子模式:
{
"$id": "http://localhost:8080/fixed_set",
"enum": [1, 12, 30 ... , 1000]
}请注意,您必须使用支持draft2019 2019-09的求值器,才能将$ref识别为同级关键字。否则,您需要将其包装在allOf中:
{
"type": "object",
"properties": {
"aproperty": {
"type": "integer",
"allOf": [
{ "$ref": "http://localhost:8080/fixed_set" }
]
},
}
}https://stackoverflow.com/questions/63252555
复制相似问题