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

Update Spectral to latest release #3179

Merged
merged 3 commits into from
Jun 30, 2021
Merged

Update Spectral to latest release #3179

merged 3 commits into from
Jun 30, 2021

Conversation

rossmcdonald
Copy link
Contributor

This PR:

  • Updates and standardizes all Spectral references to the latest v5.9.0 release. Previously different packages were using different versions of the library.
  • Corrects the call structure when using Spectral, which looks like it wasn't being used properly in the insomnia-app package.
  • Restricts run results to errors only (as opposed to warnings, which are more style-related).
  • Updates the sample API spec test fixtures to make them syntactically correct.

To demonstrate the change to the designer itself, before this change (running 2021.01.0):

Screen Shot 2021-03-11 at 9 10 41 AM

Note the lack of validations. And then after this change:

image

Validations are now being reported properly based on the contents of the specification. This will help provide immediate feedback to the user as they build out their specifications, and improve the overall value-add of the Insomnia Design view.

Feel free to ping me on company Slack to review.

@rossmcdonald
Copy link
Contributor Author

Let me know if I should un-stage the package-lock files, or what the best way to handle that is. It looks like I may be using a newer version of npm, so I'm happy to adjust as needed.

@reynolek reynolek removed the request for review from develohpanda March 11, 2021 17:22
@nijikokun
Copy link
Contributor

Thank you for the submission @rossmcdonald, this is definitely an improvement, the team is currently heads down trying to get out an update for Electron at the moment, once that's done we will circle back with reviews. 🙏

@rossmcdonald
Copy link
Contributor Author

Sounds great, @nijikokun! Don't hesitate to reach out should any questions come up.

@dimitropoulos
Copy link
Contributor

Just wanna say I'm really excited about this PR. Spectral (being old) caused LOTS of trouble for another PR I'm working on. Thank you so much. I anticipated getting to this as soon as possible (which, haha, to be clear, will be a few days, and maybe even a week or two) because we need it for other reasons.

@rossmcdonald
Copy link
Contributor Author

Glad to hear it @dimitropoulos! This will be a win for us on the sales side as well. I'm also the original author of Spectral, so feel free to reach out anytime if you have any questions.

@dimitropoulos
Copy link
Contributor

oh sweet. I have a bat-phone now! mainly the issues were, by the way, with us upgrading to get the typescript types (I'm converting all of insomnia to typescript) and there was some issue with the bundling (jsonc-parser includes a file called ./impl/format that throws from webpack)

Screenshot_20210318_083816

I think we're sorta-kinda past it (we ended up just downgrading webpack) but there were other problems that came from decimal, I believe it was. We also get lots of errors similar to what caused this PR to be raised stoplightio/spectral#1458.

All the same, I'll keep at it and let you know. Definitely a big fan of the tool. I made something similar (now privately held by a prior employer) a few years ago for parsing yaml using the haskell reference parser.

@dimitropoulos
Copy link
Contributor

I rebased this. @develohpanda please take a look

@dimitropoulos
Copy link
Contributor

(rebased again). hey @rossmcdonald next time would you mind committing on a different branch than develop? no biggie, but just would make things a easier for us.

@rossmcdonald
Copy link
Contributor Author

@dimitropoulos Yep, sorry about that. Let me know if you need me to re-open this one from a different branch if it's causing issues.

@dimitropoulos
Copy link
Contributor

nah, no biggie - next time.

@dimitropoulos
Copy link
Contributor

rebased again @develohpanda if you get a second, it'd be nice to get this one over-and-out. if not, no biggie, either.


const spectral = new Spectral();
spectral.registerFormat('oas2', isOpenApiv2);
spectral.registerFormat('oas3', isOpenApiv3);
spectral.loadRuleset('spectral:oas');
Copy link
Contributor

Choose a reason for hiding this comment

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

Ooooooo does this mean we can have rulesets with kong directives as well, in the future 👀

Comment on lines 19 to 22
const spectral = new Spectral();
spectral.registerFormat('oas2', isOpenApiv2);
spectral.registerFormat('oas3', isOpenApiv3);
spectral.loadRuleset('spectral:oas');
Copy link
Contributor

@develohpanda develohpanda Jun 30, 2021

Choose a reason for hiding this comment

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

Seeing this repeated a few times so it makes sense to have a common initializeSpectral() function, and maybe for the lint operation filter as well.

EDIT: fda6408 (#3179)

@develohpanda
Copy link
Contributor

Thank you @rossmcdonald!

Comment on lines +55 to +57
const results = (await spectral.run(specContent)).filter(result => (
result.severity === 0 // filter for errors only
));
Copy link
Contributor

Choose a reason for hiding this comment

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

it's too bad we can't use isLintError here. This helps build the case for a package for top-level (i.e. 0 dependency) utils that any/all packages in the project can use (including typescript types).

@dimitropoulos dimitropoulos enabled auto-merge (squash) June 30, 2021 13:53
CI was failing
@dimitropoulos dimitropoulos merged commit c24d08a into Kong:develop Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants