-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
False error oas3-valid-schema-example reference resolves to more than one schema #2081
Comments
The error goes away if I globally change |
The error seems to be coming from
Note that |
@DavidBiesack Thanks for the work tracking this down. I ran into it independently in case another test case is useful: #2140 |
Is there any update on this issue? It's causing problems for me. |
I dropped in the same issue while using stoplight studio. I found ajv-validator/ajv#1426 which seems to deal with the same thing.
If this is true, then it appears to be a bug i stoplight studio. When validating the examples, only the schema relevant for the example should be provided to AJV but not the openapi schema, and also not all schemas within the openapi instance. the openapi schema says in https://swagger.io/specification/#example-object that "examples" can be |
Would be great to get this fixed - we have an API spec that has loads of these, it's super annoying |
a workaround is to use unique |
yes, we also managed to work around this as suggested, but just having to do that is plain silly |
Any chance we could get some attention on this issue? My team supports a spectral-based validator along with a ruleset that inherits the spectral:oas ruleset, and we've received reports of this problem with the oas3-valid-schema-example rule, along with reports of a similar issue in the oas3-valid-media-example rule as well. |
There might be some hope for this one yet... for the last couple of days, I've been studying the code related to the oas3-valid-schema-example & oas3-valid-media-example rules and trying to understand what's going on. I have a hunch that the
So with this in mind, and the fact that I really didn't have any other leads 😂, I modified the oasExample() rule function a bit so that it removes any "example" fields in the schema that it's going to pass into oasSchema() to do the actual schema validation of the example value. Surprisingly, that was enough to avoid the false errors. I figured the oasExample() function was the best place to do this, so that other invocations of oasSchema() are not subject to this example filtering. I still have more testing to do, but I'll try to get a PR opened up for this soon. |
This commit modifies the oasExample function so that example fields are removed from the schema to be used for validation. This is needed because the presence of an "example" field in a schema confuses ajv in certain scenarios. References: - stoplightio#2081 - stoplightio#2140 - ajv-validator/ajv#1426
@DavidBiesack I've opened a PR that fixes this issue in case you'd like to give it a try. |
This commit modifies the oasExample function so that example fields are removed from the schema to be used for validation. This is needed because the presence of an "example" field in a schema confuses ajv in certain scenarios. References: - stoplightio#2081 - stoplightio#2140 - ajv-validator/ajv#1426
Specifically needed to update 2 rules causing issues with examples: oas3-valid-media-example - causing issues in very weird circumstances with examples that shouldn't be failing. But in spectral? stoplightio/spectral#2081 Custom rule sps-ref-property-name - causing issues in indicating examples needed to use format.
This commit modifies the oasExample function so that example fields are removed from the schema to be used for validation. This is needed because the presence of an "example" field in a schema confuses ajv in certain scenarios. References: - stoplightio#2081 - stoplightio#2140 - ajv-validator/ajv#1426
Most of the issues here are due to ajv having a bug and interpreting `id: <uuid>` as schema id even when they're used in examples. See stoplightio/spectral#2081 Also, we seem to be mixing openapi 3.0.3 and 3.1.0 syntax for examples, which we should clean up at some point.
This commit modifies the oasExample function so that example fields are removed from the schema to be used for validation. This is needed because the presence of an "example" field in a schema confuses ajv in certain scenarios. References: - stoplightio#2081 - stoplightio#2140 - ajv-validator/ajv#1426
* fix(rulesets): avoid false errors from ajv This commit modifies the oasExample function so that example fields are removed from the schema to be used for validation. This is needed because the presence of an "example" field in a schema confuses ajv in certain scenarios. References: - #2081 - #2140 - ajv-validator/ajv#1426 * docs(repo): fix lint warning in README Signed-off-by: Phil Adams <[email protected]> * chore(rulesets): use traverse --------- Signed-off-by: Phil Adams <[email protected]> Co-authored-by: Jakub Rożek <[email protected]>
* fix(rulesets): avoid false errors from ajv This commit modifies the oasExample function so that example fields are removed from the schema to be used for validation. This is needed because the presence of an "example" field in a schema confuses ajv in certain scenarios. References: - #2081 - #2140 - ajv-validator/ajv#1426 * docs(repo): fix lint warning in README Signed-off-by: Phil Adams <[email protected]> * chore(rulesets): use traverse --------- Signed-off-by: Phil Adams <[email protected]> Co-authored-by: Jakub Rożek <[email protected]>
🎉 This issue has been resolved in version 1.18.1 🎉 The release is available on Your semantic-release bot 📦🚀 |
Describe the bug
Spectral is generating a strange error when a schema has a property with the name
id
.To Reproduce
and this
.spectral.yaml
3. Run this CLI command:
spectral lint -r ./.spectral.yaml openapi.yaml
4. See error
Expected behavior
There should be no error here.
Environment (remove any that are not applicable):
The text was updated successfully, but these errors were encountered: