stoplightio / spectral

A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI (v3.1, v3.0, and v2.0), Arazzo v1.0, as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.46k stars 233 forks source link

fix(rulesets): avoid false errors from ajv #2408

Closed padamstx closed 1 year ago

padamstx commented 1 year ago

Fixes #2081.

Checklist

Does this PR introduce a breaking change?

Screenshots

If applicable, add screenshots or gifs to help demonstrate the changes. If not applicable, remove this screenshots section before creating the PR.

Additional context

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:

padamstx commented 1 year ago

This PR supercedes this PR.

padamstx commented 1 year ago

Hi, would it be possible for someone to review and possibly merge this PR? This issue seems to be a common problem for folks that use spectral to validate openapi documents.

mnaumanali94 commented 1 year ago

@padamstx thank you for the PR. The team is a bit busy with some other feature development. We'll be going through this and replying in a couple of weeks.

padamstx commented 1 year ago

@mnaumanali94 Please don't forget about this PR :)

ndreno commented 1 year ago

Hi there, any news? We have the same issue

padamstx commented 1 year ago

@mnaumanali94, sorry to be a pest about this one, but I was wondering if you have an updated ETA when this PR might be reviewed. Here at IBM, we have a validator (https://github.com/IBM/openapi-validator) that is dependent on Spectral, including a custom ruleset that inherits from Spectral's oas ruleset, so our users are running into this issue. Depending on when this PR might be able to be reviewed/merged, we might need to solve the issue by replacing the oas3-valid-schema-example rule with our own version that includes the fixed oasExample function. Thanks!

padamstx commented 1 year ago

@P0lip Thank you for merging. I'll keep an eye out for a new spectral release so that we can move our validator project up to the latest.

P0lip commented 1 year ago

@padamstx the new version of the @stoplight/spectral-rulesets is already out :) You can bump it

padamstx commented 1 year ago

@P0lip excellent, that was quick!