ga4gh / gh-openapi-docs

Package for building OpenAPI schema docs and UI for gh-pages
Apache License 2.0
7 stars 5 forks source link

Remove "npx" from globally installed commands #61

Open jb-adams opened 3 years ago

jb-adams commented 3 years ago

Can we remove the npx at the beginning of the following commands, especially since the README states to install the two dependencies globally:

npx openapi bundle -f --output ${OPENAPI_JSON_PATH} ${config.apiSpecPath} npx openapi bundle -f --output ${OPENAPI_YAML_PATH} ${config.apiSpecPath} npx redoc-cli bundle --output ${indexPath} ${OPENAPI_YAML_PATH} ${redocOpts}

I am making a docker image of this app, and currently some of the steps are failing when the command is run with npx at the beginning.

command: npx openapi bundle -f --output openapi.yaml service-registry.yaml error:

npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /usr/src/repo/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/repo/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-10-28T14_44_20_262Z-debug.log

However when I just run: openapi bundle -f --output openapi.yaml service-registry.yaml the job completes successfully

tschaffter commented 3 years ago

The current README says to install this tool globally with npm install -g. The reason I shy away from this is because I usually look for solution that does not require the user to modify his/her global development environment.

Using npx solves this issues but has two drawbacks:

Proposed solution:

Rely on local install npm install + running ./node_modules/.bin/<command>

$ ./node_modules/.bin/openapi
Usage: openapi [options] [command]

Options:
  -v, --version                        Output current version of the OpenAPI CLI.
  -h, --help                           output usage information

Commands:
  bundle [options] [entryPoints...]    Create a bundle using <entryPoint> as a root document.
  validate [options] [entryPoints...]  Validate given OpenAPI 3 definition file.
  preview-docs [options] [entryPoint]  Preview API Reference docs for the specified entrypoint OAS definition

We could send the paths to the command in the config object with the default path set to ./node_modules/.bin/<command>. If the user want to use another version for some reason, he/she could overrides the paths in the config file.

tschaffter commented 3 years ago

I'm actually not sure how the above solution would work when gh-openapi-docs is installed from npmjs. The easy solution is to continue using npm install -g. Alternatively we could investigate on how to use openapi and redocly as libraries instead of running their executables.

jb-adams commented 3 years ago

Yeah, I'm good to leave this one as is. My above error was related to dependencies being incorrectly installed in the docker image, which I've since rectified.

As you mention, it'll be good once there's a library API for these packages that we can import rather than run on the command line, but last time I checked there was nothing available.

Feel free to close this issue