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

Getting schema not found exception even though the URL is valid #114

Open
matronator opened this issue Sep 10, 2022 · 2 comments
Open

Getting schema not found exception even though the URL is valid #114

matronator opened this issue Sep 10, 2022 · 2 comments

Comments

@matronator
Copy link

I have this piece of code:

$validator = new Validator();
$schema = 'https://files.matronator.com/public/mtrgen/1.0.2/mtrgen-template-schema.json';
$result = $validator->validate($parsed, $schema);

return $result->isValid();

And it throws schema not found exception. What am I doing wrong?

@franckweb
Copy link

franckweb commented Oct 19, 2022

Try decoding the contents of your json schema:

$schema = json_decode(file_get_contents("https://domain.name/your-schema.json"));

or even better, try registering your $id to a file path:

$validator = new Opis\JsonSchema\Validator();
$validator->resolver()->registerFile(
    'file:definitions/myschema.json', 
    '/path/to/file/myschema.json'
);

and use that $id string to pass it as $schema

$data = json_decode('{"your: "data"}');
$schema = 'file:definitions/myschema.json';
$result = $validator->validate($data, $schema);

@matronator
Copy link
Author

Yeah, I managed to get it working with the file_get_contents, but I was under the impression that the $schema parameter can also be a URL pointing to a schema online.

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

2 participants