Skip to content

Commit

Permalink
Merge branch 'develop' into security-schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
mnaumanali94 authored Feb 18, 2022
2 parents 5e8efff + 6b21eb1 commit 11b4420
Show file tree
Hide file tree
Showing 42 changed files with 2,984 additions and 441 deletions.
65 changes: 43 additions & 22 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,40 @@ commands:
- restore_cache:
name: Restore Yarn Package Cache
keys:
- yarn-packages-{{ arch }}-{{ checksum "yarn.lock" }}
- &yarn-cache-key yarn-packages-{{ arch }}-{{ checksum "yarn.lock" }}
- run:
name: Install Dependencies
command: yarn install --immutable
- save_cache:
name: Save Yarn Package Cache
key: yarn-packages-{{ arch }}-{{ checksum "yarn.lock" }}
key: *yarn-cache-key
paths:
- ~/.yarn

install-and-build:
build:
description: >-
Build everything required to run the test suite
Build everything required to run the test suite and to release the package
steps:
- cached-dependencies
- run:
name: Build the code
command: yarn build

build-binary:
parameters:
targets:
type: string
steps:
- run:
name: Create the Spectral Binary
command: yarn workspace @stoplight/spectral-cli pkg . --public --targets << parameters.targets >> --output binaries/spectral

install-and-build:
description: >-
Install and build everything required to run the test suite
steps:
- cached-dependencies
- build

lint-code:
steps:
- run:
Expand Down Expand Up @@ -79,10 +94,16 @@ commands:
command: yarn test.jest --maxWorkers=<< parameters.max-workers >>

test-harness:
parameters:
os:
type: enum
enum:
- linux
- windows
default: linux
steps:
- run:
name: Create the Spectral Binary
command: yarn workspace @stoplight/spectral-cli build.binary
- build-binary:
targets: << parameters.os >>
- run:
name: Run harness tests
command: yarn test.harness
Expand All @@ -91,14 +112,8 @@ commands:
steps:
- checkout
- cached-dependencies
- run:
name: Install semantic-release
command: |
yarn add --dev semantic-release@18.0 semantic-release-monorepo@7.0 @semantic-release/git@10.0 patch-package@6.4
yarn patch-package
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run: yarn build
- build

jobs:
lint:
Expand All @@ -125,7 +140,8 @@ jobs:
- checkout
- install-and-build
- test-node
- test-harness
- test-harness:
os: linux

test-browser:
docker:
Expand All @@ -144,17 +160,20 @@ jobs:
steps:
- checkout
- cached-dependencies
- run: yarn build
- build
- test-node:
max-workers: 3
- test-harness:
os: windows

build-nix-binaries:
docker:
- image: circleci/node:lts
steps:
- checkout
- install-and-build
- run: yarn workspace @stoplight/spectral-cli build.nix
- build-binary:
targets: linux,macos,alpine
- persist_to_workspace:
root: ./packages/cli/
paths:
Expand All @@ -167,7 +186,8 @@ jobs:
- checkout
- cached-dependencies
- run: yarn build
- run: yarn workspace @stoplight/spectral-cli build.windows
- build-binary:
targets: windows
- persist_to_workspace:
root: ./packages/cli/
paths:
Expand Down Expand Up @@ -218,6 +238,7 @@ jobs:
docker tag stoplight/spectral:${GIT_SHA} stoplight/spectral:${FULL_VERSION};
docker tag stoplight/spectral:${GIT_SHA} stoplight/spectral:${MINOR_VERSION};
docker tag stoplight/spectral:${GIT_SHA} stoplight/spectral:${MAJOR_VERSION};
docker tag stoplight/spectral:${GIT_SHA} stoplight/spectral:latest;
fi
echo "Docker tags:";
docker images stoplight/spectral --format="{{ .Tag }}";
Expand All @@ -227,6 +248,7 @@ jobs:
docker push stoplight/spectral:${FULL_VERSION};
docker push stoplight/spectral:${MINOR_VERSION};
docker push stoplight/spectral:${MAJOR_VERSION};
docker push stoplight/spectral:latest;
echo "Pushed stoplight/spectral:${FULL_VERSION}";
fi
if [[ -n "$DOCKER_BRANCH" ]]; then
Expand Down Expand Up @@ -268,14 +290,13 @@ workflows:
- approve-release:
type: approval
filters: *default-branch-filter
- release:
filters: *default-branch-filter
requires:
- lint
- test-node
- test-windows
- test-browser
- release:
filters: *default-branch-filter
requires:
- approve-release

release:
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ yarn test.harness
3. In your terminal, navigate to the directory you cloned Spectral into.
4. Install the dependencies: `yarn`
5. Build Spectral: `yarn build`
6. Run Spectral from your local installation: `./packages/cli/dist/index.js lint [openapi_spec_file]`
6. Run Spectral from your local installation: `node ./packages/cli/dist/index.js lint [openapi_spec_file] --ruleset /path/to/ruleset.yaml`
7. Create a new branch for your work: `git checkout -b [name_of_your_new_branch]`
8. Make changes, add tests, and then run the tests: `yarn test` and `yarn workspace @stoplight/spectral-cli build.binary && yarn test.harness`
9. Update the documentation if appropriate. For example, if you added a new rule to an OpenAPI ruleset,
Expand Down
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,28 @@ Find more [installation methods](https://meta.stoplight.io/docs/spectral/docs/ge

**Create a Ruleset**

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

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.
To reference them, you can run the following command:
1. Run this command to get our predefined rulesets based on OpenAPI or AsyncAPI:

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

2. Create your [own ruleset](./docs/getting-started/3-rulesets.md).

**Lint**

Use this command to lint with the predefined ruleset or a ruleset stored in the same directory as your API document:

```bash
spectral lint myapifile.yaml
```

Use this command to lint with a custom ruleset or one that is located in a different directory than your API document:

```bash
spectral lint petstore.yaml
spectral lint myapifile.yaml --ruleset myruleset.json
```

## 📖 Documentation
Expand Down
8 changes: 7 additions & 1 deletion docs/guides/2-cli.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Spectral CLI

[Once installed](../getting-started/2-installation.md), Spectral can be run via the command-line:
[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:

```bash
spectral lint petstore.yaml
```

Use this command to lint with a custom ruleset or one that is located in a different directory than your API document:

```bash
spectral lint petstore.yaml --ruleset myruleset.json
```

You can lint multiple files at the same time by passing on multiple arguments:

```bash
Expand Down
25 changes: 0 additions & 25 deletions docs/guides/3-javascript.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,28 +132,3 @@ const spectral = new Spectral({ resolver: customFileResolver });
The custom resolver we've just created will resolve all remote file refs relatively to the current working directory.

More on that can be found in the [json-ref-resolver repo](https://github.com/stoplightio/json-ref-resolver).

### Using a Custom De-duplication Strategy

By default, Spectral will de-duplicate results based on the result code and document location. You can customize this
behavior with the `computeFingerprint` option. For example, here is the default fingerprint implementation:

The final reported results are de-duplicated based on their computed fingerprint.

```ts
const spectral = new Spectral({
computeFingerprint: (rule: IRuleResult, hash) => {
let id = String(rule.code);

if (rule.path && rule.path.length) {
id += JSON.stringify(rule.path);
} else if (rule.range) {
id += JSON.stringify(rule.range);
}

if (rule.source) id += rule.source;

return hash(id);
},
});
```
2 changes: 1 addition & 1 deletion docs/guides/4-custom-rulesets.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ It has a specific syntax known as [JSONPath](https://goessner.net/articles/JsonP
Both of them support all the main JSONPath functionality and a little bit more, but this syntax may differ slightly from other JSONPath implementations.

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.
You can also consume your (aliases)[#aliases] here if you have some defined.
You can also consume your [aliases](#aliases) here if you have some defined.

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

Expand Down
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"test.jest": "jest --silent --cacheDirectory=.cache/.jest",
"test.karma": "karma start",
"prepare": "husky install",
"release": "HUSKY=0 yarn workspaces foreach run release"
"prerelease": "patch-package",
"release": "yarn prerelease && HUSKY=0 yarn workspaces foreach run release"
},
"workspaces": {
"packages": [
Expand All @@ -54,6 +55,7 @@
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/changelog",
"@semantic-release/npm",
"@semantic-release/github",
"@semantic-release/git"
Expand All @@ -63,12 +65,16 @@
"@commitlint/cli": "^14.1.0",
"@commitlint/config-conventional": "^12.1.4",
"@octokit/core": "^3.5.1",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.2",
"@types/jest": "^27.0.3",
"@types/jest-when": "^2.7.3",
"@types/karma": "^6.3.1",
"@types/lodash": "^4.14.176",
"@types/node": "^15.12.4",
"@types/node-fetch": "^2.5.12",
"@types/node-powershell": "^3.1.1",
"@types/text-table": "^0.2.2",
"@types/tmp": "^0.2.2",
"@typescript-eslint/eslint-plugin": "^4.33.0",
Expand All @@ -91,7 +97,11 @@
"karma-typescript-es6-transform": "^5.5.2",
"lint-staged": "^11.2.6",
"memfs": "^3.3.0",
"node-powershell": "^4.0.0",
"patch-package": "^6.4.7",
"prettier": "^2.4.1",
"semantic-release": "^19.0.2",
"semantic-release-monorepo": "^7.0.5",
"ts-jest": "^27.0.7",
"ts-node": "^10.4.0",
"typescript": "^4.4.4"
Expand Down
31 changes: 31 additions & 0 deletions packages/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
# [@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)

### Bug Fixes

- 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))

# [@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)

### Features

- support multiple formats and outputs at once ([#2037](https://github.com/stoplightio/spectral/issues/2037)) ([e7b5816](https://github.com/stoplightio/spectral/commit/e7b5816e6cfa28814f7cadeeb0c834d43758485e))

# [@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)

### Bug Fixes

- add path to JUnit testcase name ([#2029](https://github.com/stoplightio/spectral/issues/2029)) ([062ae0c](https://github.com/stoplightio/spectral/commit/062ae0c8b48534c554ac41a23edafb0fbe6aa1b3))
- correctly handle special characters in JUnit failure details ([#2028](https://github.com/stoplightio/spectral/issues/2028)) ([cabd2a9](https://github.com/stoplightio/spectral/commit/cabd2a9a7e81057c3006558add071fd80662827c))

# [@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)

### Features

- integrate ruleset-bundler ([#1824](https://github.com/stoplightio/spectral/issues/1824)) ([26284c7](https://github.com/stoplightio/spectral/commit/26284c7004d3b1d7c3ec2bd59910b66bfb3bd414))

# [@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)

### Bug Fixes

- update all prod dependencies ([963a162](https://github.com/stoplightio/spectral/commit/963a16251ed9d85032f6452d72f5cf5370bb34e0))

# [@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)

### Bug Fixes
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/spectral-cli",
"version": "6.2.0",
"version": "6.2.1",
"homepage": "https://github.com/stoplightio/spectral",
"bugs": "https://github.com/stoplightio/spectral/issues",
"author": "Stoplight <support@stoplight.io>",
Expand Down Expand Up @@ -54,11 +54,11 @@
"strip-ansi": "6.0",
"text-table": "0.2",
"tslib": "^2.3.0",
"yargs": "17.2.1"
"yargs": "17.3.1"
},
"devDependencies": {
"@types/xml2js": "^0.4.9",
"@types/yargs": "^17.0.5",
"@types/yargs": "^17.0.8",
"copyfiles": "^2.4.1",
"jest-when": "^3.4.2",
"nock": "^13.1.3",
Expand Down
15 changes: 9 additions & 6 deletions packages/cli/src/commands/__tests__/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ jest.mock('../../services/linter');

function run(command: string) {
const parser = yargs.command(lintCommand).help();
return new Promise(done => {
return new Promise((resolve, reject) => {
parser.parse(command, (err: Error, argv: unknown, output: string) => {
done(output);
if (err) {
reject(`${err.message}\n${output}`);
} else {
resolve(output);
}
});
});
}
Expand Down Expand Up @@ -60,10 +64,9 @@ describe('lint', () => {
process.stdin.isTTY = isTTY;
});

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

describe('when STDIN is present', () => {
Expand Down Expand Up @@ -204,7 +207,7 @@ describe('lint', () => {
});

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

0 comments on commit 11b4420

Please sign in to comment.