thim81 / openapi-format

Format an OpenAPI document by ordering, formatting and filtering fields.
MIT License
77 stars 14 forks source link

1.15.4 fails to locate the filter file path when set #102

Closed greinerb closed 2 months ago

greinerb commented 4 months ago

With the latest version, 1.15.4, using the --filterFile parameter, it produces the following error. "Filter file error - no such file or directory" We have tried it both with the relative path and an absolute path to the file within our CI pipeline with the same results. The contents of our file (named filter.json) is the following and have verified that it exists and has the output below. stripFlags: ['x-internal'] We altered our CI pipeline to install the prior version (and not pull the latest) and that solves it currently. `npm install -g openapi-format@1.15.3

thim81 commented 4 months ago

@greinerb Thanks for reporting this. I have been reworking the file handling logic to make the the code more compact and easier to maintain and extend. Although there is a large test suite, it seems that something has slipped through.

I ll try to reproduce it and fix it as soon as possible.

thim81 commented 4 months ago

Would you mind sharing the command with the parameters that triggered the error? So I can reproduce it.

greinerb commented 4 months ago

Here is the command that is executed. openapi-format $file -o filtered/$file --filterFile filter.json; $file is the file that was changed in our repo that we are validating the change.

thim81 commented 4 months ago

hi @greinerb

I tried to reproduce it but i was unable to do so:

Example: openapi-format ../openapi.yml --output filtered.yaml --filterFile customFilter.json

output:

image

Which OS are you using?

can you increase the verbose output? This will output the underlying error.

Example: openapi-format ../openapi.yml --output filtered.yaml --filterFile customFilter.json --verbose 2

greinerb commented 4 months ago

We are using the docker image node:19.5-bullseye, that contains debian:11, 11.6.

Here is the output from the verbose command. SyntaxError: Unexpected token 's', "stripFlags"... is not valid JSON at JSON.parse (<anonymous>) at Object.parseFile (/usr/local/lib/node_modules/openapi-format/utils/file.js:30:14) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Command.run (/usr/local/lib/node_modules/openapi-format/bin/cli.js:105:33)

The contents of that file is the following. stripFlags: ['x-internal'] I have tried to remove the single quotes and still the same output. Did the requirements change for stripFlags?

thim81 commented 4 months ago

@greinerb The fileFile has a JSON extension?

Does the content looks like this like this JSON structure or YAML

{
  "stripFlags": [
    "x-internal"
  ]
}
stripFlags: ['x-internal']
greinerb commented 4 months ago

Is is as the 2nd even though the file extension is json. So does it require it to be in json format only if the file extension is json? I am going to run a few different tests with json format and different file extensions.

thim81 commented 4 months ago

We load the file content and parse it from json or yaml based on the file extension.

thim81 commented 4 months ago

@greinerb Did you get it to work by changing the extension to YAML or convert the content to JSON?

thim81 commented 2 months ago

@greinerb Going to close this item, since it should be solved when applying the correct extension.