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

No causing exceptions #33

Closed
ivanalikin opened this issue Apr 29, 2016 · 9 comments
Closed

No causing exceptions #33

ivanalikin opened this issue Apr 29, 2016 · 9 comments

Comments

@ivanalikin
Copy link

Hi,
I have an error "#: only 1 subschema matches out of 2" but it's not possible to know what exactly caused the error since the getCausingExceptions() returns an empty list.

@jebbench
Copy link

I'm having the same issue; I get the message "#: 2 schema violations found" but there are no causing exceptions.

@erosb
Copy link
Contributor

erosb commented May 24, 2016

Thanks guys for reporting it. You may send a PR with a bugfix in
CombinedSchema.java but I won't fix it on my own until the middle of June,
due to other activities.
On 24 May 2016 12:32, "James Bench" notifications@github.com wrote:

I'm having the same issue; I get the message "#: 2 schema violations
found" but there are no causing exceptions.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#33 (comment)

erosb added a commit that referenced this issue Jun 26, 2016
@erosb
Copy link
Contributor

erosb commented Jun 26, 2016

I've just committed the bugfix, it will be released with 1.4.0

@erosb erosb closed this as completed Jun 26, 2016
@Sudesh1989
Copy link

Hi, iam facing the above issue when I call getCausingExceptions() method in ValidationException class. The getCausingExceptions() method returns valid exception list for multiple schema violations, but it returns empty list for a single schema violation?

@saurabhdwivedi13
Copy link

I am getting this even in 1.9.2 version.

@electronABS
Copy link

@erosb
Same thing with the latest version 1.11.1 returns empty list for a single schema violation !!

@erosb
Copy link
Contributor

erosb commented Jun 21, 2019

@electronABS please post reproduction details (schema, instance json).

@electronABS
Copy link

electronABS commented Jun 21, 2019

@erosb

  • Schema "Report.json"

{
"$schema":"http://json-schema.org/draft-07/schema#",
"title":"Report",
"description":"A report json format",
"type":"object",
"required":[
"startedAt",
"finishedAt",
"agentId",
"reportType",
"reportJSON"
],
"properties":{
"agentId":{
"description":"The agent's who generate the discovery report'",
"type":"integer"
},
"reportType":{
"description":"The report type",
"type":"string"
},
"reportJSON":{
"description":"The discovered object",
"type":"object",
"required":[
"certificates"
],
"properties":{
"certificates":{
"description":"The discovered certificates array",
"type":"array",
"items":{
"type":"object",
"required":[
"certB64",
"certPath",
"hostFQDN",
"appVersion",
"appConfPath",
"appProduct"
],
"properties":{
"certB64":{
"type":"string"
},
"certFileExt":{
"type":"string"
},
"certFileName":{
"type":"string"
},
"certPath":{
"type":"string"
},
"privateKeyPath":{
"type":"string"
},
"hostFQDN":{
"type":"string"
},
"appProduct":{
"type":"string"
},
"appVersion":{
"type":"string"
},
"appConfPath":{
"type":"string"
}
}
}
}
}
},
"startedAt":{
"description":"Discovery job start data-time",
"type":"string",
"format":"date-time"
},
"finishedAt":{
"description":"Discovery job finish data-time",
"type":"string",
"format":"date-time"
}
}
}

  • Instance to validate with one violation (agentId required but not exist)
    `
    {
    "agentType" ; "testType" ,
    "reportJSON": {
    "certificates": [
    {"certB64": "testCertB64",
    "certFileExt": "testCertFileExt" ,
    "certFileName": "testCertFileName" ,
    "certPath": "testCertPath" ,
    "privateKeyPath": "testPrivateKeyPath" ,
    "hostFQDN": "testHostFQDN",
    "appProduct": "testAppProduct",
    "appVersion": "testAppVersion",
    "appConfPath": "testAppConfPath"}
    ]} ,
    "startedAt" : "2019-11-13T20:20:39+00:00" ,
    "finishedAt" : "2019-11-13T20:22:39+00:00"
    }

  • Validate java service

`
public static List jsonValidator(File JSONSchemaFile, JSONObject JSONToValidate)
throws FileNotFoundException {
List listOfViolations = new ArrayList<>();
log.debug("starting validate json object...");
try {
InputStream schemaStream = new FileInputStream(JSONSchemaFile);
JSONObject jsonSchema = new JSONObject(new JSONTokener(schemaStream));
Schema schema = SchemaLoader.load(jsonSchema);
schema.validate(JSONToValidate);
} catch (ValidationException e) {

listOfViolations = e.getCausingExceptions().stream().map(ValidationException::getMessage)
					.collect(Collectors.toList());
		
	}
	return listOfViolations;
}

`

  • Expected behaviour
    listOfViolations : [#: required key [agentId] not found]

  • Actual behaviour
    listOfViolations : []

@erosb
Copy link
Contributor

erosb commented Jun 25, 2019

Hi @electronABS I ran a test with your input and got the following output (by calling Validationexception#toJSON(), which looks correct for me (2 causing exceptions):

{
    "causingExceptions": [
        {
            "causingExceptions": [],
            "keyword": "required",
            "message": "required key [agentId] not found",
            "pointerToViolation": "#",
            "schemaLocation": "#"
        },
        {
            "causingExceptions": [],
            "keyword": "required",
            "message": "required key [reportType] not found",
            "pointerToViolation": "#",
            "schemaLocation": "#"
        }
    ],
    "message": "2 schema violations found",
    "pointerToViolation": "#",
    "schemaLocation": "#"
}

Reproduction testcase added in 0d797d0

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

6 participants