Skip to content

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

@tomhollingworth
Copy link
Author

Due to the lack of interest here, I'm maintaining a JSON ISA95/88 schema over at https://github.com/libremfg/json-schema. If you just want to use the JSON schema refer to https://json.libremfg.ai/ as we are hosting it publicly for use in tools like vs-code.

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