Skip to content

Commit 11b4420

Browse files
authored
Merge branch 'develop' into security-schemes
2 parents 5e8efff + 6b21eb1 commit 11b4420

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2984
-441
lines changed

.circleci/config.yml

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,40 @@ commands:
3030
- restore_cache:
3131
name: Restore Yarn Package Cache
3232
keys:
33-
- yarn-packages-{{ arch }}-{{ checksum "yarn.lock" }}
33+
- &yarn-cache-key yarn-packages-{{ arch }}-{{ checksum "yarn.lock" }}
3434
- run:
3535
name: Install Dependencies
3636
command: yarn install --immutable
3737
- save_cache:
3838
name: Save Yarn Package Cache
39-
key: yarn-packages-{{ arch }}-{{ checksum "yarn.lock" }}
39+
key: *yarn-cache-key
4040
paths:
4141
- ~/.yarn
4242

43-
install-and-build:
43+
build:
4444
description: >-
45-
Build everything required to run the test suite
45+
Build everything required to run the test suite and to release the package
4646
steps:
47-
- cached-dependencies
4847
- run:
4948
name: Build the code
5049
command: yarn build
5150

51+
build-binary:
52+
parameters:
53+
targets:
54+
type: string
55+
steps:
56+
- run:
57+
name: Create the Spectral Binary
58+
command: yarn workspace @stoplight/spectral-cli pkg . --public --targets << parameters.targets >> --output binaries/spectral
59+
60+
install-and-build:
61+
description: >-
62+
Install and build everything required to run the test suite
63+
steps:
64+
- cached-dependencies
65+
- build
66+
5267
lint-code:
5368
steps:
5469
- run:
@@ -79,10 +94,16 @@ commands:
7994
command: yarn test.jest --maxWorkers=<< parameters.max-workers >>
8095

8196
test-harness:
97+
parameters:
98+
os:
99+
type: enum
100+
enum:
101+
- linux
102+
- windows
103+
default: linux
82104
steps:
83-
- run:
84-
name: Create the Spectral Binary
85-
command: yarn workspace @stoplight/spectral-cli build.binary
105+
- build-binary:
106+
targets: << parameters.os >>
86107
- run:
87108
name: Run harness tests
88109
command: yarn test.harness
@@ -91,14 +112,8 @@ commands:
91112
steps:
92113
- checkout
93114
- cached-dependencies
94-
- run:
95-
name: Install semantic-release
96-
command: |
97-
98-
yarn patch-package
99-
100115
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
101-
- run: yarn build
116+
- build
102117

103118
jobs:
104119
lint:
@@ -125,7 +140,8 @@ jobs:
125140
- checkout
126141
- install-and-build
127142
- test-node
128-
- test-harness
143+
- test-harness:
144+
os: linux
129145

130146
test-browser:
131147
docker:
@@ -144,17 +160,20 @@ jobs:
144160
steps:
145161
- checkout
146162
- cached-dependencies
147-
- run: yarn build
163+
- build
148164
- test-node:
149165
max-workers: 3
166+
- test-harness:
167+
os: windows
150168

151169
build-nix-binaries:
152170
docker:
153171
- image: circleci/node:lts
154172
steps:
155173
- checkout
156174
- install-and-build
157-
- run: yarn workspace @stoplight/spectral-cli build.nix
175+
- build-binary:
176+
targets: linux,macos,alpine
158177
- persist_to_workspace:
159178
root: ./packages/cli/
160179
paths:
@@ -167,7 +186,8 @@ jobs:
167186
- checkout
168187
- cached-dependencies
169188
- run: yarn build
170-
- run: yarn workspace @stoplight/spectral-cli build.windows
189+
- build-binary:
190+
targets: windows
171191
- persist_to_workspace:
172192
root: ./packages/cli/
173193
paths:
@@ -218,6 +238,7 @@ jobs:
218238
docker tag stoplight/spectral:${GIT_SHA} stoplight/spectral:${FULL_VERSION};
219239
docker tag stoplight/spectral:${GIT_SHA} stoplight/spectral:${MINOR_VERSION};
220240
docker tag stoplight/spectral:${GIT_SHA} stoplight/spectral:${MAJOR_VERSION};
241+
docker tag stoplight/spectral:${GIT_SHA} stoplight/spectral:latest;
221242
fi
222243
echo "Docker tags:";
223244
docker images stoplight/spectral --format="{{ .Tag }}";
@@ -227,6 +248,7 @@ jobs:
227248
docker push stoplight/spectral:${FULL_VERSION};
228249
docker push stoplight/spectral:${MINOR_VERSION};
229250
docker push stoplight/spectral:${MAJOR_VERSION};
251+
docker push stoplight/spectral:latest;
230252
echo "Pushed stoplight/spectral:${FULL_VERSION}";
231253
fi
232254
if [[ -n "$DOCKER_BRANCH" ]]; then
@@ -268,14 +290,13 @@ workflows:
268290
- approve-release:
269291
type: approval
270292
filters: *default-branch-filter
293+
- release:
294+
filters: *default-branch-filter
271295
requires:
272296
- lint
273297
- test-node
274298
- test-windows
275299
- test-browser
276-
- release:
277-
filters: *default-branch-filter
278-
requires:
279300
- approve-release
280301

