Correctly setting up schema within RAML v0.8


#1

Can anyone suggest how to best go about setting up my schema correctly to take into account ‘explaining’ properties that are not as simple as a string|integer etc…

P.S Forgive me if this doesn’t make sense i’m still learning RAML.

For instance in the snippet below the ‘nodes’ is currently set as a ‘string’ that is ‘required’ but this is actually a object as illustrated in the example at the bottom of this post.

Can anyone give me any idea if this is possible or if I’m utilising this in the wrong way?

// part of schema

{
  "type": "object",
  "$schema": "http://json-schema.org/draft-03/schema",
  "id": "http://jsonschema.net",
  "required": true,
  "properties": {
    "iID": {
    "type": "integer",
    "description": "ID of the zone (Read only)"
     }
   },
    "nodes": {
    "type": "string",
    "required": true
   }
}

The issue I have is how do I add the nodes to be structured in the following format as it isn’t a string but an object that is required (see below):

nodes : [{ 
  "health" : 2,
  "address" : "0xf26f7q3e:001"
}]

#2

Maybe you are trying to do this? There is a definition of a ‘zone’ with two properties “iID” and “nodes”. The “nodes” field is an array containing node objects. To do the latter you have to refer to another schema using the “$ref” field and the id of the other schema (“http://mydomain.net/schemas/node.json”).

The schema for the zone is then:

{
  "$schema": "http://json-schema.org/draft-03/schema",
  "id": "http://mydomain.net/schemas/zone.json",
  "type": "object",
  "properties": {
    "iID": {
      "type": "integer",
      "description": "ID of the zone (Read only)"
    },
    "nodes": {
      "type": "array",
      "required": true,
      "items": {
        "$ref": "http://mydomain.net/schemas/node.json"
      }
    }
  }
}

and the definition of a node:

{
  "$schema": "http://json-schema.org/draft-03/schema",
  "id": "http://mydomain.net/schemas/node.json",
  "type": "object",
  "properties": {
    "health": {
      "type": "integer"
    },
    "address": {
      "type": "string",
      "required": true
    }
  }
}

I hope this helps.


#3

Sorry I should have posted my findings - you are correct that is exactly what I was trying to achieve, if it helps anyone this is the link I found the info from

http://json-schema.org/example1.html