如何为包含一些固定值并可能具有其他附加值的数组字符串创建数组 json 模式

所以我有这个 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 如何修复它?


慕容森
浏览 124回答 1
1回答

噜噜哒

架构中的值contains必须是架构:根据您的问题,也许将“属性”架构更改为:"attributes": {  "type": "array",  "minItems": 2,  "items": [ { "const": "fk" }, { "const": "uid" } ],  "additionalItems": {    "type": "string"  }}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go