eclipse-basyx / basyx-databridge

Eclipse Public License 2.0
9 stars 13 forks source link

[Suggestion] Validation of JSON configuration files againts JSON Schema file #263

Closed BlackRose01 closed 5 months ago

BlackRose01 commented 9 months ago

Hi,

I have a suggestion to standardize the validation of the JSON configuration, extend it slightly and make it more readable for external developers. This is especially helpful if you want to change certain options or have to rebuild the whole configuration file.

Therefore, I would recommend the use of JSON Schema. This is a specification for describing the structure of JSON files. Also provided are libraries [1] for it that provide validation of the schema with a JSON string/object.

Since I need to create some AAS Databridges in my current project Fed-X-Pro, I created a tool for me where I can create just these configurations for the AAS. I have the form for this created based on the schema and at the same time validate the data entered against it.

The advantages of this would be the following:

[1] Example for library: Vertx

KR, BlackRose01


JSON Schema for opcuaconsumer.json

{
    "$id": "https://example.com/person.schema.json",
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "title": "opcuaconsumer.json",
    "type": "object",
    "required": [
        "uniqueId",
        "pathToService",
        "nodeInformation"
    ],
    "properties": {
        "uniqueId": {
            "title": "Unique ID",
            "type": "string",
            "description": "Unique ID to match options",
            "pattern": "^[a-z0-9-]+$"
        },
        "serverUrl": {
            "title": "Hostname or IP",
            "type": "string",
            "description": "IP or Hostname of the OPC UA Server",
            "default": "127.0.0.1",
            "pattern": "^([a-z0-9-_\\.]+\\.[a-z]{1,3}|[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})$"
        },
        "serverPort": {
            "title": "Port",
            "description": "Port of the OPC UA Server",
            "type": "integer",
            "minimum": 0,
            "maximum": 65535,
            "default": "4048"
        },
        "pathToService": {
            "title": "Path to Service",
            "type": "string",
            "description": "URI of the Service in the OPC UA Server",
            "pattern": "[a-z/]+"
        },
        "nodeInformation": {
            "title": "OPC UA Node ID",
            "type": "string",
            "description": "Path to a variable node in the OPC UA Server"
        },
        "username": {
            "title": "Username",
            "type": "string",
            "description": "Username to authenticate to the OPC UA Server"
        },
        "password": {
            "title": "Password",
            "type": "string",
            "description": "Password to authenticate to the OPC UA Server"
        },
        "parameters": {
            "title": "Parameters",
            "type": "object",
            "properties": {
                "requestedPublishingInterval": {
                    "type": "integer",
                    "description": "Interval to request the value of the variable",
                    "minimum": 500,
                    "default": "500"
                },
                "clientId": {
                    "type": "string",
                    "description": "A virtual client id to force the creation of a new connection instance"
                },
                "dataChangeFilterDeadbandType": {
                    "type": "integer",
                    "description": "Deadband type for MonitorFilterType DataChangeFilter"
                },
                "dataChangeFilterDeadbandValue": {
                    "type": "number",
                    "description": "Deadband value for MonitorFilterType DataChangeFilter"
                },
                "allowedSecurityPolicies": {
                    "enum": [
                        "None",
                        "Basic128Rsa15",
                        "Basic256",
                        "Basic256Sha256",
                        "Aes128_Sha256_RsaOaep",
                        "Aes256_Sha256_RsaPss"
                    ],
                    "default": "None",
                    "description": "A set of allowed security policy URIs. Default is to accept all and use the highest"
                },
                "keyAlias": {
                    "type": "string",
                    "description": "The name of the key in the keystore file"
                },
                "keyPassword": {
                    "type": "string",
                    "description": "The key password"
                },
                "keyStorePassword": {
                    "type": "string",
                    "description": "The keystore password"
                },
                "keyStoreType": {
                    "type": "string",
                    "description": "The key store type"
                },
                "keyStoreUrl": {
                    "type": "string",
                    "description": "The URL where the key should be loaded from"
                },
                "sessionName": {
                    "type": "string",
                    "description": "Session name",
                    "pattern": "[a-z0-9-]*"
                },
                "sessionTimeout": {
                    "type": "integer",
                    "description": "Session timeout in milliseconds",
                    "minimum": 0
                }
            }
        }
    }
}
FrankSchnicke commented 9 months ago

This is an interesting idea. Would you be willing to contribute your created JSON schemas?

BlackRose01 commented 9 months ago

Actually I'm not sure if I have all consumers/transformers transfered to JSON-Schema but here are my current files. Maybe you also have to adjust some points to meet your requirements but basically they should work.

Consumers

honoconsumer.schema.json httpconsumer.schema.json kafkaconsumer.schema.json mqttconsumer.schema.json opcuaconsumer.schema.json plc4xconsumer.schema.json activemqconsumer.schema.json

Transformers

jsonatatransformer.schema.json jsonjacksontransformer.schema.json

KR, BlackRose01

FrankSchnicke commented 5 months ago

Thanks a lot for providing these schemas!