From 0cef9623c51c9e04c2ca7f2c9697daa4e47becad Mon Sep 17 00:00:00 2001 From: Florian Schmidt Date: Mon, 15 Aug 2016 19:36:00 +0200 Subject: [PATCH] Upgrade justinrainbow/json-schema to ~3.0 The release between 1.6.1 and 3.0.0 has a huge amount of code maintenance changes, as well as internal optimization and some "visible" changes (as well as the one mentioned in the linked task). However, it's a version jump over 2 major versions, which is, by it's definition a major change ;). Nonetheless, the (for us) important api has changed marginally: Instead of using the JsonSchema\Uri\UriRetriever class to retrieve the schema, we now use the $ref keyword to reference the json schema file (which also is an internal optimization). In this way, we let the json-schema library decide, how to resolve a ref (and the schema) instead of relying on the UriRetriever api to be public and stable. The versions also include various bug fixes (which, as far as I know, doesn't apply to us). I tested this change with various combinations of valid and invalid extension.json schemas (version 2 as well as version 3). Given that there were no major changes to the schema interpretation itself, and the good test coverage of the library, there shouldn't be a high risk because of this change. The full list of changes can be found at: https://github.com/justinrainbow/json-schema/compare/1.6.1...3.0.0 as well as the changelogs of the single versions: https://github.com/justinrainbow/json-schema/releases Bug: T141281 Depends-On: I5687286da9f7fa2bb2b84699fa43ab3c2547fe03 Change-Id: Ie37e2ebc48684783abf8d99d2f775ee6a5988da7 --- composer.json | 2 +- maintenance/validateRegistrationFile.php | 9 +++------ tests/phpunit/structure/ExtensionJsonValidationTest.php | 6 ++---- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 9bd0fa1f07..c8ed37e997 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ }, "require-dev": { "jakub-onderka/php-parallel-lint": "0.9.2", - "justinrainbow/json-schema": "~1.6", + "justinrainbow/json-schema": "~3.0", "mediawiki/mediawiki-codesniffer": "0.7.2", "monolog/monolog": "~1.18.2", "nikic/php-parser": "1.4.1", diff --git a/maintenance/validateRegistrationFile.php b/maintenance/validateRegistrationFile.php index 9cf7b2bdc8..bd34a50eab 100644 --- a/maintenance/validateRegistrationFile.php +++ b/maintenance/validateRegistrationFile.php @@ -8,7 +8,7 @@ class ValidateRegistrationFile extends Maintenance { $this->addArg( 'path', 'Path to extension.json/skin.json file.', true ); } public function execute() { - if ( !class_exists( 'JsonSchema\Uri\UriRetriever' ) ) { + if ( !class_exists( 'JsonSchema\Validato' ) ) { $this->error( 'The JsonSchema library cannot be found, please install it through composer.', 1 ); } @@ -38,11 +38,8 @@ class ValidateRegistrationFile extends Maintenance { $this->output( "Warning: $path is using a deprecated schema, and should be updated to " . ExtensionRegistry::MANIFEST_VERSION . "\n" ); } - $retriever = new JsonSchema\Uri\UriRetriever(); - $schema = $retriever->retrieve( 'file://' . $schemaPath ); - - $validator = new JsonSchema\Validator(); - $validator->check( $data, $schema ); + $validator = new JsonSchema\Validator; + $validator->check( $data, (object) [ '$ref' => 'file://' . $schemaPath ] ); if ( $validator->isValid() ) { $this->output( "$path validates against the version $version schema!\n" ); } else { diff --git a/tests/phpunit/structure/ExtensionJsonValidationTest.php b/tests/phpunit/structure/ExtensionJsonValidationTest.php index 275c0d1794..711eab647e 100644 --- a/tests/phpunit/structure/ExtensionJsonValidationTest.php +++ b/tests/phpunit/structure/ExtensionJsonValidationTest.php @@ -74,11 +74,9 @@ class ExtensionJsonValidationTest extends PHPUnit_Framework_TestCase { $version <= ExtensionRegistry::MANIFEST_VERSION, "$path is using a non-supported schema version" ); - $retriever = new JsonSchema\Uri\UriRetriever(); - $schema = $retriever->retrieve( 'file://' . $schemaPath ); - $validator = new JsonSchema\Validator(); - $validator->check( $data, $schema ); + $validator = new JsonSchema\Validator; + $validator->check( $data, (object) [ '$ref' => 'file://' . $schemaPath ] ); if ( $validator->isValid() ) { // All good. $this->assertTrue( true ); -- 2.20.1