Skip to content

Commit b1425e5

Browse files
author
Phil Sturgeon
authored
Release v0.8.0 (#106)
* deps; use oas-resolver * Dropped validator tests now validator is gone * Mention OAS Kit changes in changelog * Config File (#102) * Added config file (JSON or YAML) * Renamed linter.initalize to linter.init Shorter and consistent with how config turned out. * Fixed linter tests * Updated jekyll dependency yawn * Updated dependencies * Enabled path-keys-no-trailing-slash (#104) * Fixed oas-linter changes for notEndWith * Enabled path-keys-no-trailing-slash * Published v0.8.0-dev3 * Changelog typo * Removed common now oas-kit does all that * Fixed verbose (quiet was also verbose!) (#111) * Fix verbose in 0.8.0-devX * Mention folder/file writing bug in changelog. * Got rid of wework rules. Dont need em (#110) * Release v0.8.0
1 parent 82d4fd2 commit b1425e5

25 files changed

+827
-1339
lines changed

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,31 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.8.0] - 2018-08-09
8+
### Changed
9+
- Switched to using [oas-kit] for resolving and validating
10+
- Moved `short-summary` from `wework` to `strict` rules ([#110])
11+
- YAML files were previously loaded in "JSON mode", which meant duplicate keys were allowed. They will now error ([#108])
12+
### Added
13+
- Config files can be passed with `-c` (defaults to `speccy.yaml`). See [README](./README.md) for more information
14+
- Enabled `path-keys-no-trailing-slash` now oas-resolver can handle keys for lint rules
15+
- Enabled [better-ajv-errors][] for beautiful validation errors. Linter errors remain unchanged
16+
### Fixed
17+
- Resolving to a file would silently fail when writing to a folder that did not exist
18+
### Removed
19+
- Got rid of `wework` rules, as the last rule was moved to `strict` ([#110])
20+
721
## [0.7.3] - 2018-06-19
822
### Added
923
- Provide "More Info" links in linter errors, so users understand the reasoning behind various rules. ([#78])
1024

1125

1226
[#90]: https://github.com/wework/speccy/pull/90
27+
[#108]: https://github.com/wework/speccy/pull/108
28+
[#110]: https://github.com/wework/speccy/pull/110
29+
[better-ajv-errors]: https://github.com/atlassian/better-ajv-errors
30+
[oas-kit]: https://github.com/Mermade/oas-kit
31+
1332

1433
## [0.7.2] - 2018-05-31
1534
### Fixed

README.md

+39-6
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@ If you want to run speccy on OpenAPI (f.k.a Swagger) v2.0 specs, run it through
2323
```
2424
Usage: speccy <command>
2525
26+
2627
Options:
2728
28-
-V, --version output the version number
29-
-h, --help output usage information
29+
-V, --version output the version number
30+
-c, --config [configFile] config file (containing JSON/YAML). See README for potential values.
31+
-h, --help output usage information
32+
3033
3134
Commands:
3235
33-
lint [options] <file-or-url> ensure specs are not just valid OpenAPI, but lint against specified rules
34-
resolve [options] <file-or-url> pull in external $ref files to create one mega-file
35-
serve [options] <file-or-url> view specifications in beautiful human readable documentation
36+
lint [options] <file-or-url> ensure specs are not just valid OpenAPI, but lint against specified rules
37+
resolve [options] <file-or-url> pull in external $ref files to create one mega-file
38+
serve [options] <file-or-url> view specifications in beautiful human readable documentation
3639
```
3740

3841
### Lint Command
@@ -117,11 +120,41 @@ Options:
117120
-h, --help output usage information
118121
```
119122

123+
### Config File
124+
125+
To avoid needing to send command line options and switches every time, a config file can be used. Create
126+
a `speccy.yaml` in the root of your project.
127+
128+
Example:
129+
```yaml
130+
# Convert JSON Schema-proper to OpenAPI-flavoured Schema Objects
131+
jsonSchema: true
132+
# Keep the noise down
133+
quiet: true
134+
# Output a lot of information about what is happening (wont work if you have quiet on)
135+
verbose: true
136+
# Rules specific to the lint command
137+
lint:
138+
# rules files to load
139+
rules:
140+
- strict
141+
- ./some/local/rules.json
142+
- https://example.org/my-rules.json
143+
# rules to skip
144+
skip:
145+
- info-contact
146+
# Rules specific to the resolve command
147+
resolve:
148+
output: foo.yaml
149+
# Rules specific to the serve command
150+
serve:
151+
port: 8001
152+
```
153+
120154
### Calling Speccy from Code
121155
122156
Not just a command line tool, speccy can be used to normalize machine-readable specifications.
123157
124-
125158
The loader object will return a promise that resolves to an object containing
126159
the specification. For example:
127160

docs/Gemfile.lock

+1-9
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ GEM
88
tzinfo (~> 1.1)
99
addressable (2.5.2)
1010
public_suffix (>= 2.0.2, < 4.0)
11-
autoprefixer-rails (8.6.3)
12-
execjs
13-
bootstrap (4.1.1)
14-
autoprefixer-rails (>= 6.0.3)
15-
popper_js (>= 1.12.9, < 2)
16-
sass (>= 3.5.2)
1711
coffee-script (2.4.1)
1812
coffee-script-source
1913
execjs
@@ -229,7 +223,6 @@ GEM
229223
sawyer (~> 0.8.0, >= 0.5.3)
230224
pathutil (0.16.1)
231225
forwardable-extended (~> 2.6)
232-
popper_js (1.12.9)
233226
public_suffix (2.0.5)
234227
rack (1.6.10)
235228
rb-fsevent (0.10.3)
@@ -249,7 +242,7 @@ GEM
249242
sawyer (0.8.1)
250243
addressable (>= 2.3.5, < 2.6)
251244
faraday (~> 0.8, < 1.0)
252-
sprockets (3.7.1)
245+
sprockets (3.7.2)
253246
concurrent-ruby (~> 1.0)
254247
rack (> 1, < 3)
255248
terminal-table (1.8.0)
@@ -265,7 +258,6 @@ PLATFORMS
265258
ruby
266259

267260
DEPENDENCIES
268-
bootstrap (~> 4.1)
269261
github-pages
270262
jekyll-assets
271263
jekyll-seo-tag

docs/index.md

-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ There are going to be different things people are interested in, so the [default
5757

5858
There are [strict rules][rules-strict] which demand more contact details, "real" domains, a license, and requires tags have a description!
5959

60-
There are also [wework rules][rules-wework], building things we consider important on top of the strict rules; keeping summaries short (so they fit into ReDoc navigation for example).
61-
6260
#### Rules
6361

6462
Rule actions from the [default rules][rules-default] will be used if no rules file is specified. Right now there are only the three bundled options, but supporting custom rules files via local path and URL is on the roadmap.

lib/common.js

-54
This file was deleted.

lib/config.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'use strict';
2+
3+
const nconf = require('nconf');
4+
5+
nconf.formats.yaml = require('nconf-yaml');
6+
7+
class Config {
8+
9+
init(args) {
10+
const configFile = args.config || './speccy.yaml';
11+
12+
this.load(configFile, {
13+
quiet: args.quiet,
14+
jsonSchema: args.jsonSchema,
15+
verbose: args.verbose,
16+
// Command specific options
17+
lint: {
18+
rules: args.rules,
19+
skip: args.skip,
20+
},
21+
resolve: {
22+
output: args.output,
23+
},
24+
serve: {
25+
port: args.port,
26+
}
27+
});
28+
}
29+
30+
load(file, supplied) {
31+
// 1, check the supplied values
32+
nconf.add('supplied', {
33+
type: 'literal',
34+
store: this.cleanObject(supplied),
35+
});
36+
37+
// 2, look in config file (e.g: speccy.yaml)
38+
nconf.add('local', {
39+
type: 'file',
40+
format: nconf.formats.yaml,
41+
file,
42+
});
43+
}
44+
45+
get(key, defaultValue) {
46+
// Search through all known stores for the value
47+
const value = nconf.get(key);
48+
return (value === undefined) ? defaultValue : value;
49+
}
50+
51+
// Don't want an object full of null
52+
cleanObject(object) {
53+
const cleaned = {};
54+
Object.keys(object).forEach(key => {
55+
const value = object[key];
56+
if (value === undefined || value === null) {
57+
return;
58+
} else if (typeof value === "object") {
59+
return cleaned[key] = this.cleanObject(value);
60+
} else {
61+
cleaned[key] = value;
62+
}
63+
});
64+
return cleaned;
65+
}
66+
}
67+
68+
module.exports = new Config;

lib/linter.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const ensureRule = (context, rule, shouldAssertion) => {
2121

2222
let activeRules = {};
2323

24-
const initialize = () => {
24+
const init = () => {
2525
activeRules = {};
2626
};
2727

@@ -47,7 +47,7 @@ const relevantRules = skipRules => {
4747
return rules.filter(rule => skipRules.indexOf(rule.name) === -1);
4848
}
4949

50-
const lint = (objectName, object, options = {}) => {
50+
const lint = (objectName, object, key, options = {}) => {
5151
const { skip } = options;
5252

5353
const rules = relevantRules(skip);
@@ -166,10 +166,16 @@ const lint = (objectName, object, options = {}) => {
166166
}
167167
}
168168
if (rule.notEndWith) {
169-
const { value, property } = rule.notEndWith;
170-
ensure(rule, () => {
171-
should(object[property]).not.endWith(value);
172-
});
169+
const { omit, property, value } = rule.notEndWith;
170+
let propertyValue = (property === '$key') ? key : object[property];
171+
if (typeof propertyValue === 'string') {
172+
if (omit) {
173+
propertyValue = propertyValue.replace(omit,'');
174+
}
175+
ensure(rule, () => {
176+
propertyValue.should.not.endWith(value);
177+
});
178+
}
173179
}
174180
if (rule.maxLength) {
175181
const { value, property } = rule.maxLength;
@@ -193,6 +199,6 @@ const lint = (objectName, object, options = {}) => {
193199
module.exports = {
194200
createNewRule,
195201
createNewRules,
196-
initialize,
202+
init,
197203
lint,
198204
};

0 commit comments

Comments
 (0)