Skip to content

Add support for relative '../' paths and ignore commented !includes#2

Open
Jbelmonte wants to merge 2 commits intomikestowe:masterfrom
Jbelmonte:master
Open

Add support for relative '../' paths and ignore commented !includes#2
Jbelmonte wants to merge 2 commits intomikestowe:masterfrom
Jbelmonte:master

Conversation

@Jbelmonte
Copy link

Hi there!

First of all, thank you for your merge solution! I needed that to import RAML into Postman.
Secondly I must say I am not a PHP developer, so please forgive any bad use of PHP.

This pull request contains the following changes/improvements:

  • Add support to local file paths referencing parent folders.
    • I have a complex RAML specification where I refer to yaml in nested folders and them refer to parent folders.
      Bellow you'll find an example.
  • Refactor code so it handles files line by line:
    • It eases ignoring commented (#) !include lines. Includes were processed anyway, causing syntax errors as the first line remained commented.
    • Handle !include in all available situations: traits, securitySchemes, resourceTypes and so on.
  • Remove extra \n on each line.

File structure

~/api/api.raml
  |- /resources
  |      |- ...
  |- /yaml
  |      |- /traits.yaml
  |      |- ...
  |- /yaml-core
  |      |- /traits/trait.localizable.yaml
  |      |- ...

Cross references

# Fragment of `api.raml`
traits: !include yaml/traits.yaml
# Fragment of `/yaml/traits.yaml`
- !include ../yaml-core/traits/trait.localizable.yaml
# Fragment of `/yaml-core/traits/trait.localizable.yaml`
localizable:
    headers:
      Accept-Language:
        description: Language code.
        example: es

The problem

$  php ramlMerge.php api.raml
[...]
# Unable to Include ~/api/../yaml-core/traits/trait.localizable.yaml
[...]

The folder containing referenced file ../yaml-core/traits/trait.localizable.yaml had to be computed based on current file being included (/yaml/traits.yaml).

Of course, that complex specification was valid according to RAML parsers used by RAML designer and RAML console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant