alexa-samples / alexa-smarthome

Resources for Alexa Smart Home developers.
https://alexa.design/smarthome
Other
679 stars 336 forks source link

Validation schema fails to parse in Node.js #174

Closed camdendobrien closed 1 year ago

camdendobrien commented 3 years ago

I'm trying to create some integration tests for a smart home skill back-end using the validation schema in this repository, but when I try to parse the file (using JSON.parse) I get an error:

> JSON.parse(fs.readFileSync('alexa_smart_home_message_schema.json', 'utf-8'))
Uncaught SyntaxError: Unexpected token } in JSON at position 262146

It's odd because looking at that part of the file it looks absolutely fine:

...
"proactivelyReported": {
    "oneOf": [
        {
            "type": "boolean"
        },
        {
            "type": "string",
            "enum": [
                "true",
                "false",
                "True",
                "False",
                "TRUE",
                "FALSE"
            ],
        }, // error is on this '}'
        {
            "type": "integer",
            "format": "int32",
            "enum": [
                0,
                1
            ]
        }
    ]
},
...
camdendobrien commented 3 years ago

There is actually a syntax error in the schema, will open a PR to fix it shortly.

Relequestual commented 3 years ago

While dangling commas are fine in JavaScript, they are not allowed in JSON. This seems to be the issue.

Relequestual commented 3 years ago

Looks like the schema is machine-generated! So you may have to dig into how, and fix the issue in code, rather than just PR the schema file.

camdendobrien commented 3 years ago

Looks like the schema is machine-generated! So you may have to dig into how, and fix the issue in code, rather than just PR the schema file.

Oh ok, that's a pain :joy:

camdendobrien commented 3 years ago

Can't find any information on how the schema is generated, hopefully will hear from the maintainers at some point ¯\_(ツ)_/¯

Relequestual commented 3 years ago

I don't think the code required to do this is in this repo, nor the source. The repo readme just says "resources".

Also suggest, add tests to check that schemas provided are...

  1. Valid JSON
  2. Valid JSON Schema
Sowmyanalluri commented 1 year ago

Closing this issue as there is a closed pull request https://github.com/alexa/alexa-smarthome/pull/175