亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何為包含一些固定值并可能具有其他附加值的數組字符串創建數組 json 模式

如何為包含一些固定值并可能具有其他附加值的數組字符串創建數組 json 模式

Go
慕容森 2022-12-19 21:48:04
所以我有這個 json 模式:-{    "type": "object",    "properties": {        "campaignType": {            "type": "string",            "enum": [                "export"            ]        },        "clientid": {            "type": "integer",            "minimum": 1        },        "select": {            "type": "object",            "minProperties": 1,            "anyOf": [                {                    "required": [                        "list"                    ]                },                {                    "required": [                        "segment"                    ]                }            ],            "properties": {                "list": {                    "type": "array",                    "items": {                        "type": "integer"                    }                },                "segment": {                    "type": "array",                    "items": {                        "type": "integer"                    }                }            }        },        "attributes": {            "type": "array",            "minItems": 2,            "items": {                 "type": "string",                "contains": ["fk", "uid"]            }        }    },    "required": [        "campaignType",        "clientid",        "select",        "attributes"    ]}在這里,我想讓屬性字段的值“fk”、“uid”固定,并且必須允許其他字段值帶有“fk”和“uid”。使用以下代碼,我在傳遞附加值時遇到錯誤:- { "campaignType":"export", "clientid":107311, "select":{ "segment":[30] }, "attributes":["uid ","fk", "att1"] }error unmarshaling properties from json: error unmarshaling items from json: json: cannot unmarshal object into Go value of type []*jsonschema.Schema 如何修復它?
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻1784條經驗 獲得超7個贊

架構中的值contains必須是架構:

http://img1.sycdn.imooc.com//63a06bb300019b2207500273.jpg

根據您的問題,也許將“屬性”架構更改為:


"attributes": {

  "type": "array",

  "minItems": 2,

  "items": [ { "const": "fk" }, { "const": "uid" } ],

  "additionalItems": {

    "type": "string"

  }

}


查看完整回答
反對 回復 2022-12-19
  • 1 回答
  • 0 關注
  • 103 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號