poke-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Updated JSON Schema, pk_mi_val_to_json, pk_mi_json_to_val an


From: Jose E. Marchesi
Subject: Re: [PATCH] Updated JSON Schema, pk_mi_val_to_json, pk_mi_json_to_val and a test file
Date: Fri, 26 Jun 2020 12:36:14 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

[Sorry for the delay on replying to this.]

    Hello, I have updated our JSON Schema, finished pk_mi_val_to_json and
    pk_mi_json_to_val functions and added a test file.

Thanks.

In this email I'm reviewing the schema part only.  In the future, please
split patches among domains, i.e. use a separated commit for the JSON
schema update, and another for work in pk-json.

    The only reason I added this test file on the commit is just for you to
    see the code and, if you wish, copy it on poke.c and see yourself that it
    works.

We really need to setup some infrastructure so we can write unit tests.
I will do so this coming weekend.
    
    Please note that pk_mi_json_to_val and pk_mi_val_to_json are not
    completely finished, we need to add more functionality about mapped
    structs and/or arrays, as discussed on IRC.

Noted.
    
    diff --git a/poke/pk-mi-json-schema.json b/poke/pk-mi-json-schema.json
    new file mode 100644
    index 00000000..ea894500
    --- /dev/null
    +++ b/poke/pk-mi-json-schema.json


I would place pk-mi-json-schema.json in etc/ rather than in poke/.

By the way, did you find out whether libjson-c supports validating data
against json-schemas?  Or any other C library?  If so, we could write
schemas for all the MI JSON and then rely on correct input in the json
conversion routines.

    @@ -0,0 +1,284 @@
    +{
    +    "$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"
    +        },
    +        "String": {
    +            "type": "object",
    +            "properties": {
    +                "type" : {
    +                    "type" : "string",
    +                    "const" : "String"
    +                },
    +                "value": {
    +                    "type": "string"
    +                }
    +            },
    +            "maxProperties" : 2,
    +            "required": [
    +                "value",
    +                "type"
    +            ],
    +            "title": "String"
    +        },
    +        "Offset": {
    +            "type": "object",
    +            "properties": {
    +                "type" : {
    +                    "type" : "string",
    +                    "const" : "Offset"
    +                },
    +                "magnitude": {
    +                    "type": "object",
    +                    "oneOf": [
    +                    {
    +                        "$ref": "#/definitions/UnsignedInteger"
    +                    },
    +                    {
    +                        "$ref": "#/definitions/Integer"
    +                    }
    +                    ]
    +                },
    +                "unit": {
    +                    "type": "object",
    +                    "allOf" : [
    +                    {"$ref": "#/definitions/UnsignedInteger"}
    +                    ],
    +                    "properties" : {
    +                        "size" : {
    +                            "const" : 64
    +                        }
    +                    },

Hmm, can you show an example of an encoded offset?

Are the properties of the "unit" object the properties of the referred
UnsignedInteger plus the "size"?  Or how does it work?

Also, can the "allOf" with a single alternative be simply replaced with
a "$ref"?

    +                    "required" : ["size"]
    +                }
    +            },
    +            "maxProperties" : 3,
    +            "required": [
    +                "magnitude",
    +                "base",
    +                "type"
    +            ],
    +            "title": "Offset"
    +        },
    +        "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"}
    +                    ]
    +                }
    +            },
    +            "maxProperties": 3,
    +            "required" : [
    +                "offset",
    +                "name",
    +                "value"
    +            ]
    +        },
    +        "Struct": {
    +            "type":"object",
    +            "properties":{
    +                "type" : {
    +                    "type" : "string",
    +                    "const" : "Struct"
    +                },
    +                "name" : {
    +                    "type" : "object",
    +                    "$ref" : "#/definitions/String"
    +                },
    +                "fields": {
    +                    "type" : "array",
    +                    "items" : {
    +                        "type" : "object",
    +                        "$ref" : "#/definitions/StructField"
    +                    }
    +                },
    +                "mapping" : {
    +                    "type" : "object",
    +                    "oneOf" : [
    +                        {"$ref" : "#/definitions/Mapping"},
    +                        {"$ref" : "#/definitions/Null"}
    +                    ]
    +                }
    +            },
    +            "maxProperties" : 3,
    +            "required": [
    +                "fields",
    +                "type",
    +                "mapping",
    +                "name"
    +            ],
    +            "title": "Struct"
    +        },
    +        "Mapping": {
    +            "type": "object",
    +            "properties": {
    +                "IOS": {
    +                    "type": "integer",
    +                    "minimum" : -2147483648,
    +                    "maximum" :  2147483647
    +                },
    +                "offset": {
    +                    "type": "object",
    +                    "$ref": "#/definitions/Offset"
    +                }
    +            },
    +            "maxProperties": 2,
    +            "required": [
    +            "IOS",
    +            "offset"
    +            ],
    +            "title": "Mapping"
    +        },
    +        "Array": {
    +            "type" : "object",
    +            "properties" : {
    +                "type" : {
    +                    "type" : "string",
    +                    "const" : "Array"
    +                },
    +                "elements" : {
    +                "type": "array",
    +                    "items": {
    +                        "type": "object",
    +                        "properties" : {
    +                            "value" : {
    +                                "type" : "object",
    +                                "oneOf" : [
    +                                    {"$ref": "#/definitions/Integer"},
    +                                    {"$ref":
    "#/definitions/UnsignedInteger"},
    +                                    {"$ref": "#/definitions/String"},
    +                                    {"$ref": "#/definitions/Struct"},
    +                                    {"$ref": "#/definitions/Array"},
    +                                    {"$ref": "#/definitions/Offset"},
    +                                    {"$ref": "#/definitions/Null"}

Isn't this replicating the PokeValue of the top-level object defined
below?  Isn't there a way to refer to it recursively?

    +                                    ]
    +                            },
    +                            "offset" : {
    +                                "type" : "object",
    +                                "$ref" : "#/definitions/Offset"
    +                            }
    +                        },
    +                        "maxProperties" : 2,
    +                        "required" : [
    +                            "value",
    +                            "offset"
    +                        ]
    +                    }
    +                },
    +                "mapping" : {
    +                    "type" : "object",
    +                        "oneOf" : [
    +                        {"$ref" : "#/definitions/Mapping"},
    +                        {"$ref" : "#/definitions/Null"}
    +                        ]
    +                }
    +            },
    +            "maxProperties" : 3,
    +            "required" : [
    +                    "elements",
    +                    "type",
    +                    "mapping"
    +                ]
    +        },
    +        "Null": {
    +            "type": "object",
    +            "properties" : {
    +            "type" : {
    +                    "type" : "string",
    +                    "const" : "Null"
    +                },
    +                    "value" : {
    +                    "type" : "null"
    +                }
    +            },
    +            "maxProperties" : 2,
    +            "required" : ["type", "value"],
    +            "title": "Null"
    +        }
    +    },
    +    "type": "object",
    +    "properties": {
    +      "PokeValue" : {
    +        "type" : "object",
    +         "anyOf" : [
    +            {"$ref": "#/definitions/Integer"},
    +            {"$ref": "#/definitions/UnsignedInteger"},
    +            {"$ref": "#/definitions/String"},
    +            {"$ref": "#/definitions/Struct"},
    +            {"$ref": "#/definitions/Array"},
    +            {"$ref": "#/definitions/Offset"},
    +            {"$ref": "#/definitions/Null"}
    +          ]
    +      }
    +    },
    +    "additionalProperties": false
    +}



reply via email to

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