Skip to content

Generalize JSON schemas #5

Description

@dennib

Need help generalizing data schemas currently divided into two files:

  • data-schema.json
  • move-schema.json

move-schema.json is referenced inside of data-schema.json.

Currently data-schema.json is too verbose imho.

{
    "type": "object",
    "required": [
        "ryu",
        "chun-li",
        "nash",
         ...
        "seth"
    ],
    "properties": {
        "abigail": {
            "type": "object",
            "properties": {
                "vt1": {
                    "type": "array",
                    "items": {
                        "allOf": [
                            {
                                "type": "object",
                                "$ref": "file:data/schemas/move-schema.json"
                            }
                        ]
                    }
                },
                "vt2": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "$ref": "file:data/schemas/move-schema.json"
                    }
                }
            }
        },
        "akuma": {
            "type": "object",
            "properties": {
                "vt1": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "$ref": "file:data/schemas/move-schema.json"
                    }
                },
                "vt2": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "$ref": "file:data/schemas/move-schema.json"
                    }
                }
            }
        },
        "alex": {
            "type": "object",
            "properties": {
                "vt1": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "$ref": "file:data/schemas/move-schema.json"
                    }
                },
                "vt2": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "$ref": "file:data/schemas/move-schema.json"
                    }
                }
            }
        },

Every character is repeating its internal structure.

What I would like to do:

  1. Avoid to list evey single character, saying instead something like every root level property is an object of "this" type
  2. "this" type should be a reference to a new schema, the char-schema inside a new file (char-schema.json)
  3. Char schema should say something like required properties are "vt1" and "vt2", every root level properties are of type "array", containing items of type move-schema of move-schema.json

I wasn't able to specify a single rule for all the properties at a specif level (using "allOf") and to reference a local schema from within a referenced schema (reference move-schema from char-schema)

Help please :P

Metadata

Metadata

Assignees

Labels

help wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions