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" );
72 $schemaPath = str_replace(
'\\',
'/', $schemaPath );
74 $validator =
new Validator;
75 $validator->check( $data, (
object)[
'$ref' =>
'file://' . $schemaPath ] );
76 if ( $validator->isValid() ) {
81 $out =
"$path did not pass validation.\n";
82 foreach ( $validator->getErrors() as $error ) {
83 $out .=
"[{$error['property']}] {$error['message']}\n";
85 throw new AbstractSchemaValidationError( $out );