Skip to content

Commit a8862f2

Browse files
committed
feat: add docs/test for disabling rules
1 parent e77f46e commit a8862f2

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ $ docker run -it -v $(pwd):/tmp rest-api-lint:latest /tmp/my-openapi.yaml
4444

4545
The command will return a `0` on success and a `1` if any errors are found. Warnings do not trigger a failure.
4646

47+
### Exceptions & Overrides
48+
49+
When [stoplightio/spectral#747](https://github.com/stoplightio/spectral/issues/747) gets fixed you will be able to provide individual exceptions on a case-by-case basis.
50+
51+
To disable an entire rule, e.g. to support a legacy API, you can provide your own `.spectral.yaml` file in the root of your repo which sets some rules to `false`. Note that this disables the rule for the _entire file_:
52+
53+
```yaml
54+
rules:
55+
iso8601: false
56+
server-version: false
57+
```
58+
59+
It's also possible to set it to `warn`
60+
61+
The `extends` field is automatically added (or appended to) by the linter script to inject the iSP ruleset into your config.
62+
4763
## License
4864

4965
Copyright © 2020 iStreamPlanet Co., LLC

entrypoint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { Spectral, isOpenApiv3 } = require('@stoplight/spectral');
77
const { stylish } = require('@stoplight/spectral/dist/formatters/stylish');
88

99
const SPECTRAL_CONFIG = '.spectral.yaml';
10-
const ISP_RULES_PREFIX = process.env.ISP_RULES_PREFIX || '';
10+
const ISP_RULES_PREFIX = process.env.ISP_RULES_PREFIX || './';
1111

1212
// Mapping of Spectral severity to GitHub Actions message level
1313
const SEV_MAP = ['error', 'warning', 'debug', 'debug'];

fixtures/disable/openapi.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
openapi: '3.0.0'
2+
info:
3+
version: 1.0.0
4+
title: API Fixture
5+
description: API fixture description
6+
license:
7+
name: Apache2
8+
contact:
9+
10+
servers:
11+
- url: https://api.example.com/v1
12+
tags:
13+
- name: Test
14+
description: Test tag
15+
paths:
16+
/test:
17+
get:
18+
summary: Test operation
19+
description: Test operation description
20+
operationId: test
21+
tags:
22+
- Test
23+
parameters:
24+
- name: startedUtc
25+
in: query
26+
description: Some query param
27+
schema:
28+
type: string
29+
- name: stopped
30+
in: query
31+
description: Some query param
32+
schema:
33+
type: string
34+
- name: created
35+
in: query
36+
description: Some query param
37+
schema:
38+
type: string
39+
format: date-time
40+
example: 2020-01-01T12:00:00Z
41+
responses:
42+
'204':
43+
description: Response description

test.js

+21
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,24 @@ describe('Linting fixture files', () => {
3131
});
3232
});
3333
});
34+
35+
describe('Disable rules test', () => {
36+
it('should pass when rule is disabled', () => {
37+
const cwd = process.cwd();
38+
39+
process.env.ISP_RULES_PREFIX = '../../';
40+
process.chdir('fixtures/disable');
41+
42+
try {
43+
const out = execSync('../../entrypoint.js', {
44+
stdio: 'pipe',
45+
encoding: 'utf8'
46+
});
47+
} catch (err) {
48+
throw new Error(err.stdout);
49+
} finally {
50+
process.env.ISP_RULES_PREFIX = '';
51+
process.chdir(cwd);
52+
}
53+
});
54+
});

0 commit comments

Comments
 (0)