IndustryFusion / DigitalTwin

This repository contains the ingredients for the Digital Twin Concept of Industry Fusion.
Apache License 2.0
25 stars 15 forks source link

[Issue] JSON Schema Validation tool #478

Open LahariMIBS opened 7 months ago

LahariMIBS commented 7 months ago

Issue 1:

Validation tool is not validating the ‘datatype’ and ‘unit’ keys in the JSON-Schema.

The JSON-Schema must accommodate two different type related keys, one is ‘datatype’ that is inherited from ECLASS for XSD types, and one is ‘type’ for UI usage that might contain types like ‘string’, ‘array’, 'number', etc. The JSON-Schema must also accommodate ‘unit’ key for some properties to use in UI.

Hence, we need to include ‘datatype’ and ‘unit’ in validation process.

Example JSON-Schema:


{ 

  "$schema": "http://json-schema.org/schema#", 

  "$id": "https://industry-fusion.org/eclass%230173-1%2301-AKJ975%23017", 

  "title": "Plasma Cutter POC", 

  "description": "Plasma Cutter template for IFF", 

  "type": "object", 

  "properties": { 

    "eclass:0173-1#02-AAH841#003": { 

      "type": "number", 

      "datatype": "xsd:double", 

      "title": "max. center cut", 

      "description": "maximum spacial expansion of the centre cut", 

      "unit": "mm" 

    } 

    } 

} 

Issue 2:

Validation tool is validating unknown fields.

Expected:

Field doesn’t exist in the schema.

Actual:

The data is getting validated successfully.

Example JSON-Schema:


{ 

  "$schema": "http://json-schema.org/schema#", 

  "$id": "https://industry-fusion.org/eclass%230173-1%2301-AKJ975%23017", 

  "title": "Plasma Cutter POC", 

  "description": "Plasma Cutter template for IFF", 

  "type": "object", 

  "properties": { 

    "machine_state": { 

        "type": "string", 

        "title": "Machine Status", 

        "description": "Current status of the machine (Online_Idle, Run, Online_Error, Online_Maintenance,   Setup, Testing)", 

        "readOnly": false 

    }, 

    "eclass:0173-1#02-AAH841#003": { 

      "type": "number", 

      "datatype": "xs:double", 

      "title": "max. center cut", 

      "description": "maximum spacial expansion of the centre cut", 

      "unit": "mm" 

    } 

} 

Example JSON-LD Data:


{ 

    "@context": "https://industryfusion.github.io/contexts/v0.1/context.jsonld", 

    "id": "urn:iff:abc123", 

    "type": "eclass:0173-1#01-AKJ975#017", 

    "machine_state": "Testing",  

    "unknown_field": 12457,  ##invalid field 

    "eclass:0173-1#02-AAH841#003": 25 

} 
wagmarcel commented 6 months ago

first part: @LahariMIBS this can be solved by adding both field names to the addedKeywords array in validate.js. Please create a PR for it, in the PR please add the example in the examples directory and add one example to tests/validation directory for script tests. second part: This needs a little bit more considerations. JSON-LD is also adding fields which must be ignored by the schema (e.g the "@context" field in your example. When we validate that strict, we can run into other problems.