dto
dto copied to clipboard
Support for relative paths in JSON schemas
When using the $ref
keyword and pointing to a .json
file (e.g. a local file path), we should be able to specify relative file paths in a couple "expected" places.
E.g. in a PersonDto:
protected $schema = [
'$ref' => '../../person.json'
];
Or inside person.json
:
{
"type": "object",
"properties": {
"name": {"type": "string"},
"phone": {"$ref": "../partials/phone.json"}
}
}
In the first case, the $ref
should resolve relative to the location of the PersonDto.php
class. In the second, the ../partials/phone.json
should resolve relative to the location of the person.json
file.
Probably the code should be refactored to use the league/json-reference
package.
Hey @fireproofsocks , this sounds really (!) really handy.. How is the progress of this feature? Thanks a lot and all the best
It's a tricky feature because the package has attempted to simplify the representation of the definitions so that JSON or PHP can be interchangeable, but in reality it's hard to maintain that simplification. My last attempt at implementing this did not go so well...
Hey there, thanks a lot for the fast reply on this.. Wouldn't it be possible to just "recursive replace" the filepaths with the respective content in order to achieve the latter? All the best