redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Issue with path resolving in the configuration file

Open IgorKarpiuk opened this issue 8 months ago • 2 comments

Describe the bug

If using the --config option to specify the path to a configuration file, an issue occurs when the specified config file is located at a different directory level compared to the command execution directory. In such cases, path resolution works incorrectly

To Reproduce

  1. File Tree structure:
  ├── folder1
  │   ├── subfolder
  │   │   └── redocly.yaml  
  ├── folder2
  │   ├── openapi.yaml
  1. redocly.yaml file
apis:
  main:
    root: ../../folder2/openapi.yaml

extends:
  - recommended
  1. Run command:
redocly lint main --config folder1/subfolder/redocly.yaml
  1. See error

    ../../folder2/openapi.yaml does not exist or is invalid.

Expected behavior

Should correctly resolve paths

Logs

Screenshot 2023-12-08 at 11 15 28

Redocly Version(s)

1.5.0

Node.js Version(s)

20.4.0

Additional context

Paths from the config file are resolved relative to the location where the command is run, but should be relative to the location of the config file

IgorKarpiuk avatar Dec 08 '23 09:12 IgorKarpiuk

isn't path always resolving in the context of where the command is executed? I use this quite a bit and always use a relative path to the pwd

jeremyfiel avatar Dec 08 '23 21:12 jeremyfiel

This behaviour also caught me by surprise.

With contracts/v1.yaml and contracts/v2.yaml, and the config contracts/redocly.yaml:

apis:
  my-api@v1:
    root: ./v1.yaml
  my-api@v2:
    root: ./v2.yaml

I can bundle successfully with these commands:

cd contracts
redocly lint

I then also expected this to work, and resolve the ./v1.yaml and ./v2.yaml files reltive to the config file:

cd ..
redocly lint --config contracts/redocly.yaml

Instead I get these errors:

v1.yaml does not exist or is invalid.


v2.yaml does not exist or is invalid.

Please provide a valid path.

tore-hammervoll avatar Dec 11 '23 19:12 tore-hammervoll