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

Is it possible to have all errors reported in one step? #6

Closed
balasaalin opened this issue Oct 22, 2015 · 11 comments
Closed

Is it possible to have all errors reported in one step? #6

balasaalin opened this issue Oct 22, 2015 · 11 comments

Comments

@balasaalin
Copy link

The validator reports only the first error it encounters and stops. It would be useful to report all the errors.

For the JSON instance and JSON Schema samples below, I would expect to get both errors without having to fix one error and then validate again in order to get the second error:
expected type: String, found: Integer
extraneous key [otherProp] is not permitted

Schema:

{
  "properties" : {
    "prop" : {
      "type" : "string"
    }
  },
  "additionalProperties":false
}

Instance:

{
  "prop": 4,
  "otherProp": 5
}
@erosb
Copy link
Contributor

erosb commented Oct 26, 2015

@balasaalin thank your for reporting this issue. The current version of the library was designed with only having the "if the JSON is valid" question in mind, but enhancing it to scan everything and to provide a list of failures in a programmatically consumable manner makes sense for me.

So my idea is to enhance the ValidationException to contain a list of failure descriptions, each having a

  • readable error description (the current exception message)
  • a JSON pointer pointing to the violating value
  • a reference to the violated Schema instance

I will try to handle it without breaking the current API.

@illumi
Copy link

illumi commented Nov 9, 2015

This would be a really nice feature.

@illumi
Copy link

illumi commented Nov 27, 2015

I tested this feature with a complicated structure and have an issue. Inner Object which is contained inside an array doesn't seem to be picked up in validation.

I'm using this site for reference which does detect the error in the below example: http://jsonschemalint.com/draft4/#

JSON Document:

{
    "notification": {
        "message": "test",
        "sound": "sounds/alarmsound.wav",
        "target": {
            "apps": [
                {
                    "id": "This should be a number type!",
                    "platforms": [
                        "ios"
                    ]
                }
            ]
        }
    },
    "access_token": "access_token",
    "testNull": null,
    "testBoolean": true
}

Schema:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "NotificationApp",
    "description": "A structure specifying some sort of notification",
    "type": "object",
    "properties": {
        "notification": {
            "description": "The notification",
            "type": "object",
            "properties": {
                "message": {
                    "type": "string"
                },
                "sound": {
                    "type": "string"
                },
                "target": {
                    "type": "object",
                    "properties": {
                        "apps": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "number"
                                    },
                                    "platforms": {
                                        "type": "array",
                                        "items": {
                                            "type": "string"
                                        }
                                    }
                                },
                                "required": ["id", "platforms"]
                            }
                        }
                    },
                    "required": ["apps"]
                }
            },
            "required": ["message", "sound", "target"]
        },
        "access_token": {
            "description": "some sort of token",
            "type": "string"
        },
        "testNull": {
            "description": "some sort of null value",
            "type": "null"
        },
        "testBoolean": {
            "description": "some sort of boolean value",
            "type": "boolean"
        }
    },
    "required": ["notification", "access_token", "testNull", "testBoolean"]
}

erosb added a commit to erosb/everit-json-schema that referenced this issue Nov 27, 2015
@erosb
Copy link
Contributor

erosb commented Nov 27, 2015

@illumi are you sure you tested it with version 1.1.0 ?
I've just added a test with your inputs, and looks fine for me: erosb@1ed345f
(the ValidationException is thrown and its JSON pointer is correct)

@illumi
Copy link

illumi commented Nov 27, 2015

@erosb Ah, my bad. It seems to work perfectly :)

@erosb
Copy link
Contributor

erosb commented Nov 27, 2015

Ok, great :) I'm closing this issue.

@erosb erosb closed this as completed Nov 27, 2015
@pmdoll
Copy link

pmdoll commented Jan 14, 2016

Hello,
With version 1.1.1, I expect to see 2 validation messages for the given schema and data but I see only this one:
#: extraneous key [node-24522] is not permitted

The 2nd message should be about "additioanl" property.
Possibly a bug. Hope this helps.

Schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "id": "http://yourdomain.com/schemas/myschema.json",
  "title" : "TPN Full Schema",
  "description" : "To describe required TPN keys",

  "properties": {
    "network-id": {"type": "string"}
  },
  "required": ["network-id"],
  "additionalProperties": false,

  "patternProperties": {
    "^[a-z]+[0-9]+$":{
      "properties": {
        "uid":{"type":"string"},
        "tpn-type":{"type":"string"}
      },
      "required": ["uid", "tpn-type"]
    }
  }
}

Data:
{
"network-id": "net-24542",
"node-24522": {
"uid": "node-24522",
"activities": [
"act-24526",
"act-24524"
],
"constraints": [],
"incidence-set": [],
"end-node": "node-24523",
"tpn-type": "p-begin"
}
,"additioanl":true
}

@erosb
Copy link
Contributor

erosb commented Jan 14, 2016

Hi @pmdoll , thanks yor reporting it. I fixed it in 07ba71c .
If you don't mind we won't release this single bugfix now, because it is a very small patch, and I personally don't find it essentially important. But if this bugfix is urgent for you then we can make a release today or tomorrow.

@pmdoll
Copy link

pmdoll commented Jan 14, 2016

No urgency on my side.

@topazadam
Copy link

Was this bugfix ever released? I still have this issue.

@erosb
Copy link
Contributor

erosb commented Feb 7, 2019

Hello, this was fixed in version 1.1.0 , please read the manual, thanks.

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

5 participants