Open DimitrisKaramanis opened 4 months ago
@lobocv would you like to take a stab at this, as it's your feature?
Running it with some debug prints I see that the path on the error is sometimes different than the one you are ignoring:
On the run with 6 errors (ignoring is failing) I get the following path
$.paths['/v1/repo'].post.requestBody.content['application/json;charset=UTF-8'].schema.properties['name'].minLength
When it does work (5 errors, 1 ignored) I see the path is:
$.components.schemas['CreateRepository'].properties['name'].minLength
Seems like a bug in the code that generates the path? Looking at the openapi.yaml, it looks like the first one is the real path.
@daveshanley do you know what could be going wrong here?
EDIT: Ah I see. It looks like in one case, the $ref is being resolved and in the other case it's not. Looks like the linting behaviour is not consistent in it's output.
@DimitrisKaramanis can you recreate this issue on the latest release of vacuum? @daveshanley has made some fixes to how paths are generated in the linting output and it may have resolved this issue. If so, feel free to close the ticket. Thanks!
I was able to recreate this issue on v0.13.1 đŸ˜¢
This is my rule which checks that all paths start with a version
url-starts-with-major-version: description: Major version must be the first URL component message: All paths must start with a version number, eg /v1, /v2 given: $.paths[*]~ severity: error type: style then: function: pattern functionOptions: match: "$/v[0-9]+/"
About 1/4 times I run the lint I get a failure. When it fails, it matches on some object in the path rather than the path key: For example:
$.paths['/memberAppComponents'].post.responses
is what vacuum says the path is that is failing
but it should be
$.paths['/memberAppComponents']
And it is, most of the time (and then the tests pass because I have that ignored)
I was debugging this and it looks to be coming from this line.
It assumes the thing you are matching is an object. For my rule, I am matching against the path keys with $.paths[*]~
Edit: Maybe it's fine, the node that is matched has a Value of the path key but for some reason GenerateJSONPath()
is sometimes generating the path to a field inside the path object. Other time it returns the path.
I'm having a hard time figuring it out. Seems like it depends on some other state in the Foundation{}
Not sure what the solution would be here @daveshanley but i'm happy to contribute to a fix.
Okay I think I've nailed this down the the source. It seems to be an issue in the doctor building a mapping of line number to node objects here.
There is a race condition that happens here when using $ref
.
The line numbers of the processed nodes are relative to the yaml file the object is defined, not relative to the overall document. In my case, I have each path in a separate yaml file. What happens is that all the objects from a particular path (path items, reponses, operations etc) get assigned to the same line number. Only the first node gets used.
Since this happens asynchronously, there is a race condition where the first node is the right one and the path reported by vacuum is correct. But in other cases, one of the nodes from deeper within the $ref is used and is assigned the line number of the $ref.
I hope I am explaining this correctly. Unfortunately I don't know the solution. The lineObjects
needs to account for the line numbers injected by the $ref.
I will see if I can recreate this as a test in the doctor
I am in version 0.11.1 and I am trying to use
vacuum lint
with the--ignore-file
argument.When I lint the yaml file with the ignoring, sometimes I get 5 errors (5 valid ones and 1 ignored), but some other times I get 6 errors (none of them gets ignored). I am executing it one time after the other without changing anything, so there is no difference between the two executions. Also, I tried to do the same things with a smaller OpenAPI file (13 lines), but then it was working perfectly.
And I couldn't find any 'sequence` of how often I get the right and the wrong result. It seems random to me.
Below you can find both my demo OpenAPI file and the ignore file that I use.
OpenAPI file:
Ignore file: