Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add jsonschema extensions #91

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

tomhollingworth
Copy link

@tomhollingworth tomhollingworth commented Aug 3, 2023

Issue

Extending the JSON schema is difficult due to "additionalProperties": false on entities.

Extending AllSchema.json only provides two easy options; add extensions directly into AllSchema.json or maintain a file that lists every specific override.

  • Editing AllSchema.json prevents encapsulating extensions to definitions in a single file to maintain separation between original defintion and extensions,
  • Maintaining a file of every specific parent override file is very repetitive, cumbersome and doesn't follow the DRY principal. For example, consider an extension to EquipmentType with a new attribute "Color": {"type": "string"}. I would need to change all occurences of EquipmentType and override; GetEquipment, ProcessEquipment.... e.g.
{
    "$id": "B2MML_schema_extension.json",
    "$schema": "http://json-schema.org/2020-12/schema#",
    "title": "ODH - B2MML Schema extensions",
    "type": "object",
    "allOf": [
        {
            "$ref": "AllSchemas.json"
        }
    ],
    "properties": {
        "GetEquipment": {
            "properties": {
                "DataArea": {
                    "properties": {
                        "Equipment": {
                            "type": "array",
                            "items": {
                                "properties": {
                                    "Color": "string"
                                }
                            }
                        }
                    }
                }
            }
        },
        "ProcessEquipment": {
            "properties": {
                "DataArea": {
                    "properties": {
                        "Equipment": {
                            "type": "array",
                            "items": {
                                "properties": {
                                    "Color": "string"
                                }
                            }
                        }
                    }
                }
            }
        },
        ... other usages, e.g. ChangeEquipment, SyncEquimpent, AcknowledgeEquipmentType, CancelEquipment...
    }
}

Proposal

Introduce a new file for easy extension and update existing JSON schema to references the easy extension file. This change makes use of unevaluatedProperties attribute on original entities and drops additionalProperties.

❗️This proposal does introduce a dependency on the extension schema file being present to avoid warnings/errors, which previously didn't exist.

Add

  • Add a new AllSchema-Extensions file B2MML-AllExtensions.schema.json that can be used to extend entities.
  • Add allOf to include the extension file to allow

Change

  • Renamed AllSchema.json to AllSchema.schema.json
  • Changed Definitions in AllSchema.schema.json swap "additionalProperties": false for "unevaluatedProperties": false,

Example Usage

Add Color to EquipmentType

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant