Skip to content
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

feat: validate x-sdk-operations extension #290

Merged
merged 1 commit into from
May 5, 2021

Conversation

barrett-schonefeld
Copy link
Contributor

@barrett-schonefeld barrett-schonefeld commented Apr 29, 2021

Description:

  • This PR uses a provided Spectral function to do JSON Schema validation. This is a positive because it is a well-defined way to invoke the AJV validator.
  • The one drawback is that we need to dynamically convert the relative path to an absolute path before loading the default config into STATIC_ASSETS because we need to ensure Spectral can always find the schema regardless of the current working directory.
  • The Spectral schema function has the same problem we observed (in Spectral 5.8.1 and below) in the oas3-schema rule where only one error is returned at a time. We will want to follow up on this implementation by raising this issue to Spectral and fixing the schema function.

Purpose:

  • Validate that the x-sdk-operations extension is used correctly.

Changes:

  • Load the absolute path to the JSON Schema into static assets, so when the ibm:oas ruleset is extended, still able to find the JSON Schema
  • Replace relative references to ./schema in .defaultsforspectral.yaml with their absolute path using regex replace

Tests:

  • Ensure ibm-sdk-operations rule catches errors

Docs:

  • Document the ibm-sdk-operations rule

@codecov
Copy link

codecov bot commented Apr 29, 2021

Codecov Report

Merging #290 (2f73cd2) into main (ba00a8d) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 2f73cd2 differs from pull request most recent head 11ddb36. Consider uploading reports for the commit 11ddb36 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##             main     #290   +/-   ##
=======================================
  Coverage   92.00%   92.00%           
=======================================
  Files          73       73           
  Lines        2376     2377    +1     
  Branches      605      605           
=======================================
+ Hits         2186     2187    +1     
  Misses        157      157           
  Partials       33       33           
Impacted Files Coverage Δ
src/spectral/utils/spectral-validator.js 98.21% <100.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 83c8993...11ddb36. Read the comment docs.

Copy link
Contributor

@mkistler mkistler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the doc changes are a bit messed up.

And I had an idea about using regex replace to update the paths.

docs/spectral-rules.md Outdated Show resolved Hide resolved
src/spectral/utils/spectral-validator.js Outdated Show resolved Hide resolved
@barrett-schonefeld barrett-schonefeld force-pushed the better-fix-extends-problem branch 2 times, most recently from 2b3e44a to 3d11414 Compare May 1, 2021 01:46
Purpose:
- Validate that the x-sdk-operations extension is used correctly.

Changes:
- Load the absolute path to the JSON Schema into static assets, so when the `ibm:oas` ruleset is extended, still able to find the JSON Schema

Tests:
- Ensure `ibm-sdk-operations` rule catches errors

Docs:
- Document the `ibm-sdk-operations` rule
Copy link
Contributor

@mkistler mkistler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

Copy link
Member

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@barrett-schonefeld barrett-schonefeld merged commit 019c06f into main May 5, 2021
@barrett-schonefeld barrett-schonefeld deleted the better-fix-extends-problem branch May 5, 2021 15:21
ibm-devx-sdk pushed a commit that referenced this pull request May 5, 2021
# [0.46.0](v0.45.0...v0.46.0) (2021-05-05)

### Features

* validate `x-sdk-operations` extension ([#290](#290)) ([019c06f](019c06f))
@ibm-devx-sdk
Copy link

🎉 This PR is included in version 0.46.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants