JSON schema array without properties

697 views
Skip to first unread message

Christopher Graham

unread,
Apr 18, 2016, 1:33:54 PM4/18/16
to jsonschema - An implementation of JSON Schema for Python
I'm totally new to raml and JSON schema so I'm still cutting my teeth and learning.

See my related git issue which I likely should've posted here instead: https://github.com/Julian/jsonschema/issues/282

I have the following schema which has a "type":"array" but just a list of items with no properties.


schema = {
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "pushNotifDevices" : {
      "type": "array",
      "description" : "",
      "items": {
        "applicationId": {
          "type": "boolean",
          "example":"CTS",
          "description":"This application ID identifies."
        },
        "deviceType":{
          "type": "string",
          "enum":["ANDROID"],
          "description":"This enum indicates the type of device."
        },
        "deviceId": {
          "type":"string",
          "maxLength":1,
          "description":"Unqiue DeviceID."
        },
        "notifDeviceId": {
          "type":"string",
          "maxLength":1,
          "description":"This ID."
        },
        "active" : {
          "type":"boolean",
          "default":True,
          "description":"Boolean to determine if the device is active."
        },
        "failureDescription" : {
          "type":"string",
          "maxLength":1,
          "description":"This indicates the reason."
        }
      },
      "required": [
        "applicationId",
        "deviceType",
        "deviceId",
        "notifDeviceId"
      ]
    }
  }
}


This is apparently preventing me from simply using the schema as it exists to validate against as without properties no validation occurs on this array. Looking through my various schemas I see that objects are being defined with properties, but arrays are not.

So, this brings me to my questions:

Is this an issue with my schema? I'm not seeing any documentation in regards to arrays as to whether they should have properties defined. 
Or is this simply something I must manually modify in the schema to support being able to use validation? 

I was really hoping for my first pass at this to be able to use the schema as provided, and have the tool find type mismatches, enums that don't bind to the list, required fields that are missing, parameters that are totally missing, etc. All of the low hanging fruit.

Many thanks.

Christopher Graham

unread,
Apr 18, 2016, 1:40:51 PM4/18/16
to jsonschema - An implementation of JSON Schema for Python
I should clarify, the schema is being provided to me via RAML documentation for an API I'm attempting to test.

sop...@ordoro.com

unread,
Apr 21, 2016, 1:20:46 PM4/21/16
to jsonschema - An implementation of JSON Schema for Python
From the issue you posted on github, it looks like you're trying to validate an array (list) of objects (dict). The schema you provided is like a list of differently types items. If you want to specify that the items in the array are objects with the included properties, I think you'd want something more like this.

"type": "array",
     
"description" : "",
     
"items": {

         
"type": "object",
         
"properties": {
               
...<your properties here>
         
},
         
"required": [<required properties>]
       
}
...
}

Christopher Graham

unread,
Apr 21, 2016, 1:53:24 PM4/21/16
to jsonschema - An implementation of JSON Schema for Python
You're correct, and I thank you.

Have had my dev team update the RAML schema to specify as you've described. Heh, the JSON schema adventure has been just that. :)

Thanks for your help.
Reply all
Reply to author
Forward
0 new messages