85 $contents = file_get_contents(
$path );
86 $jsonParser =
new JsonParser();
88 $data = $jsonParser->parse( $contents, JsonParser::DETECT_KEY_CONFLICTS );
89 }
catch ( DuplicateKeyException $e ) {
91 }
catch ( ParsingException $e ) {
92 throw new AbstractSchemaValidationError(
"$path is not valid JSON", $e->getCode(), $e );
96 if ( is_array( $data ) ) {
97 $schemaPath = __DIR__ .
'/../../docs/abstract-schema.schema.json';
98 } elseif ( is_object( $data ) ) {
99 $schemaPath = __DIR__ .
'/../../docs/abstract-schema-changes.schema.json';
101 throw new AbstractSchemaValidationError(
"$path is not a supported JSON object" );
104 $validator =
new Validator;
105 $validator->check( $data, (
object)[
'$ref' =>
'file://' . $schemaPath ] );
106 if ( $validator->isValid() ) {
111 $out =
"$path did not pass validation.\n";
112 foreach ( $validator->getErrors() as $error ) {
113 $out .=
"[{$error['property']}] {$error['message']}\n";
115 throw new AbstractSchemaValidationError( $out );