-
Notifications
You must be signed in to change notification settings - Fork 52
Any way to get meta by SchemaPointer? #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@gigi please see the attached commit for failed schema resolution example:
Hope it is helpful, error inspection is also discussed in #55 and json-schema-org/json-schema-spec#643. With JSON Schema draft-08 out error inspection in this library will likely need some revamping. |
Not working at all. $file = __DIR__ . '/../../../vendor/development-contract/mylib/user-profile.json';
$str = '{"user":{"id":"111","is_dev":true}, ... other data}'; // my data
$schema = Schema::import($file);
try {
$schema->in((object)json_decode($str));
} catch (Exception $e) {
$data = json_decode(file_get_contents($file));
$pointer = $e->getSchemaPointer(); // /srv/www/namespace/module/test/Unit/Validator/../../..//vendor/development-contract/mylib/user-server-event.json/allOf/1/properties/field_data/properties/email
// Different errors depending on exception:
// Swaggest\JsonDiff\Exception : Key not found: srv
// Swaggest\JsonDiff\Exception : Path must start with "/": ./user-event.json if there is ref to another schema
// etc
$meta = JsonPointer::getByPointer($data, $pointer);
} I have to make a lot of string manipulations in order to get cause field private function isRequired($schema, $schemaPointer, $dataPointer)
{
$path = str_replace($schema->getFromRefs()[0], '', $schemaPointer);
$pathItems = array_slice(JsonPointer::splitPath($path), 0);
array_splice($pathItems, -2);
$pathItems[] = 'required';
// FIXME to much json operations
$items = JsonPointer::get(json_decode(json_encode($schema), true), $pathItems);
$lastSegment = substr($dataPointer, strrpos($dataPointer, '/') + 1);
return in_array($lastSegment, $items, true);
} |
@gigi please check v0.12.9. There is now https://github.com/swaggest/php-json-schema/blob/v0.12.9/tests/src/PHPUnit/Error/ErrorTest.php#L193 |
Reason I'm asking is I'm looking for a way of getting a Sub-Schema from only 2 parts: root Schema object and DocumentPath string, specifically one that works with https $ref resolution. |
Hi!
Is it possible to get metadata of field by
InvalidValue
exception?For example I want to know if failed field marked as required in the schema.
Thanx!
The text was updated successfully, but these errors were encountered: