opis / json-schema

JSON Schema validator for PHP
https://opis.io/json-schema
Apache License 2.0
567 stars 58 forks source link

ID passed to SchemaLoader::loadObjectSchema() should take precedence over `$id` in schema data #106

Open bradjones1 opened 2 years ago

bradjones1 commented 2 years ago

Sometimes schema files have more specific $ids than their well-known/canonical URLs. E.g.,

https://jsonapi.org/schema vs. https://jsonapi.org/schemas/spec/v1.0/draft

I may be using a local file with that more specific/versioned $id, but other schemas will reference the canonical version. If I choose to explicitly set the ID in ::loadObjectSchema(), we should use that. Except, it's overridden at https://github.com/opis/json-schema/blob/c48df6d7089a45f01e1c82432348f2d5976f9bfb/src/Parsers/SchemaParser.php#L346-L349