Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON-structure-validator example doesn't seem to work #8

Open
wolfen opened this issue Jul 1, 2018 · 3 comments
Open

JSON-structure-validator example doesn't seem to work #8

wolfen opened this issue Jul 1, 2018 · 3 comments

Comments

@wolfen
Copy link

wolfen commented Jul 1, 2018

Attempting to run the suggested example in Runkit, I see this (screen capture is attached): https://www.dropbox.com/s/vchk5v7qu9n664f/Screenshot%202018-07-01%2010.02.11.png?dl=0

I'm not sure why the validation failed; An "aliases" array with a single record is expected?

@wolfen
Copy link
Author

wolfen commented Jul 1, 2018

In case the above dropbox link is not accessible for any reason, here's the code I pasted into the runkit window:

var compareJSON = require("json-structure-validator");

var emptyMapSingle = {
        "name" : "",
        "username": "",
        "id": "",
        "aliases": [ {
            "alias": "",
            "id": ""
        }]
    };
 
var emptyMap = [];
emptyMap.push(emptyMapSingle);

body = {
  name: "Foo",
  username: "foo",
  id: 123,
  aliases: [ { "alias": "Bar", "id": "234" } ]
}

const compare = compareJSON(body, emptyMap);
console.log(`compare=${JSON.stringify(compare)}`);

And here's the output I saw:

"compare=\"Objects do not match at aliases\""

I expected to see:

"compare=\"true\""

@wolfen
Copy link
Author

wolfen commented Jul 1, 2018

I found that this version does work as expected:

var compareJSON = require("json-structure-validator");

var emptyMapSingle = {
        "name" : "",
        "username": "",
        "id": "",
        "aliases": [ {
            "alias": "",
            "id": ""
        }]
    };

body = {
  name: "Foo",
  username: "foo",
  id: 123,
  aliases: [ { "alias": "Bar", "id": "234" } ]
}

const compare = compareJSON(body, emptyMapSingle);
console.log(`compare=${JSON.stringify(compare)}`);

This is the output:

"compare=true"

So the problem appears to be with passing an array of map structures as the second parameter to compareJSON(). If this feature is supported by the package, then the documentation should be updated to include a working example; Otherwise, the example should be removed.

@AntJanus
Copy link
Owner

AntJanus commented Jul 2, 2018

It all works as expected, the problem is with the example and the docs. It seems that I made some mistakes around it. Thanks for letting me now, I'll get to it when I have a chance.

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

No branches or pull requests

2 participants