65 $contents = file_get_contents(
$path );
66 $jsonParser =
new JsonParser();
68 $data = $jsonParser->parse( $contents, JsonParser::DETECT_KEY_CONFLICTS );
69 }
catch ( DuplicateKeyException $e ) {
71 }
catch ( ParsingException $e ) {
72 throw new AbstractSchemaValidationError(
"$path is not valid JSON", $e->getCode(), $e );
76 if ( is_array( $data ) ) {
77 $schemaPath = __DIR__ .
'/../../docs/abstract-schema.schema.json';
78 } elseif ( is_object( $data ) ) {
79 $schemaPath = __DIR__ .
'/../../docs/abstract-schema-changes.schema.json';
81 throw new AbstractSchemaValidationError(
"$path is not a supported JSON object" );
84 $validator =
new Validator;
85 $validator->check( $data, (
object)[
'$ref' =>
'file://' . $schemaPath ] );
86 if ( $validator->isValid() ) {
91 $out =
"$path did not pass validation.\n";
92 foreach ( $validator->getErrors() as $error ) {
93 $out .=
"[{$error['property']}] {$error['message']}\n";
95 throw new AbstractSchemaValidationError( $out );