Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/validate-tags-uniqueness' into v…
Browse files Browse the repository at this point in the history
…alidate-tags-uniqueness
  • Loading branch information
magicmatatjahu committed May 19, 2022
2 parents 08807dc + f070f4e commit 42598f5
Show file tree
Hide file tree
Showing 50 changed files with 828 additions and 391 deletions.
1 change: 1 addition & 0 deletions docs/getting-started/3-rulesets.md
Expand Up @@ -80,6 +80,7 @@ Formats are an optional way to specify which API description formats a rule, or
- `aas2_1` (AsyncAPI v2.1.0)
- `aas2_2` (AsyncAPI v2.2.0)
- `aas2_3` (AsyncAPI v2.3.0)
- `aas2_4` (AsyncAPI v2.4.0)
- `oas2` (OpenAPI v2.0)
- `oas3` (OpenAPI v3.x)
- `oas3.0` (OpenAPI v3.0.x)
Expand Down
68 changes: 68 additions & 0 deletions docs/guides/4-custom-rulesets.md
Expand Up @@ -454,3 +454,71 @@ overrides:
```

In the event of multiple matches, the order of definition takes place, with the last one having the higher priority.

### Caveats

Please bear in mind that overrides are only applied to the _root_ documents. If your documents have any external dependencies, i.e. $refs, the overrides won't apply.

**Example:**

Given the following 2 YAML documents

```yaml
# my-document.yaml
openapi: "3.1.0"
paths: {}
components:
schemas:
User:
$ref: "./User.yaml"
```

```yaml
# User.yaml
title: ""
type: object
properties:
id:
type: string
required:
- id
```

and the ruleset below

```json
{
"rules": {
"empty-title-property": {
"message": "Title must not be empty",
"given": "$..title",
"then": {
"function": "truthy"
}
}
},
"overrides": [
{
"files": ["User.yaml"],
"rules": {
"empty-title-property": "off"
}
}
]
}
```

running `spectral lint my-document.yaml` will result in

```
/project/User.yaml
1:8 warning empty-title-property Title must not be empty title
✖ 1 problem (0 errors, 1 warning, 0 infos, 0 hints)
```

while executing `spectral lint User.yaml` will output

```
No results with a severity of 'error' or higher found!
```
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -30,7 +30,7 @@
"lint": "yarn lint.prettier && yarn lint.eslint",
"lint.fix": "yarn lint.prettier --write && yarn lint.eslint --fix",
"lint.eslint": "eslint --cache --cache-location .cache/.eslintcache --ext=.js,.mjs,.ts packages test-harness",
"lint.prettier": "prettier --ignore-path .eslintignore --ignore-unknown --check packages/core/src/meta/*.json packages/rulesets/src/{asyncapi,oas}/schemas/*.json docs/**/*.md README.md",
"lint.prettier": "prettier --ignore-path .eslintignore --ignore-unknown --check packages/core/src/ruleset/meta/*.json packages/rulesets/src/{asyncapi,oas}/schemas/*.json docs/**/*.md README.md",
"pretest": "yarn workspace @stoplight/spectral-ruleset-migrator pretest",
"test": "yarn pretest && yarn test.karma && yarn test.jest",
"test.harness": "jest -c ./test-harness/jest.config.js",
Expand Down Expand Up @@ -116,7 +116,7 @@
"README.md": [
"prettier --write"
],
"packages/core/src/meta/*.json": [
"packages/core/src/ruleset/meta/*.json": [
"prettier --ignore-path .eslintignore --write"
],
"packages/rulesets/src/{asyncapi,oas}/schemas/*.json": [
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/CHANGELOG.md
@@ -1,3 +1,10 @@
# [@stoplight/spectral-cli-v6.4.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-v6.3.0...@stoplight/spectral-cli-v6.4.0) (2022-05-12)


### Features

* **cli:** sort linting results alphabetically ([#2147](https://github.com/stoplightio/spectral/issues/2147)) ([84d48cf](https://github.com/stoplightio/spectral/commit/84d48cf5e02780f0cbb9ae9074c03a618c2bc462))

# [@stoplight/spectral-cli-v6.3.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-v6.2.1...@stoplight/spectral-cli-v6.3.0) (2022-03-03)


Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@stoplight/spectral-cli",
"version": "6.3.0",
"version": "6.4.0",
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
"author": "Stoplight <support@stoplight.io>",
Expand Down
@@ -0,0 +1,5 @@
{
"info": {
"title": "no stoplight :("
}
}
25 changes: 24 additions & 1 deletion packages/cli/src/services/__tests__/linter.test.ts
Expand Up @@ -118,8 +118,8 @@ describe('Linter service', () => {

it('given a list of files is provided, outputs issues for each file', () => {
const documents = [
join(__dirname, `./__fixtures__/invalid-stoplight-info-document.json`),
join(__dirname, `./__fixtures__/missing-stoplight-info-document.json`),
join(__dirname, `./__fixtures__/missing-stoplight-info-document-copy.json`),
];

return expect(run(['lint', ...documents].join(' '))).resolves.toEqual([
Expand All @@ -142,6 +142,29 @@ describe('Linter service', () => {
]);
});

it('sorts linting results in an alphabetical order', () => {
const documents = [
join(__dirname, `./__fixtures__/missing-stoplight-info-document.json`),
join(__dirname, `./__fixtures__/openapi-3.0-valid.yaml`),
join(__dirname, `./__fixtures__/invalid-stoplight-info-document.json`),
];

return expect(run(['lint', ...documents].join(' '))).resolves.toEqual([
expect.objectContaining({
code: 'info-matches-stoplight',
source: join(__dirname, `./__fixtures__/invalid-stoplight-info-document.json`),
}),
expect.objectContaining({
code: 'info-matches-stoplight',
source: join(__dirname, `./__fixtures__/missing-stoplight-info-document.json`),
}),
expect.objectContaining({
code: 'info-matches-stoplight',
source: join(__dirname, `./__fixtures__/openapi-3.0-valid.yaml`),
}),
]);
});

describe('when glob is provided', () => {
const documents = join(__dirname, `./__fixtures__/missing-stoplight-info*.json`);

Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/services/linter/utils/listFiles.ts
Expand Up @@ -10,6 +10,8 @@ async function match(pattern: fg.Pattern | fg.Pattern[]): Promise<string[]> {
return (await fg(pattern, GLOB_OPTIONS)).map(normalize);
}

const compareString = (a: string, b: string): number => a.localeCompare(b);

export async function listFiles(patterns: string[], ignoreUnmatchedGlobs: boolean): Promise<[string[], string[]]> {
const { files, urls } = patterns.reduce<{
files: string[];
Expand Down Expand Up @@ -49,5 +51,5 @@ export async function listFiles(patterns: string[], ignoreUnmatchedGlobs: boolea
);
}

return [[...urls, ...filesFound], fileSearchWithoutResult]; // let's normalize OS paths produced by fast-glob to have consistent paths across all platforms
return [[...urls, ...filesFound].sort(compareString), fileSearchWithoutResult]; // let's normalize OS paths produced by fast-glob to have consistent paths across all platforms
}
21 changes: 21 additions & 0 deletions packages/core/CHANGELOG.md
@@ -1,3 +1,24 @@
# [@stoplight/spectral-core-v1.12.2](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-v1.12.1...@stoplight/spectral-core-v1.12.2) (2022-05-18)


### Bug Fixes

* **core:** bump nimma from 0.2.0 to 0.2.1 ([#2157](https://github.com/stoplightio/spectral/issues/2157)) ([4d5ebeb](https://github.com/stoplightio/spectral/commit/4d5ebebb65cb8f6c44faa5b629311f5b25dd6bfe))

# [@stoplight/spectral-core-v1.12.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-v1.12.0...@stoplight/spectral-core-v1.12.1) (2022-04-29)


### Bug Fixes

* **core:** redeclared rules should always be re-enabled ([#2138](https://github.com/stoplightio/spectral/issues/2138)) ([6def6be](https://github.com/stoplightio/spectral/commit/6def6be4bc3f318c8e93d2e1c0df2ff1b803a178))

# [@stoplight/spectral-core-v1.12.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-v1.11.1...@stoplight/spectral-core-v1.12.0) (2022-04-18)


### Features

* **core:** support JSON ruleset validation ([#2062](https://github.com/stoplightio/spectral/issues/2062)) ([aeb7d5b](https://github.com/stoplightio/spectral/commit/aeb7d5b842741d85229fb2c8575ae2c58c8dfbb8))

# [@stoplight/spectral-core-v1.11.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-core-v1.11.0...@stoplight/spectral-core-v1.11.1) (2022-03-16)


Expand Down
30 changes: 22 additions & 8 deletions packages/core/package.json
@@ -1,8 +1,6 @@
{
"name": "@stoplight/spectral-core",
"version": "1.11.1",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"version": "1.12.2",
"sideEffects": false,
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
Expand All @@ -15,6 +13,23 @@
"files": [
"dist"
],
"type": "commonjs",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./ruleset": {
"types": "./dist/ruleset/index.d.ts",
"default": "./dist/ruleset/index.js"
},
"./ruleset/validation": {
"types": "./dist/ruleset/validation/index.d.ts",
"default": "./dist/ruleset/validation/index.js"
}
},
"engines": {
"node": "^12.20 || >= 14.13"
},
Expand All @@ -23,23 +38,23 @@
},
"dependencies": {
"@stoplight/better-ajv-errors": "1.0.1",
"@stoplight/json": "~3.17.1",
"@stoplight/json": "~3.18.1",
"@stoplight/lifecycle": "2.3.2",
"@stoplight/path": "1.3.2",
"@stoplight/spectral-parsers": "^1.0.0",
"@stoplight/spectral-ref-resolver": "^1.0.0",
"@stoplight/spectral-runtime": "^1.0.0",
"@stoplight/types": "12.3.0",
"@stoplight/types": "13.1.0",
"@types/json-schema": "^7.0.7",
"ajv": "^8.6.0",
"ajv-errors": "~3.0.0",
"ajv-formats": "~2.1.0",
"blueimp-md5": "2.18.0",
"json-schema": "0.4.0",
"jsonpath-plus": "6.0.1",
"lodash": "~4.17.21",
"lodash.topath": "^4.5.2",
"minimatch": "3.0.4",
"nimma": "0.2.0",
"nimma": "0.2.1",
"pony-cause": "^1.0.0",
"simple-eval": "1.0.0",
"tslib": "^2.3.0"
Expand All @@ -49,7 +64,6 @@
"@stoplight/spectral-functions": "*",
"@stoplight/spectral-parsers": "*",
"@stoplight/yaml": "^4.2.2",
"@types/json-schema": "^7.0.7",
"@types/minimatch": "^3.0.5",
"@types/treeify": "^1.0.0",
"nock": "^13.1.0",
Expand Down

This file was deleted.

14 changes: 0 additions & 14 deletions packages/core/src/ruleset/__tests__/__fixtures__/foo-ruleset.json

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,15 @@
import { RulesetDefinition } from '@stoplight/spectral-core';
import shared from './shared';
import { truthy } from '@stoplight/spectral-functions/src';

export default {
extends: [[shared, 'off']],
rules: {
'overridable-rule': {
given: '$.foo',
then: {
function: truthy,
},
},
},
} as RulesetDefinition;

This file was deleted.

This file was deleted.

0 comments on commit 42598f5

Please sign in to comment.