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

Update to version 5.0 from version 1.6 #586

Closed
harikakatkam opened this issue Aug 16, 2019 · 7 comments
Closed

Update to version 5.0 from version 1.6 #586

harikakatkam opened this issue Aug 16, 2019 · 7 comments

Comments

@harikakatkam
Copy link

harikakatkam commented Aug 16, 2019

Hi,

we have Version 1.6 implememted nearly 3 years ago, its working fine, now we wanted to upgrade to version 5.6, we are seeing issues when trying to resolve references ..we are always seeing no fragments found error

This is how we resolve in version 1.6

       $path = /path/to/schema.json
       $definitionsPath = /path/to/definitions
        $retriever = new UriRetriever();
        $schema = $retriever->retrieve('file://' . $path);
        $refResolver = new RefResolver($retriever);
        RefResolver::$maxDepth = 50;
        $refResolver->resolve($schema, 'file://' . $definitionsPath);

we couldn't find the alternate similar to RefResolver , using SchemaStorage is not resolving the references.

        $resolver = new UriResolver();
        $retriever = new UriRetriever();
        $urlSchema = $resolver->resolve('file://' . $path);
        $refResolver = new JsonSchemaStorage($retriever, $resolver);
        return $schema = $refResolver->resolveRef($urlSchema);

Any help would be much appreciated

Thanks,
Harika

@erayd
Copy link
Contributor

erayd commented Aug 16, 2019

References are resolved as they are needed, rather than a preprocessing step as your example shows. We don't provide a preprocessor that does this.

Can you expand a bit on what you are trying to achieve? You should never need to manually expand references.

@harikakatkam
Copy link
Author

Hi,

Many thanks for your reply.
We have a number of schemas, sharing same objects defined in definitions folder.
In the example below, offer object defined in common.json, is shared in foo.json and some other schemas too.
It would be great if you help us to find a solution to our situation, we are desperate to upgrade.
On other note, Is there release supporting draft-07 schema ?
$path => schemas/external/foo.json
$definitions => schemas/definitions/common.json

contents of common.json

{
  "title": "Common Object",
  "description": "My Common Object",
  "definitions": {
    "offer": {
         //elements of offer
           }
      }
}

contents of foo.json

{
  "$id": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "offer" : {
      "$ref": "common.json#/definitions/offer"
    }
  },
  "required": [
    "offer"
  ]
}

@erayd
Copy link
Contributor

erayd commented Aug 17, 2019

@harikakatkam Could you please clarify what the problem is? Cross-file references should work out of the box; you don't need to do anything special.

No, we do not yet have a release which supports draft-07.

@hkatkam-eagleeye
Copy link

Thanks @erayd for your help, could you please provide me with a snippet that validates schemas with this structure.

Cheers,
Harika

@erayd
Copy link
Contributor

erayd commented Aug 19, 2019

...could you please provide me with a snippet that validates schemas with this structure.

@hkatkam-eagleeye Your example above is fine. The only thing you need to change is the ref in foo.json; it needs to point to the file in the correct directory:

"$ref": "../definitions/common.json#/definitions/offer"

@erayd
Copy link
Contributor

erayd commented Aug 19, 2019

@hkatkam-eagleeye Here's an example PHP script:

<?php

require "vendor/autoload.php";

use JsonSchema\Constraints\Constraint;
use JsonSchema\Validator;

$schema = (object)['$ref' => 'file://' . realpath('./external/foo.json')];
$data = json_decode(file_get_contents('test.json'));

$validator = new Validator();
$validator->validate($data, $schema, Constraint::CHECK_MODE_EXCEPTIONS);

@DannyvdSluijs
Copy link
Collaborator

@harikakatkam / @hkatkam-eagleeye in an attempt to cleanup this repo we are trying to filter the issues and see which ones might be closed. Is it safe to assume this is a rather old issue, which sadly was left unanswered, and can be closed? Feel free to close it yourself with some comments if helpful.

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

4 participants