-
Notifications
You must be signed in to change notification settings - Fork 356
Fix RefResolver and make it compatible with draft-04 #240
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
Comments
This would be much appreciated. We tried to add swagger json schema validation do our pipeline in PHP using this library but ultimately failed because of the draft-04 requirement. |
OK, then I will try to speed things up. |
Trying to get it also working with older PHP versions (I'm using PHP 5.6.14) and make sure the travis build: https://travis-ci.org/jojo1981/json-schema will be OK before creating a PR. So for now it's still work in progress. |
@mfn please join the review. |
@jojo1981 please go ahead and open a PR for your work. I basically agree that the public can decide. |
Derp... nvm: #245 |
Revert .gitignore file.
@jojo1981 I tried but embarrassingly I actually don't know how to do it. Maybe I'm wrong here, but I've this setup:
I know how to valdiate a single json file against a single schema, but I'm stuck how to actually use the API to have them use both. The swagger schema is built on top of the json schema (referencing things like Here's a sample code I'm using for "one schema, one json" to validate (in that case it's about the "jsonapi schema" which works fine). Sorry to ask for such support here but I feel like I'm missing something ... <?php
$data = new stdClass(); // assume some actual data I want to validate
$schemaFile = base_path('docs/jsonapi/jsonapi-schema-1.0.json');
$schema = json_decode(file_get_contents($schemaFile));
$refResolver = new RefResolver();
# Minimum depth required to work with jsonapi schema
$refResolver::$maxDepth = 11;
$refResolver->resolve($schema);
$validator = new Validator();
$validator->check($data, $schema);
if (!$validator->isValid()) {
$msg = "Invalid jsonapi reponse:\n";
foreach ($validator->getErrors() as $error) {
$msg .= ' path "' . $error['property'] . '" -> ' . $error['message'] . "\n";
}
} |
@mfn I don't understand which problem you have? |
I've two schema files -> what's the API usage to validate a json with them? |
@mfn the whole idea is to validate data against one schema, but that schema can have references to other schemas. Please check the documentation at: http://spacetelescope.github.io/understanding-json-schema/reference/combining.html |
- Removed dead code. - Throw exception in case a fragment part of the JSON Pointer can not be resolved - Add extra test which test the exception (now the RefResolver has 100% code coverage).
- Removed the stupid left over debug code
#240 Fix RefResolver and make it compatible with draft-04
PR is merged so I will close this issue. |
The current implementation of the RefResolver can only handle JSON schema definitions which result in a tree and not a graph and only to a certain depth.
The RefResolver needs to be replaced or fixed so it can handle JSON schema definitions which contains cycles.
I'm still working on a solution for the RefResolver and I'm almost done. When I've added some regression tests I will submit my code and create a pull request.
The text was updated successfully, but these errors were encountered: