dto icon indicating copy to clipboard operation
dto copied to clipboard

Support for relative paths in JSON schemas

Open fireproofsocks opened this issue 7 years ago • 3 comments

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.

fireproofsocks avatar Mar 10 '17 23:03 fireproofsocks

Hey @fireproofsocks , this sounds really (!) really handy.. How is the progress of this feature? Thanks a lot and all the best

johannesschobel avatar Oct 15 '18 13:10 johannesschobel

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...

fireproofsocks avatar Oct 15 '18 23:10 fireproofsocks

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

johannesschobel avatar Oct 16 '18 06:10 johannesschobel