fireproofsocks / dto

Data Transfer Object (DTO) in PHP using JSON Schema
77 stars 12 forks source link

Support for relative paths in JSON schemas #9

Open fireproofsocks opened 7 years ago

fireproofsocks commented 7 years ago

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.

johannesschobel commented 6 years ago

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

fireproofsocks commented 6 years ago

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

johannesschobel commented 6 years ago

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