Azure / azure-iot-cli-extension

Azure IoT extension for Azure CLI
Other
83 stars 65 forks source link

Additional properties are not allowed ('$schema' was unexpected) #100

Closed baywet closed 4 years ago

baywet commented 4 years ago

Repro: Command

az iot edge deployment create --config-id desktop-test --hub-name senseaiqahub --content ./saip02.json --target-condition deviceId='saip02' --priority 0 --output none

Configuration file

{
   "$schema": "https://raw.githubusercontent.com/SLdragon/schemastore/master/src/schemas/json/azure-iot-edge-deployment-1.0.json",
    "modulesContent": {
        "$edgeAgent": {
            "properties.desired": {
                "modules": {
                    "agent": {
                        "settings": {
                            "image": "senseai.azurecr.io/agent:1114",
                            "createOptions": "{\"HostConfig\":{\"PortBindings\":{\"1883/tcp\":[{\"HostPort\":\"1883\"}]}}}"
                        },
                        "type": "docker",
                        "env": {
                            "CLIENTID": {
                                "value": "senseaidev"
                            },
                            "SITEID": {
                                "value": "montreal"
                            },
                            "ALLOWEDCLIENTIDS:0": {
                                "value": "redacted"
                            }
                        },
                        "status": "running",
                        "restartPolicy": "always",
                        "version": "1.0"
                    }
                },
                "runtime": {
                    "settings": {
                        "minDockerVersion": "v1.25",
                        "registryCredentials": {
                            "senseai": {
                                "address": "senseai.azurecr.io",
                                "password": "redacted",
                                "username": "redacted"
                            }
                        }
                    },
                    "type": "docker"
                },
                "schemaVersion": "1.0",
                "systemModules": {
                    "edgeAgent": {
                        "settings": {
                            "image": "mcr.microsoft.com/azureiotedge-agent:1.0",
                            "createOptions": ""
                        },
                        "type": "docker"
                    },
                    "edgeHub": {
                        "settings": {
                            "image": "mcr.microsoft.com/azureiotedge-hub:1.0",
                            "createOptions": "{\"HostConfig\":{\"PortBindings\":{\"443/tcp\":[{\"HostPort\":\"443\"}],\"5671/tcp\":[{\"HostPort\":\"5671\"}],\"8883/tcp\":[{\"HostPort\":\"8883\"}]}}}"
                        },
                        "type": "docker",
                        "status": "running",
                        "restartPolicy": "always"
                    }
                }
            }
        },
        "$edgeHub": {
            "properties.desired": {
                "routes": {
                    "route": "FROM /messages/* INTO $upstream"
                },
                "schemaVersion": "1.0",
                "storeAndForwardConfiguration": {
                    "timeToLiveSecs": 7200
                }
            }
        }
    }
}

Error message

Additional properties are not allowed ('$schema' was unexpected)

Failed validating 'additionalProperties' in schema:
    {'$schema': 'http://json-schema.org/draft-04/schema#',
     'additionalProperties': False,

Workaround removing the $schema property from our configuration file. Azure cli version: 2.0.74 extension version: 0.8.2 environment: windows Note: also having the issue with azure iot edge tasks for azure devops on ubuntu hosted agent.

baywet commented 4 years ago

Note, also tried with schema "http://json.schemastore.org/azure-iot-edge-deployment-template-1.0"

digimaun commented 4 years ago

The CLI now validates your deployment with this schema which should be compatible with 1.0. As you mentioned you need to remove "$schema" - because its not a defined property in the schema and the schema is not configured to allow additional properties at that context.

If you are using $schema in conjunction with editor/ide tooling support, in a future release we can pop this element before validation to support your use case.

baywet commented 4 years ago

Thanks for the quick follow up. Yes we'd like to keep the schema, makes things much easier in the IDE.

baywet commented 4 years ago

closing as 0.8.3 fixes the issue. Thanks for the quick turnaround!