function SchemaStorage::addSchema
Overrides SchemaStorageInterface::addSchema
1 call to SchemaStorage::addSchema()
- SchemaStorage::getSchema in vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ SchemaStorage.php - Returns schema for given identifier, or null if it does not exist
File
-
vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ SchemaStorage.php, line 46
Class
Namespace
JsonSchemaCode
public function addSchema($id, $schema = null) {
if (is_null($schema) && $id !== self::INTERNAL_PROVIDED_SCHEMA_URI) {
// if the schema was user-provided to Validator and is still null, then assume this is
// what the user intended, as there's no way for us to retrieve anything else. User-supplied
// schemas do not have an associated URI when passed via Validator::validate().
$schema = $this->uriRetriever
->retrieve($id);
}
// cast array schemas to object
if (is_array($schema)) {
$schema = BaseConstraint::arrayToObjectRecursive($schema);
}
// workaround for bug in draft-03 & draft-04 meta-schemas (id & $ref defined with incorrect format)
// see https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/177#issuecomment-293051367
if (is_object($schema) && property_exists($schema, 'id')) {
if ($schema->id == 'http://json-schema.org/draft-04/schema#') {
$schema->properties->id->format = 'uri-reference';
}
elseif ($schema->id == 'http://json-schema.org/draft-03/schema#') {
$schema->properties->id->format = 'uri-reference';
$schema->properties->{'$ref'}->format = 'uri-reference';
}
}
// resolve references
$this->expandRefs($schema, $id);
$this->schemas[$id] = $schema;
}