-
-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: improve error source detection #685
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably dig in re the question you pose in the original PR description soon.
src/resolved.ts
Outdated
while ($ref in refMap) { | ||
$ref = refMap[$ref]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an odd looking piece of code, could you add a comment describing what this is for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just in general maybe this entire hasRef
logic tree (line 55-74) could be pulled out to its own function, with a comment describing what it does (or some descriptive tests)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From code perspective looks alright to me, but I didn't do any verification it fixes the original issue in a satisfactory way. @nulltoken if you have time, would be awesome if you could spin this PR branch up and do a quick verification that the changes here solve #658.
@@ -0,0 +1,66 @@ | |||
import { extractSourceFromRef, traverseObjUntilRef } from '..'; | |||
|
|||
describe('$ref utils', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These might be a good fit for the JSON package (where we already have a bunch of pointer helpers etc)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marbemac @P0lip Did a quick test. No more URIError warns! 🎉 REDACTED@XXXXX MINGW64 /c/_work/spectral (fix/uri-error)
$ git log -1
commit a1cf6c206eb3cd11c4bdcb680bc54a382f13e61d (HEAD -> fix/uri-error, upstream/fix/uri-error)
Author: Jakub Rożek <jakub@stoplight.io>
Date: Tue Dec 3 14:29:33 2019 +0100
fix: normalize source
REDACTED@XXXXX MINGW64 /c/_work/spectral (fix/uri-error)
$ yarn cli lint --ruleset ./repro/ruleset.yaml ./repro/URIError.yaml
yarn run v1.19.2
$ node -r ts-node/register -r tsconfig-paths/register src/cli/index.ts lint --ruleset ./repro/ruleset.yaml ./repro/URIError.yaml
Missing baseUrl in compilerOptions. tsconfig-paths will be skipped
Function 'oasOpSecurityDefined' could not be loaded: Not Found
Function 'oasPathParam' could not be loaded: Not Found
Function 'oasOp2xxResponse' could not be loaded: Not Found
Function 'oasOpFormDataConsumeCheck' could not be loaded: Not Found
Function 'oasOpIdUnique' could not be loaded: Not Found
Function 'oasOpParams' could not be loaded: Not Found
Function 'refSiblings' could not be loaded: Not Found
Function 'oasTagDefined' could not be loaded: Not Found
OpenAPI 3.x detected
c:/_work/spectral/repro/URIError.yaml
23:22 warning schema-strings-maxLength String typed properties MUST be further described using 'maxLength'. Error: paths./test.get.responses.200.content.application/json.schema.maxLength is not truthy
https://[REDACTED]]/static/schemas/common/v2/library.openapi.yaml
65:15 warning schema-strings-maxLength String typed properties MUST be further described using 'maxLength'. Error: components.schemas.Error.properties.error.maxLength is not truthy
65:15 warning schema-strings-maxLength String typed properties MUST be further described using 'maxLength'. Error: paths./test.get.responses.400.content.application/json.schema.properties.error.maxLength is not truthy
67:27 warning schema-strings-maxLength String typed properties MUST be further described using 'maxLength'. Error: components.schemas.Error.properties.error_description.maxLength is not truthy
67:27 warning schema-strings-maxLength String typed properties MUST be further described using 'maxLength'. Error: paths./test.get.responses.400.content.application/json.schema.properties.error_description.maxLength is not truthy
69:21 warning schema-strings-maxLength String typed properties MUST be further described using 'maxLength'. Error: components.schemas.Error.properties.status_code.maxLength is not truthy
69:21 warning schema-strings-maxLength String typed properties MUST be further described using 'maxLength'. Error: paths./test.get.responses.400.content.application/json.schema.properties.status_code.maxLength is not truthy
✖ 7 problems (0 errors, 7 warnings, 0 infos, 0 hints)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command. However, I'm on a bit on the fence regarding the reported errors....
Thoughts? |
Yeaaah, I guess we'd need to provide a json path relevant to that file.
It the referenced remote file contains issues, that error will still be reported, but for the file containing errors (the referenced one) Note, this change was partially driven by Studio where we show errors relevant to the current files and ignore errors coming from $refs. |
👍
I do agree.
That would also awesome. If that hint would be tied to some new built-in rule and that the user could change the severity of that rule, that would be even awesome-er ;-) |
cc @philsturgeon you may find the above convo quite interesting considering the Spectral VS Code plugin. |
Alright, so I'm working on the path issue. |
Not sure what the two files in question look like, but assuming the following:
I'd expect the resulting error report to look like:
Basically if we're reporting on another file, still reporting on inner paths relative to that file - in the example above it's the Does that make sense / is that what you were thinking? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming plan is to consider improvements to the path reporting stuff in a separate PR, this looks good to me 👍.
Fixes #658
Checklist
Does this PR introduce a breaking change?
Additional context
We need to figure #608 out as soon as possible.
Basically, we need to make a call whether or not to return validation results that cannot be associated with any document, as we do now.
If we happen to do so, we'll keep reporting duplicate errors under certain circumstances.