poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

JSON Schema


From: Konstantinos Chasialis
Subject: JSON Schema
Date: Wed, 27 May 2020 16:17:57 +0300
User-agent: SquirrelMail/1.4.23 [email.uoa.gr]

Hello poke team!
I am very glad to be back after some days missing due to obligations with
my university. I want to mention that now my time is fully devoted to our
project!

This is the current version of our JSON Schema.


First, there are some things I would like to point out.

We had a little problem with the "type" thingie and I decided to
make a change to fix it.

The previous schema had a bad-looking behavior when we added the "type"
property.

For example, to define an UnsignedInteger we had to do something like :

{
  "UnsignedInteger" : {"type" : "UnsignedInteger" , "value" : 15, "size" : 3}

}

which I didn't like.

What I prefer is something like this :

{
 "PokeObject" : {"type" : "UnsignedInteger" , "value" : 15, "size" : 3},
 "PokeObject" : {"type" : "String" , "value" : "jemarch"},
}

so now we just define one PokeObject and fill the right properties.
Please tell me what you think of this :).

I also applied some important restrictions on our schema.
For example, before applying these restrictions, we could have
redefinition of properties.

For example, the following :
{
 "PokeObject" : {"type" : "UnsignedInteger" , "value" : 15, "size" : 3,
"size" : 15 },
}
passed the validator despite having "size" twice.
and some other pretty weird stuff.


--------SCHEMA--------
{
  "$schema": "http://json-schema.org/draft-07/schema#";,
  "$id": "",
  "title": "Poke values",
  "description": "JSON Representation for Poke values",
  "definitions": {
    "UnsignedInteger": {
      "type": "object",
      "properties": {
        "type" : {
          "type" : "string",
          "const" : "UnsignedInteger"
        },
        "value": {
          "type": "integer",
          "minimum": 0,
          "maximum": 18446744073709551615
        },
        "size": {
          "type": "integer",
          "minimum": 1,
          "maximum": 64
        }
      },
      "maxProperties" : 3,
      "required": [
        "size",
        "value",
        "type"
      ],
      "title": "UnsignedInteger"
    },
    "Integer": {
      "type": "object",
      "properties": {
        "type" : {
          "type" : "string",
          "const" : "Integer"
        },
        "value": {
          "type": "integer",
          "minimum": -9223372036854775808,
          "maximum": 9223372036854775807
        },
        "size": {
          "type": "integer",
          "minimum": 1,
          "maximum": 64
        }
      },
      "maxProperties" : 3,
      "required": [
        "size",
        "value",
        "type"
      ],
      "title": "Integer"
    },
    "Null": {
      "type": "object",
      "properties" : {
        "type" : {
                "type" : "string",
            "const" : "Null"
        },
              "value" : {
                "type" : "null"
        }
      },
      "maxProperties" : 2,
      "required" : ["type", "value"],
      "title": "Null"
    },
    "Offset": {
      "type": "object",
      "properties": {
        "type" : {
          "type" : "string",
          "const" : "Offset"
        },
        "magnitude": {
          "type": "object",
          "oneOf": [
            {
              "$ref": "#/definitions/UnsignedInteger"
            },
            {
              "$ref": "#/definitions/Integer"
            }
          ]
        },
        "base": {
          "type": "object",
          "allOf" : [
            {"$ref": "#/definitions/UnsignedInteger"},
          ],
          "properties" : {
            "size" : {
              "const" : 64
            }
          },
          "required" : ["size"]
        }
      },
      "maxProperties" : 3,
      "required": [
        "magnitude",
        "base",
        "type"
      ],
      "title": "Offset"
    },
    "String": {
      "type": "object",
      "properties": {
        "type" : {
          "type" : "string",
          "const" : "String"
        },
        "value": {
          "type": "string"
        }
      },
      "maxProperties" : 2,
      "required": [
        "value",
        "type"
      ],
      "title": "String"
    },
    "StructField" : {
      "type" : "object",
      "properties" : {
        "offset" : {
          "type" : "object",
          "$ref" : "#/definitions/Offset"
        },
        "name" : {
          "type" : "object",
          "$ref" : "#/definitions/String"
        },
        "value" : {
          "type" : "object",
          "anyOf" : [
              {"$ref": "#/definitions/String"},
              {"$ref": "#/definitions/Struct"},
              {"$ref": "#/definitions/Array"},
              {"$ref": "#/definitions/UnsignedInteger"},
              {"$ref": "#/definitions/Integer"},
              {"$ref": "#/definitions/Offset"}
          ]
        }
      },
      "required" : [
        "offset",
        "name",
        "value"
      ]
    },
    "Method" : {
      "type" : "object",
      "properties" : {
        "name" : {
          "type" : "object",
          "$ref" : "#/definitions/String"
        },
        "value" : {
          "type" : "object",
          "$ref" : "#/definitions/Closure"
        }
      }
    },
    "Struct": {
      "type":"object",
      "properties":{
        "type" : {
          "type" : "string",
          "const" : "Struct"
        },
        "fields": {
          "type" : "array",
          "items" : {
            "type" : "object",
            "$ref" : "#/definitions/StructField"
          }
        },
        "methods" : {
          "type" : "array",
          "items" : {
            "type" : "object",
            "$ref" : "#/definitions/Method"
          }
        },
        "mapping" : {
                "type" : "object",
            "oneOf" : [
              {"$ref" : "#/definitions/Mapping"},
              {"$ref" : "#/definitions/Null"}
            ]
        }
      },
      "maxProperties" : 4,
      "required": [
        "fields",
        "methods",
        "type",
        "mapping"
      ],
      "title": "Struct"
    },
    "Closure" : {
      "type" : "object",
      "properties" : {
        "type" : {
          "type" : "string",
          "const" : "Closure"
        },
      },
      "$comment" : "maxProperties 1 for now",
      "maxProperties" : 1,
      "required" : ["type"]
    },
    "Mapping": {
      "type": "object",
      "properties": {
        "IOS": {
          "type": "integer",
          "minimum" : -2147483648,
          "maximum" :  2147483647
        },
        "offset": {
          "type": "object",
          "$ref": "#/definitions/Offset"
        }
      },
      "required": [
        "IOS",
        "offset"
      ],
      "title": "Mapping"
    },
    "Array": {
      "type" : "object",
      "properties" : {
        "type" : {
          "type" : "string",
          "const" : "Array"
        },
        "elements" : {
            "type": "array",
            "items": {
              "type": "object",
              "anyOf" : [
                {"$ref": "#/definitions/String"},
                {"$ref": "#/definitions/Struct"},
                {"$ref": "#/definitions/Array"},
                {"$ref": "#/definitions/UnsignedInteger"},
                {"$ref": "#/definitions/Integer"},
                {"$ref": "#/definitions/Offset"}
              ]
            }
        },
        "mapping" : {
                "type" : "object",
            "oneOf" : [
              {"$ref" : "#/definitions/Mapping"},
              {"$ref" : "#/definitions/Null"}
            ]
        }
      },
      "maxProperties" : 3,
      "required" : [
        "elements",
        "type",
        "mapping"
      ]
    }
  },
  "type": "object",
  "properties": {
    "PokeObject" : {
      "type" : "object",
       "anyOf" : [
          {"$ref": "#/definitions/String"},
          {"$ref": "#/definitions/Struct"},
          {"$ref": "#/definitions/Array"},
          {"$ref": "#/definitions/UnsignedInteger"},
          {"$ref": "#/definitions/Integer"},
          {"$ref": "#/definitions/Offset"}
        ]
    }
  },
  "additionalProperties": false
}


--------USAGE EXAMPLES--------

{
  "PokeObject" : { "type" : "Array" ,
    "elements" :
    [
      {"type" : "String", "value" : "jemarch"},
      {"type" : "UnsignedInteger", "value" : 15, "size" : 1}
    ],

    "mapping" : {

      "IOS" : 15, "offset" : {
        "type" : "Offset" , "magnitude" : {"type" : "UnsignedInteger" ,
"value" : 15, "size" : 1}, "base" : {"type" : "UnsignedInteger",
"value" : 15, "size" : 64}
      }

    }

  },

  "PokeObject" : {"type" : "Struct", "fields" : [], "methods" : [],

    "mapping" :  {"type" : "Null", "value" : null}}

}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]