1
0
Fork 0

Fix the handling of references in JSON schemas when validating

References must be resolved when loading the schema, otherwise they will fail
when using them.
The easiest way is actually to let the JsonSchema library load the file itself.
pull/6013/head
Christophe Coevoet 2016-12-29 17:16:06 +01:00
parent 40e6d19d73
commit 6daa2afdd3
3 changed files with 9 additions and 3 deletions

View File

@ -23,7 +23,7 @@
}, },
"require": { "require": {
"php": "^5.3.2 || ^7.0", "php": "^5.3.2 || ^7.0",
"justinrainbow/json-schema": "^1.6 || ^2.0 || ^3.0 || ^4.0", "justinrainbow/json-schema": "^3.0 || ^4.0",
"composer/ca-bundle": "^1.0", "composer/ca-bundle": "^1.0",
"composer/semver": "^1.0", "composer/semver": "^1.0",
"composer/spdx-licenses": "^1.0", "composer/spdx-licenses": "^1.0",

2
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "deb4df08cdd39eac7d11880586076ba1", "content-hash": "e18501d127e13e3619f80abbcf372c81",
"packages": [ "packages": [
{ {
"name": "composer/ca-bundle", "name": "composer/ca-bundle",

View File

@ -157,7 +157,13 @@ class JsonFile
} }
$schemaFile = __DIR__ . '/../../../res/composer-schema.json'; $schemaFile = __DIR__ . '/../../../res/composer-schema.json';
$schemaData = json_decode(file_get_contents($schemaFile));
// Prepend with file:// only when not using a special schema already (e.g. in the phar)
if (false === strpos($schemaFile, '://')) {
$schemaFile = 'file://' . $schemaFile;
}
$schemaData = (object) array('$ref' => $schemaFile);
if ($schema === self::LAX_SCHEMA) { if ($schema === self::LAX_SCHEMA) {
$schemaData->additionalProperties = true; $schemaData->additionalProperties = true;