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: drop oas2 and oas3 rulesets #773

Merged
merged 3 commits into from
Dec 2, 2019
Merged

feat: drop oas2 and oas3 rulesets #773

merged 3 commits into from
Dec 2, 2019

Conversation

nulltoken
Copy link
Contributor

@nulltoken nulltoken commented Nov 16, 2019

#689 Has been superseded by #772
This PR superseds #772

This is an attempt at helping get all the tests pass.

@nulltoken nulltoken mentioned this pull request Nov 16, 2019
7 tasks
@nulltoken nulltoken changed the title Ntk/fixup unify [NOT FOR MERGE] Ntk/fixup unify Nov 16, 2019
@nulltoken
Copy link
Contributor Author

@philsturgeon Making progress. Still one karma failing test.

@nulltoken
Copy link
Contributor Author

nulltoken commented Nov 17, 2019

@philsturgeon Jest and harness tests have been fixed. Still got an issue with the last one.
It fails differently on node 12 and node 10 (#737 should help fix fix by making the sorting a bit more thorough).

Feel free to cherry pick and squash the proposed changes you like (don't hate too much?) in your PR.

I'm going to decorate some of the changes I'm the less happy with with some comments.

@@ -6,7 +6,6 @@ import oasOpIdUnique from '../oasOpIdUnique';

describe('oasOpIdUnique', () => {
const s = new Spectral();
s.registerFormat('oas2', () => true);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@philsturgeon I've dropped this as this is supposed to not be tied to oas2. Does that make sense? Another option would be to revert that change and add a new test targeting oas3.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think a lot of thse registerFormat's were erroneous and this is fine.

@@ -515,7 +512,7 @@
"message": "{{error}}",
"recommended": true,
"formats": ["oas2"],
"severity": "error",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@philsturgeon I do think "error" would be nicer but I was more focused on making the tests pass.

Proposal: Unless this is blocking, maybe log a tech debt issue and switch back to "error" in another PR?

src/cli/services/__tests__/linter.test.ts Outdated Show resolved Hide resolved
src/rulesets/oas/index.json Outdated Show resolved Hide resolved
@nulltoken nulltoken changed the base branch from develop to feat/improve-oas-rulesets November 17, 2019 16:31
@nulltoken
Copy link
Contributor Author

@philsturgeon rebased on top of your latest changes

@philsturgeon
Copy link
Contributor

@nulltoken this is amazing! Shall I leave this in your capable hands? @P0lip can you help him get this over the line?

@P0lip
Copy link
Contributor

P0lip commented Nov 19, 2019

@philsturgeon yup! will do my best to help.

@nulltoken
Copy link
Contributor Author

nulltoken commented Nov 20, 2019

@nulltoken this is amazing!

@philsturgeon YOU did the hard work. All I had to do was fighting against jest matchers (Yes. Looking at you expectArrayContaining and expectObjectContaining)

Shall I leave this in your capable hands? @P0lip can you help him get this over the line?

Ok. Taking over this task then.

@nulltoken nulltoken changed the title [NOT FOR MERGE] Ntk/fixup unify [WIP] Unify rulesets Nov 20, 2019
@nulltoken nulltoken changed the base branch from feat/improve-oas-rulesets to develop November 20, 2019 15:53
@nulltoken
Copy link
Contributor Author

@P0lip It's now rebased. I've started to reduce a bit the diff noise by removing unneeded changes.

Could you please start a first pass of review?

@@ -23,7 +23,7 @@
* @author Sindre Sorhus
*/

import chalk from 'chalk';
import chalk = require('chalk');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import chalk = require('chalk');
import * as chalk 'chalk';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@P0lip StripAnsi requires the same kind "required" import but doesn't seem to like the import * syntax.

How about switching esModuleInterop flag to true? Would that mess something up?

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't worry about it. I've already updated both of these dependencies on develop :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about switching esModuleInterop flag to true? Would that mess something up?

@P0lip Yep, I've seen that. But not being a transpiling guru, I'd genuinely be interested in your standpoint on that.

@@ -353,42 +336,6 @@ describe('Rulesets reader', () => {
).toHaveLength(0);
});

it('should limit the scope of formats to a ruleset', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The test should be kept. We just need to use different (custom) rulesets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@P0lip ACK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@P0lip Tentatively replaced with should limit the scope of formats to a ruleset.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@P0lip I'll rewrite this to custom rulesets later today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@P0lip Done. Did I manage to keep the intent of the original test?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, seems good! Thank you.

@@ -1,21 +1,8 @@
import { readRuleset } from '../reader';

describe('Rulesets reader', () => {
it('should resolve oas2-schema', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto, guess we want to keep it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@P0lip ACK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@P0lip Fixed

@nulltoken nulltoken mentioned this pull request Nov 21, 2019
4 tasks
@philsturgeon
Copy link
Contributor

philsturgeon commented Nov 21, 2019 via email

@nulltoken
Copy link
Contributor Author

Copied over from #772 (comment)

cc @nulltoken since you are working on that too.
I'm pretty sure src/rulesets/oas3/tests/api-servers.ts fails now.

@P0lip I don't see it failing in #773. Or is it passing for the wrong reason? Or did I misunderstand you?

@nulltoken
Copy link
Contributor Author

@P0lip I'll work on this tomorrow. Should by ready for review by Monday.

@P0lip
Copy link
Contributor

P0lip commented Nov 22, 2019

@P0lip I don't see it failing in #773. Or is it passing for the wrong reason? Or did I misunderstand you?

It's not failing, because the rule looks the same.

    "oas3-api-servers": {
      "description": "OpenAPI `servers` must be present and non-empty array.",
      "recommended": true,
      "formats": ["oas3"],
      "given": "$",
      "then": {
        "field": "servers",
        "function": "schema",
        "functionOptions": {
          "schema": {
            "items": {
              "type": "object"
            },
            "minItems": 1,
            "type": "array"
          }
        }
      },
      "tags": [
        "api"
      ]
    },

@nulltoken
Copy link
Contributor Author

Minimise the change in order to get this one done.

@philsturgeon @P0lip I've tried to reduce the diff noise as much as possible.
I'll try to get rid of some of the added registerFormat.

@nulltoken
Copy link
Contributor Author

Minimise the change in order to get this one done.

@philsturgeon @P0lip I've tried to reduce the diff noise as much as possible.
I'll try to get rid of some of the added registerFormat.

@P0lip @philsturgeon Looks like the tests fail if I remove those new registerFormat() calls. However, I'm not quite sure why they're now required whereas they previously weren't.

@philsturgeon
Copy link
Contributor

philsturgeon commented Nov 23, 2019 via email

@nulltoken
Copy link
Contributor Author

nulltoken commented Nov 23, 2019

I added formats to a lot of rules whereas before they were applied at the ruleset level. The way we pluck rules and put them into setRules in our tests means this is now important. Our test stuff is a little messy but we should clean it up in another thing, let’s just get it working first.

@philsturgeon Thanks for this feedback. Hower, I now realize that, as a user, I may not have clearly understood that subtlety.

  • The doc states Spectral supports two core formats: oas2 and oas3. Using registerFormat you can add support for autodetecting other formats. This seems to say "Hey! You're linting OAS2 or OAS3? Cool! Everything is already set up.". Or is this a cli vs Api difference in usage?

  • I my mind, when a ruleset was exposing formats, rules that didn't specify a format were inheriting those ruleset formats. I'm not sure to understand why specifying now a format at the rule level requires to previously invoke registerFormat. Or was that inheritance thingie all in my head only?

Considering this, when one should invoke registerFormat seems a bit "blurry" to me. Any chance you could sprinkle a bit of your magic documentation writing dust to enlighten this?

@nulltoken
Copy link
Contributor Author

Rebased and cleaned up history.

@nulltoken nulltoken changed the title [WIP] Unify rulesets feat: drop oas2 and oas3 rulesets Nov 24, 2019
@P0lip
Copy link
Contributor

P0lip commented Nov 26, 2019

@nulltoken I'll review it today!

Copy link
Contributor

@P0lip P0lip left a comment

Choose a reason for hiding this comment

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

Looking very well!
Almost ready to be merged.

@@ -80,7 +80,6 @@ Specifying the format is optional, so you can completely ignore this if all the
rules:
api-servers:
Copy link
Contributor

Choose a reason for hiding this comment

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

We have renamed this rule, haven't we?

Suggested change
api-servers:
oas3-api-servers:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


return rules;
}, {}),
expect(rules['generic-valid-rule'].formats).toBeInstanceOf(Array);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(rules['generic-valid-rule'].formats).toBeInstanceOf(Array);

Copy link
Contributor

Choose a reason for hiding this comment

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

(Unneeded since we match against an array of oas2 and oas3)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

rules[name] = expect.objectContaining({
formats: ['oas3'],
});
expect(rules['oas2-valid-rule'].formats).toBeInstanceOf(Array);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(rules['oas2-valid-rule'].formats).toBeInstanceOf(Array);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

},
}),
);
expect(rules['oas3-valid-rule'].formats).toBeInstanceOf(Array);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
expect(rules['oas3-valid-rule'].formats).toBeInstanceOf(Array);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -353,42 +336,6 @@ describe('Rulesets reader', () => {
).toHaveLength(0);
});

it('should limit the scope of formats to a ruleset', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, seems good! Thank you.

import { RuleType, Spectral } from '../../../spectral';
import * as ruleset from '../index.json';

describe('components-schema-description', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Have we migrated this test? Cannot find it anywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dropped by @philsturgeon (as described in #725)

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right. Confused the names.

import { RuleType, Spectral } from '../../../spectral';
import * as ruleset from '../index.json';

describe('definition-description', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto, has it been migrated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dropped by @philsturgeon (as described in #725)

image

@nulltoken
Copy link
Contributor Author

Looking very well!
Almost ready to be merged.

@P0lip I believe all comments have been dealt with.

@@ -107,21 +107,22 @@ openapi: 3.0.0
`

const spectral = new Spectral();
spectral.registerFormat('oas2', isOpenApiv2);
spectral.registerFormat('oas3', isOpenApiv3);spectral.loadRuleset('spectral:oas3') // spectral:oas2 for OAS 2.0 aka Swagger
spectral.registerFormat('oas2', isOpenApiv2); // spectral:oas2 for OAS 2.0 aka Swagger
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
spectral.registerFormat('oas2', isOpenApiv2); // spectral:oas2 for OAS 2.0 aka Swagger
spectral.registerFormat('oas2', isOpenApiv2); // spectral:oas2 for OpenAPI v2.0

We can do better than saying "oas2 = OAS 2" and we mention swagger plenty elsewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw I know you didnt add this im just noticing it now 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

philsturgeon
philsturgeon previously approved these changes Nov 27, 2019
@@ -107,21 +107,22 @@ openapi: 3.0.0
`

const spectral = new Spectral();
spectral.registerFormat('oas2', isOpenApiv2);
spectral.registerFormat('oas3', isOpenApiv3);spectral.loadRuleset('spectral:oas3') // spectral:oas2 for OAS 2.0 aka Swagger
spectral.registerFormat('oas2', isOpenApiv2); // spectral:oas2 for OAS 2.0 aka Swagger
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw I know you didnt add this im just noticing it now 😅

P0lip
P0lip previously approved these changes Nov 27, 2019
Copy link
Contributor

@P0lip P0lip left a comment

Choose a reason for hiding this comment

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

Just an extra comment.
Looks good! Thank you so much for taking care of this. Much appreciated ❤️

@philsturgeon could you have another pass too?
I did read the code thrice yet since the PR is fairly sized I might have skipped something.

mergeRules(oas3Rules, {
'valid-example-in-schemas': 'off',
mergeRules(oasRules, {
'oas3-valid-schema-example': 'off',
'components-schema-description': -1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's change this rule to something else since it's removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@P0lip Replaced with operation-2xx-response

import { RuleType, Spectral } from '../../../spectral';
import * as ruleset from '../index.json';

describe('components-schema-description', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right. Confused the names.

@P0lip P0lip added the breaking Pull requests that introduce a breaking change label Nov 28, 2019
@P0lip P0lip merged commit 84a8238 into stoplightio:develop Dec 2, 2019
@nulltoken nulltoken deleted the ntk/fixup_unify branch December 5, 2019 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Pull requests that introduce a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants