2
votes

i'm coding the following Json Schema:

{
  "$schema": "http://json-schema.org/schema#",
  "title": "Layout",
  "description": "The layout created by the user",
  "type": "object",
  "definitions": {
    "stdAttribute": {
      "type": "object",
      "properties": {
        "attributeValue": {
          "type": "object"
        },
        "attributeName": {
          "type": "string"
        }
      }
    },
    "stdItem": {
      "type": "object",
      "required" : ["stdAttributes"],
      "properties": {
        "stdType": {
          "enum": [
            "CONTAINER",
            "TEXT",
            "TEXTAREA",
            "BUTTON",
            "LABEL",
            "IMAGE",
            "MARCIMAGE",
            "DATA",
            "SELECT",
            "TABLE"
          ]
        },
        "stdAttributes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/stdAttribute"
          },
          "minItems": 1
        },
        "children": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/stdItem"
          }
        }
      }
    }
  }
}

When i set the following data:

{
    "stdItem": {
      "stdType": "CONTAINER",
      "stdAttributes": [],
      "children": []
  }
}

the validator says there is no error but in the schema i'm using a minItems and a ref to the "StdAttribute" schema in "StdAttributtes".

I tried to define this property in the base schema but the validator says the same thing.

How should i validate the type and number of items in "StdAttributes"?

I'm using the Java Validator.

1

1 Answers

3
votes

You are missing a properties attribute at the top level. Right now the only thing your schema is validating is that your data is an object. definitions doesn't validate anything by itself. It's just a place to hold schemas that can be referenced in your schema. The following would be the minimum you would have to add to the root of your schema to get the results you expect.

"properties": {
  "stdItem": { "$ref": "#/definitions/stdItem" }
}