Skip to content

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

Closed
jojo1981 opened this issue Mar 16, 2016 · 11 comments
Closed

Fix RefResolver and make it compatible with draft-04 #240

jojo1981 opened this issue Mar 16, 2016 · 11 comments

Comments

@jojo1981
Copy link

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.

@mfn
Copy link

mfn commented Mar 22, 2016

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.

@jojo1981
Copy link
Author

OK, then I will try to speed things up.

jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 22, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 22, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 22, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 22, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 22, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 22, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 22, 2016
@jojo1981
Copy link
Author

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.

@jojo1981
Copy link
Author

@mfn please join the review.

@bighappyface
Copy link
Collaborator

@jojo1981 please go ahead and open a PR for your work. I basically agree that the public can decide.

@bighappyface
Copy link
Collaborator

Derp... nvm: #245

jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 23, 2016
@mfn
Copy link

mfn commented Mar 24, 2016

@mfn please join the review.

@jojo1981 I tried but embarrassingly I actually don't know how to do it. Maybe I'm wrong here, but I've this setup:

  • downloaded json draft 04 schema
  • downloaded swagger schema
  • and then I've my own swagger.json

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 positiveInteger, etc.).

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";
    }
}

jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 26, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 26, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 28, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 28, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 28, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 28, 2016
@jojo1981
Copy link
Author

@mfn I don't understand which problem you have?

@mfn
Copy link

mfn commented Mar 29, 2016

I've two schema files -> what's the API usage to validate a json with them?

@jojo1981
Copy link
Author

@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

jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Mar 31, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Apr 1, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Apr 2, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Apr 4, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Apr 6, 2016
- 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).
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Apr 12, 2016
jojo1981 pushed a commit to jojo1981/json-schema that referenced this issue Apr 13, 2016
bighappyface added a commit that referenced this issue Apr 14, 2016
#240 Fix RefResolver and make it compatible with draft-04
@jojo1981
Copy link
Author

PR is merged so I will close this issue.

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

3 participants