281302
release:

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ yarn test.harness
170170
3. In your terminal, navigate to the directory you cloned Spectral into.
171171
4. Install the dependencies: `yarn`
172172
5. Build Spectral: `yarn build`
173-
6. Run Spectral from your local installation: `./packages/cli/dist/index.js lint [openapi_spec_file]`
173+
6. Run Spectral from your local installation: `node ./packages/cli/dist/index.js lint [openapi_spec_file] --ruleset /path/to/ruleset.yaml`
174174
7. Create a new branch for your work: `git checkout -b [name_of_your_new_branch]`
175175
8. Make changes, add tests, and then run the tests: `yarn test` and `yarn workspace @stoplight/spectral-cli build.binary && yarn test.harness`
176176
9. Update the documentation if appropriate. For example, if you added a new rule to an OpenAPI ruleset,

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,28 @@ Find more [installation methods](https://meta.stoplight.io/docs/spectral/docs/ge
3434

3535
**Create a Ruleset**
3636

37-
Spectral, being a generic YAML/JSON linter, needs a ruleset in order to be able to lint files.
38-
You can learn more about the rulesets [here](./docs/getting-started/3-rulesets.md).
37+
Spectral, being a generic YAML/JSON linter, needs a ruleset to lint files. There are two ways to get a ruleset:
3938

40-
If you intend to lint an OpenAPI or AsyncAPI document, we have a few predefined rulesets you can extend to get Spectral up and running.
41-
To reference them, you can run the following command:
39+
1. Run this command to get our predefined rulesets based on OpenAPI or AsyncAPI:
4240

4341
```bash
4442
printf '{\n "extends": ["spectral:oas", "spectral:asyncapi"]\n}\n' > .spectral.json
4543
```
4644

45+
2. Create your [own ruleset](./docs/getting-started/3-rulesets.md).
46+
4747
**Lint**
4848

49+
Use this command to lint with the predefined ruleset or a ruleset stored in the same directory as your API document:
50+
51+
```bash
52+
spectral lint myapifile.yaml
53+
```
54+
55+
Use this command to lint with a custom ruleset or one that is located in a different directory than your API document:
56+
4957
```bash
50-
spectral lint petstore.yaml
58+
spectral lint myapifile.yaml --ruleset myruleset.json
5159
```
5260

5361
## 📖 Documentation

docs/guides/2-cli.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
# Spectral CLI
22

3-
[Once installed](../getting-started/2-installation.md), Spectral can be run via the command-line:
3+
[Once Spectral is installed](../getting-started/2-installation.md) and [you have a ruleset](../../README.md#installation-and-usage), run Spectral via the command-line:
44

55
```bash
66
spectral lint petstore.yaml
77
```
88

9+
Use this command to lint with a custom ruleset or one that is located in a different directory than your API document:
10+
11+
```bash
12+
spectral lint petstore.yaml --ruleset myruleset.json
13+
```
14+
915
You can lint multiple files at the same time by passing on multiple arguments:
1016

1117
```bash

docs/guides/3-javascript.md

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,3 @@ const spectral = new Spectral({ resolver: customFileResolver });
132132
The custom resolver we've just created will resolve all remote file refs relatively to the current working directory.
133133

134134
More on that can be found in the [json-ref-resolver repo](https://github.com/stoplightio/json-ref-resolver).
135-
136-
### Using a Custom De-duplication Strategy
137-
138-
By default, Spectral will de-duplicate results based on the result code and document location. You can customize this
139-
behavior with the `computeFingerprint` option. For example, here is the default fingerprint implementation:
140-
141-
The final reported results are de-duplicated based on their computed fingerprint.
142-
143-
```ts
144-
const spectral = new Spectral({
145-
computeFingerprint: (rule: IRuleResult, hash) => {
146-
let id = String(rule.code);
147-
148-
if (rule.path && rule.path.length) {
149-
id += JSON.stringify(rule.path);
150-
} else if (rule.range) {
151-
id += JSON.stringify(rule.range);
152-
}
153-
154-
if (rule.source) id += rule.source;
155-
156-
return hash(id);
157-
},
158-
});
159-
```

docs/guides/4-custom-rulesets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ It has a specific syntax known as [JSONPath](https://goessner.net/articles/JsonP
3131
Both of them support all the main JSONPath functionality and a little bit more, but this syntax may differ slightly from other JSONPath implementations.
3232

3333
Your `given` value can be a string containing any valid JSONPath expression, or an array of expressions to apply a rule to multiple parts of a document.
34-
You can also consume your (aliases)[#aliases] here if you have some defined.
34+
You can also consume your [aliases](#aliases) here if you have some defined.
3535

3636
Use the [JSONPath Online Evaluator](http://jsonpath.com/) to determine what `given` path you want.
3737

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"test.jest": "jest --silent --cacheDirectory=.cache/.jest",
3838
"test.karma": "karma start",
3939
"prepare": "husky install",
40-
"release": "HUSKY=0 yarn workspaces foreach run release"
40+
"prerelease": "patch-package",
41+
"release": "yarn prerelease && HUSKY=0 yarn workspaces foreach run release"
4142
},
4243
"workspaces": {
4344
"packages": [
@@ -54,6 +55,7 @@
5455
"plugins": [
5556
"@semantic-release/commit-analyzer",
5657
"@semantic-release/release-notes-generator",
58+
"@semantic-release/changelog",
5759
"@semantic-release/npm",
5860
"@semantic-release/github",
5961
"@semantic-release/git"
@@ -63,12 +65,16 @@
6365
"@commitlint/cli": "^14.1.0",
6466
"@commitlint/config-conventional": "^12.1.4",
6567
"@octokit/core": "^3.5.1",
68+
"@semantic-release/changelog": "^6.0.1",
69+
"@semantic-release/git": "^10.0.1",
70+
"@semantic-release/github": "^8.0.2",
6671
"@types/jest": "^27.0.3",
6772
"@types/jest-when": "^2.7.3",
6873
"@types/karma": "^6.3.1",
6974
"@types/lodash": "^4.14.176",
7075
"@types/node": "^15.12.4",
7176
"@types/node-fetch": "^2.5.12",
77+
"@types/node-powershell": "^3.1.1",
7278
"@types/text-table": "^0.2.2",
7379
"@types/tmp": "^0.2.2",
7480
"@typescript-eslint/eslint-plugin": "^4.33.0",
@@ -91,7 +97,11 @@
9197
"karma-typescript-es6-transform": "^5.5.2",
9298
"lint-staged": "^11.2.6",
9399
"memfs": "^3.3.0",
100+
"node-powershell": "^4.0.0",
101+
"patch-package": "^6.4.7",
94102
"prettier": "^2.4.1",
103+
"semantic-release": "^19.0.2",
104+
"semantic-release-monorepo": "^7.0.5",
95105
"ts-jest": "^27.0.7",
96106
"ts-node": "^10.4.0",
97107
"typescript": "^4.4.4"

packages/cli/CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
# [@stoplight/spectral-cli-v6.2.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-v6.2.0...@stoplight/spectral-cli-v6.2.1) (2022-02-08)
2+
3+
### Bug Fixes
4+
5+
- output to stdout not working with multiple output formatters ([#2044](https://github.com/stoplightio/spectral/issues/2044)) ([77dfe3b](https://github.com/stoplightio/spectral/commit/77dfe3b5237a25928febfcf5696eaea5b1edc54f))
6+
7+
# [@stoplight/spectral-cli-v6.2.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-v6.1.1...@stoplight/spectral-cli-v6.2.0) (2022-01-28)
8+
9+
### Features
10+
11+
- support multiple formats and outputs at once ([#2037](https://github.com/stoplightio/spectral/issues/2037)) ([e7b5816](https://github.com/stoplightio/spectral/commit/e7b5816e6cfa28814f7cadeeb0c834d43758485e))
12+
13+
# [@stoplight/spectral-cli-v6.1.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-v6.1.0...@stoplight/spectral-cli-v6.1.1) (2022-01-21)
14+
15+
### Bug Fixes
16+
17+
- add path to JUnit testcase name ([#2029](https://github.com/stoplightio/spectral/issues/2029)) ([062ae0c](https://github.com/stoplightio/spectral/commit/062ae0c8b48534c554ac41a23edafb0fbe6aa1b3))
18+
- correctly handle special characters in JUnit failure details ([#2028](https://github.com/stoplightio/spectral/issues/2028)) ([cabd2a9](https://github.com/stoplightio/spectral/commit/cabd2a9a7e81057c3006558add071fd80662827c))
19+
20+
# [@stoplight/spectral-cli-v6.1.0](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-v6.0.1...@stoplight/spectral-cli-v6.1.0) (2021-10-07)
21+
22+
### Features
23+
24+
- integrate ruleset-bundler ([#1824](https://github.com/stoplightio/spectral/issues/1824)) ([26284c7](https://github.com/stoplightio/spectral/commit/26284c7004d3b1d7c3ec2bd59910b66bfb3bd414))
25+
26+
# [@stoplight/spectral-cli-v6.0.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-v6.0.0...@stoplight/spectral-cli-v6.0.1) (2021-10-05)
27+
28+
### Bug Fixes
29+
30+
- update all prod dependencies ([963a162](https://github.com/stoplightio/spectral/commit/963a16251ed9d85032f6452d72f5cf5370bb34e0))
31+
132
# [@stoplight/spectral-cli-v1.2.1](https://github.com/stoplightio/spectral/compare/@stoplight/spectral-cli-v1.2.0...@stoplight/spectral-cli-v1.2.1) (2021-07-09)
233

334
### Bug Fixes

packages/cli/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@stoplight/spectral-cli",
3-
"version": "6.2.0",
3+
"version": "6.2.1",
44
"homepage": "https://github.com/stoplightio/spectral",
55
"bugs": "https://github.com/stoplightio/spectral/issues",
66
"author": "Stoplight <[email protected]>",
@@ -54,11 +54,11 @@
5454
"strip-ansi": "6.0",
5555
"text-table": "0.2",
5656
"tslib": "^2.3.0",
57-
"yargs": "17.2.1"
57+
"yargs": "17.3.1"
5858
},
5959
"devDependencies": {
6060
"@types/xml2js": "^0.4.9",
61-
"@types/yargs": "^17.0.5",
61+
"@types/yargs": "^17.0.8",
6262
"copyfiles": "^2.4.1",
6363
"jest-when": "^3.4.2",
6464
"nock": "^13.1.3",

packages/cli/src/commands/__tests__/lint.test.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ jest.mock('../../services/linter');
1212

1313
function run(command: string) {
1414
const parser = yargs.command(lintCommand).help();
15-
return new Promise(done => {
15+
return new Promise((resolve, reject) => {
1616
parser.parse(command, (err: Error, argv: unknown, output: string) => {
17-
done(output);
17+
if (err) {
18+
reject(`${err.message}\n${output}`);
19+
} else {
20+
resolve(output);
21+
}
1822
});
1923
});
2024
}
@@ -60,10 +64,9 @@ describe('lint', () => {
6064
process.stdin.isTTY = isTTY;
6165
});
6266

63-
it('shows help when no document and no STDIN are present', async () => {
67+
it('shows help when no document and no STDIN are present', () => {
6468
process.stdin.isTTY = true;
65-
const output = await run('lint');
66-
expect(output).toContain('documents Location of JSON/YAML documents');
69+
return expect(run('lint')).rejects.toContain('documents Location of JSON/YAML documents');
6770
});
6871

6972
describe('when STDIN is present', () => {
@@ -204,7 +207,7 @@ describe('lint', () => {
204207
});
205208

206209
it('shows help if unknown format is passed', () => {
207-
return expect(run('lint -f foo ./__fixtures__/empty-oas2-document.json')).resolves.toContain(
210+
return expect(run('lint -f foo ./__fixtures__/empty-oas2-document.json')).rejects.toContain(
208211
'documents Location of JSON/YAML documents. Can be either a file, a glob or',
209212
);
210213
});

0 commit comments

Comments
 (0)