3

So I have this json schema:-

{
    "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"
    ]
}

Here I want to have attributes field to have value "fk", "uid" fixed and must allow other field values with "fk" and "uid". with this following code I am getting error while passing additonal values:- { "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 how do I fix it?

1 Answer 1

2

The value of contains in your schema must be a schema:

keyword contains error message

According to your question, maybe change the "attributes" schema to:

"attributes": {
  "type": "array",
  "minItems": 2,
  "items": [ { "const": "fk" }, { "const": "uid" } ],
  "additionalItems": {
    "type": "string"
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.