Closed rakeshcusat closed 7 years ago
@rakeshcusat you mean multiple schemas for one json file?
@alenkacz let me clarify a bit. Initially I thought this validator can be used to validate the schema file for some syntax error. This would be useful if there are multiple files for different schema. This plugin doesn't validate the schema, but it validates the schema and the json file. So in other words this request is invalid. You can close this ticket.
@rakeshcusat ah that makes sense. And what is your use case? You have json files as a part of project and want to validate as part of gradle build that those are valid json files (syntactically?)
I can add feature doing that...
@alenkacz I have jsonSchema files which I want to validate whether they have any syntax error or not.
@rakeshcusat well, json schema is just a json file so I will add possibility to validate json files (syntactically not against schema) and that should solved this for you...
@alenkacz you are right it is just a json file and validating the json file may identify some of the issues. But some a valid json file can still have some invalid jsonschema syntax. For example one of the schema can refer other schema. If other schema is not existing the jsonschema validator should show an error.
{
"type" : "object",
"properties" : {
"loggedInUser" : {
"$ref" : "user.json"
}
}
}
In this example the json validation will pass but jsonchema validation should fail. If you know any library which can validate the jsonschema then let me know even I can update your plugin and send you a pull request.
By the way, I checked your profile and noticed that you work at Avast. I also work at Location Labs by Avast. Nice to meet you virtually
@rakeshcusat nice to meet you too! :-)
There is a schema syntax validation already implemented here https://github.com/daveclayton/json-schema-validator/blob/73e658d12ae660304206f8e951c9e01e1a144f11/src/main/java/com/github/fge/jsonschema/processors/syntax/SyntaxValidator.java so it should be no problem using it in this plugin. I'll try to do it today or tomorrow
@alenkacz thanks for looking into this. Another approach could be to use jsonSchema's schema file to validate schema files.
@alenkacz I just made a pull request (https://github.com/daveclayton/json-schema-validator/pull/218) against above mentioned library. This pull request may be useful for you.
@rakeshcusat cool, thanks :) I stole some small parts of your code and implemented it here https://github.com/alenkacz/gradle-json-validator/pull/3
it still needs some polishing but looks good from my point of view
@alenkacz Great.... I just provided proactive code review comments. Since your changes are already merged to main branch, I can use this plugin in my project.
Thank you for taking care of this on Weekend.
you can also close this issue.
One quick question, what should be the version number that I can use here.
classpath 'cz.alenkacz.gradle:json-validator:<FILL_VERSION_HERE>'
I noticed you have not released your project. I think it is good time to release the project that way we can also get a definite version number. This also facilitate development work on main branch without breaking other people.
@rakeshcusat sorry, was busy, will do it today in the afternoon
@rakeshcusat released 1.0.0 - please try it out
You can find newest version:
@alenkacz I figured out the version number already by the travis badge. Thanks for pointing out the other sources. :)
Should be able to validate multiple json schema file if directory path is provided in configuration. This way developer doesn't have to create multiple task for validating the different schema files.