raml-org / raml-php-parser

Community-maintained RAML parser for php
https://packagist.org/packages/raml-org/raml-php-parser
MIT License
200 stars 77 forks source link

Fix to how schema parsers are fed source URI. #89

Closed pies closed 8 years ago

pies commented 8 years ago

This one took a bit of work.

RAML !include'd schemas are resolved simply by replacing their contents with contents of referenced files. JSON-Schema references, however are resolved by separate parsers which can rely on relative paths. For example, a RAML file may refer to foo/bar.json which in turn contains a reference to ../baz.json. foo/bar.json needs no know that it's working from foo/ to know what to resolve ../baz.json into.

The problem arises, however, when !included RAML files refer via to relative paths to JSON-Schema files that refer to relative paths. The JSON-Schema loader is being fed the directory the main RAML file was included from, instead of the path of the included RAML file the JSON schema is being referenced from.

This path fixes it in a somewhat crude way. I don't see a better way to do it without re-engineering how RAML references are resolved.

pies commented 8 years ago

If you'd like to re-create the issue here's the directory structure:

item/item.raml
item/item.json
shared/shared.json
api.raml

Make it so that:

alecsammon commented 8 years ago

Hi Michał,

This is great - thank you. Are you able to write unit tests for it? Helps me to validate the change, and also prevents regressions in the future.

pies commented 8 years ago

@alecsammon Here you go :)