-
Notifications
You must be signed in to change notification settings - Fork 50
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
$ref and other properties in JSON Reference #136
Comments
Thanks for the suggested solution. This solution is simple and effective, but not applicable in my case. If I modify your example like this: ...
public function testPatchSchema()
{
$refProvider = new Preloaded();
$refProvider->setSchemaData(
'https://example.com/unixtimestamp-type.json',
json_decode(<<<'JSON'
{
"title": "UNIX Timestamp",
"description": "Number of seconds that have elapsed since the Unix epoch",
"type": "integer"
}
JSON
)
);
$schemaData = json_decode(<<<'JSON'
{
"properties": {
"atime": {
"title": "Access timestamp",
"description": "May not update if has been accessed recently",
"$ref":"https://example.com/unixtimestamp-type.json"
},
"mtime": {
"title": "Modification timestamp",
"$ref":"https://example.com/unixtimestamp-type.json"
},
"ctime": {
"title": "Change timestamp",
"$ref":"https://example.com/unixtimestamp-type.json"
}
}
}
JSON
);
... After: ...
$schema = Schema::import(...);
echo json_encode($schema, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); I would like the result to be: {
...
"properties": {
"atime": {
"title": "Access timestamp",
"description": "May not update if has been accessed recently",
"type": "integer"
},
"mtime": {
"title": "Modification timestamp",
"description": "Number of seconds that have elapsed since the Unix epoch",
"type": "integer"
},
"ctime": {
"title": "Change timestamp",
"description": "Number of seconds that have elapsed since the Unix epoch",
"type": "integer"
}
}
} (titles and descriptions have merged) So in {
"title": "Access timestamp",
"description": "May not update if has been accessed recently",
"$ref":"https://example.com/unixtimestamp-type.json"
} That way I can get the fields to be merged. I am aware of the limitations of a My case is specific of course. Now I use such constructions, but they are very cumbersome: ...
"properties": {
"atime": {
"title": "Access timestamp",
"description": "May not update if has been accessed recently",
"allOf": [{ "$ref": "https://example.com/unixtimestamp-type.json" }]
},
... |
Latest version of JSON schema spec allows keywords adjacent to Using Could you tell a bit more about your use case? What would you do with an instance of schema that has referenced value and titles/descriptions merged at top level? |
Is it possible in
getSchemaData
to get an JSON object, which contains a member named$ref
?I am aware of the limitations of a
JSON Reference
, but I need to do it in such a way that the properties with the value"my_value"
from the example override the own properties of the schema referenced by$ref
. To do this, ingetSchemaData
I need access to the object containing the$ref
, the rest is trivial.Any solution that works will do!
The text was updated successfully, but these errors were encountered: