52 $contents = file_get_contents(
$path );
53 $jsonParser =
new JsonParser();
55 $data = $jsonParser->parse( $contents, JsonParser::DETECT_KEY_CONFLICTS );
56 }
catch ( DuplicateKeyException $e ) {
58 }
catch ( ParsingException $e ) {
59 throw new AbstractSchemaValidationError(
"$path is not valid JSON", $e->getCode(), $e );
63 if ( is_array( $data ) ) {
64 $schemaPath = __DIR__ .
'/../../docs/abstract-schema.schema.json';
65 } elseif ( is_object( $data ) ) {
66 $schemaPath = __DIR__ .
'/../../docs/abstract-schema-changes.schema.json';
68 throw new AbstractSchemaValidationError(
"$path is not a supported JSON object" );
71 $validator =
new Validator;
72 $validator->check( $data, (
object)[
'$ref' =>
'file://' . $schemaPath ] );
73 if ( $validator->isValid() ) {
78 $out =
"$path did not pass validation.\n";
79 foreach ( $validator->getErrors() as $error ) {
80 $out .=
"[{$error['property']}] {$error['message']}\n";
82 throw new AbstractSchemaValidationError( $out );