Skip to content

Commit

Permalink
Merge branch 'develop' into feat/remove-when
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Sturgeon authored Oct 24, 2019
2 parents 70fc34d + 846e8d1 commit 92f06c4
Show file tree
Hide file tree
Showing 73 changed files with 1,600 additions and 208 deletions.
9 changes: 1 addition & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@ jobs:
steps:
- install-and-test

test-node-8:
docker:
- image: circleci/node:8-browsers
steps:
- install-and-test

release:
docker:
- image: circleci/node:10
Expand All @@ -91,7 +85,7 @@ jobs:
else
npm publish
fi
- run: yarn build.binary
- run: npx pkg . --targets linux,macos
- persist_to_workspace:
root: ./
paths:
Expand All @@ -116,7 +110,6 @@ workflows:
- test-node-latest
- test-node-12
- test-node-10
- test-node-8
release:
jobs:
- release:
Expand Down
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8

[*.{ts,js,yaml}]
indent_style = space
indent_size = 2

[*.{ts,js}]
trim_trailing_whitespace = true
insert_final_newline = true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/binaries
/rulesets
/src/__tests__/__fixtures__/oas-functions.json
/__karma__/__fixtures__/
/test-harness/tmp/

# testing
Expand Down
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.2.0] - 2019-10-08

### Features
- CLI: glob patterns and multiple paths are allowed [#534](https://github.com/stoplightio/spectral/issues/534)
- CLI: control fail severity and result display [#368](https://github.com/stoplightio/spectral/issues/368)
- CLI: new formatter - JUnit [#478](https://github.com/stoplightio/spectral/issues/478)
- CLI: add possibility to proxy requests [#446](https://github.com/stoplightio/spectral/issues/446)
- Built-in ruleset formats targeting JSON Schema files [#571](https://github.com/stoplightio/spectral/issues/571)
- `{{value}}` and `{{path}}` can be used in messages [#520](https://github.com/stoplightio/spectral/issues/520) [#572](https://github.com/stoplightio/spectral/issues/572)

### Deprecated
- `when` Rule property is deprecated [#585](https://github.com/stoplightio/spectral/issues/585)

### Changed
- Validation results produced by `alphabetical` function are more meaningful [#613](https://github.com/stoplightio/spectral/pull/613)
- Enhanced JSON Schema enum validation [#579](https://github.com/stoplightio/spectral/pull/579)
- Improved messages generated by `oasPathParam` function [#537](https://github.com/stoplightio/spectral/issues/537)
- CLI: the amount of enabled rules is now displayed if you run Spectral with `--verbose` flag [#435](https://github.com/stoplightio/spectral/issues/435)
- Stricter source matching for errors [#615](https://github.com/stoplightio/spectral/pull/615)

### Fixed
- `schema` function can validate falsy values [10e5d1c](https://github.com/stoplightio/spectral/commit/10e5d1c0262790ad8349e25b2e5517e7ae15402c)
- `schema` function can validate Draft 6 and Draft 7 JSON Schemas [ea2ddff](https://github.com/stoplightio/spectral/commit/ea2ddffd58a2a92f483147fec195e0a8fe80c07b)
- Parameters in links objects are not linted for not having a description property. [#272](https://github.com/stoplightio/spectral/issues/272)
- More accurate ranges for errors occurring in referenced files [6986b82](https://github.com/stoplightio/spectral/commit/6986b82bee725aa8733c2d07ccc65a99e14c22c6)
- CLI: stylish formatter reports `info` and `hint` severity levels correctly [#565](https://github.com/stoplightio/spectral/issues/565)

## [4.1.1] - 2019-09-05

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/custom-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module.exports = (obj) => {
};
```

You do not need to provide any shim for `Object.entries` or use [regenerator](https://facebook.github.io/regenerator/) for `for of` loop. As stated, you cannot use ES Modules, so the following code is considered sa invalid and won't work correctly.
You do not need to provide any shim for `Object.entries` or use [regenerator](https://facebook.github.io/regenerator/) for the `for of` loop. As stated, you cannot use ES Modules, so the following code is considered as invalid and won't work correctly.

```js
export default (obj) => {
Expand All @@ -153,4 +153,4 @@ module.exports = (obj) => {

If you have any module system, you need to use some bundler, preferably Rollup.js as it generates efficient bundles.

We are still evaluating the idea of supporting ESModule and perhaps we decide to bring support for ES Modules at some point, yet for now you cannot use them.
We are still evaluating the idea of supporting ESModule and perhaps we will decide to bring support for ES Modules at some point, yet for now you cannot use them.
30 changes: 30 additions & 0 deletions docs/reference/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ keyedBy | key to sort an object by | no
openapi-tags-alphabetical:
description: OpenAPI object should have alphabetical `tags`.
type: style
recommended: true
given: "$"
then:
field: tags
Expand Down Expand Up @@ -167,6 +168,35 @@ The value must be `undefined`. When combined with `field: foo` on an object the

_**Note:** Due to the way YAML works, just having `foo: ` with no value set is not the same as being `undefined`. This would be `falsy`.

## unreferencedReusableObject

This function identifies unreferenced objects within a document.

For it to properly operate, `given` should point to the member holding the potential reusable objects.

_Warning:_ This function may identify false positives when used against a specification that acts as a library (a container storing reusable objects, leveraged by other specifications that reference those objects).

<!-- title: functionOptions -->

name | description | required?
---------|----------|---------
reusableObjectsLocation | a local json pointer to the document member holding the reusable objects (eg. `#/definitions` for an OAS2 document, `#/components/schemas` for an OAS3 document). | yes

<!-- title: example -->

``` yaml
unused-definition:
description: Potentially unused definition has been detected.
recommended: true
type: style
resolved: false
given: "$.definitions"
then:
function: unreferencedReusableObject
functionOptions:
reusableObjectsLocation: "#/definitions"
```

## xor

Communicate that only one of these properties is allowed, and no more than one of them.
Expand Down
32 changes: 29 additions & 3 deletions docs/reference/openapi-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ Operation should have non-empty `tags` array.

**Recommended:** Yes

### operation-tag-defined

Operation tags should be defined in global tags.

**Recommended:** Yes

### path-declarations-must-exist

Path parameter declarations cannot be empty, ex.`/given/{}` is invalid.
Expand Down Expand Up @@ -409,7 +415,7 @@ Server URL should not have a trailing slash.

**Recommended:** Yes

### model-description
### definition-description

Definition `description` must be present and non-empty string.

Expand All @@ -421,6 +427,16 @@ Operation `security` values must match a scheme defined in the `securityDefiniti

**Recommended:** Yes

### unused-definition

Potential unused reusable `definition` entry has been detected.

_Warning:_ This rule may identify false positives when linting a specification
that acts as a library (a container storing reusable objects, leveraged by other
specifications that reference those objects).

**Recommended:** Yes

### valid-example

Examples must be valid against their defined schema.
Expand Down Expand Up @@ -476,7 +492,7 @@ servers:
If this is going out to the world, maybe have production and a general sandbox people can play with.


### model-description
### components-schema-description

Model `description` must be present and non-empty string.

Expand Down Expand Up @@ -532,6 +548,16 @@ servers:
- url: https://example.com/api/
```

### unused-components-schema

Potential unused reusable `schema` entry has been detected.

_Warning:_ This rule may identify false positives when linting a specification
that acts as a library (a container storing reusable objects, leveraged by other
specifications that reference those objects).

**Recommended:** Yes

### valid-example

Examples must be valid against their defined schema.
Expand All @@ -548,4 +574,4 @@ Validate structure of OpenAPI v3 specification.

Parameter objects should have a `description`.

**Recommended:** No
**Recommended:** No
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"rulesets/*"
],
"engines": {
"node": ">=8.3.0"
"node": ">=10.0"
},
"scripts": {
"build.binary": "pkg . --output ./binaries/spectral",
Expand All @@ -41,7 +41,7 @@
"compile-rulesets": "node ./scripts/compile-rulesets.js",
"inline-version": "./scripts/inline-version.js",
"lint.fix": "yarn lint --fix",
"lint": "tslint 'src/**/*.ts'",
"lint": "tsc --noEmit && tslint 'src/**/*.ts'",
"postbuild.oas-functions": "copyfiles -u 1 \"dist/rulesets/oas*/functions/*.js\" ./",
"postbuild": "yarn build.oas-functions && yarn compile-rulesets",
"prebuild": "copyfiles -u 1 \"src/rulesets/oas*/**/*.json\" dist && copyfiles -u 1 \"src/rulesets/oas*/**/*.json\" ./",
Expand All @@ -57,8 +57,9 @@
},
"dependencies": {
"@stoplight/json": "^3.1.1",
"@stoplight/json-ref-resolver": "^2.2.0",
"@stoplight/json-ref-resolver": "^3.0.1",
"@stoplight/path": "^1.2.0",
"@stoplight/ref-resolvers": "^1.1.0",
"@stoplight/types": "^11.0.0",
"@stoplight/yaml": "^3.1.0",
"abort-controller": "^3.0.0",
Expand Down Expand Up @@ -93,6 +94,7 @@
"@types/text-table": "^0.2.0",
"@types/xml2js": "^0.4.4",
"copyfiles": "^2.1.1",
"dependency-graph": "^0.8.0",
"fetch-mock": "^7.3.9",
"glob-fs": "^0.1.7",
"husky": "^3.0.0",
Expand Down
30 changes: 19 additions & 11 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,8 @@ import { terser } from 'rollup-plugin-terser';

const BASE_PATH = process.cwd();

module.exports = [
'oasOp2xxResponse',
'oasOpFormDataConsumeCheck',
'oasOpIdUnique',
'oasOpParams',
'oasOpSecurityDefined',
'oasPathParam',
'refSiblings'
].map(fn => ({
input: path.resolve(BASE_PATH, 'dist/rulesets/oas/functions', `${fn}.js`),
const processor = (folder, array) => array.map(fn => ({
input: path.resolve(BASE_PATH, folder, `${fn}.js`),
plugins: [
typescript({
tsconfig: path.join(BASE_PATH, './tsconfig.rollup.json'),
Expand All @@ -26,8 +18,24 @@ module.exports = [
terser(),
],
output: {
file: path.resolve(BASE_PATH, 'dist/rulesets/oas/functions', `${fn}.js`),
file: path.resolve(BASE_PATH, folder, `${fn}.js`),
format: 'cjs',
exports: 'named'
},
}));

module.exports = processor('dist/rulesets/oas/functions', [
'oasOp2xxResponse',
'oasOpFormDataConsumeCheck',
'oasOpIdUnique',
'oasOpParams',
'oasOpSecurityDefined',
'oasPathParam',
'refSiblings',
])
.concat(processor('dist/rulesets/oas2/functions', [
// Add here the oas2 specific functions
]))
.concat(processor('dist/rulesets/oas3/functions', [
// Add here the oas3 specific functions
]));
24 changes: 16 additions & 8 deletions scripts/generate-karma-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@
const path = require('path');
const fs = require('fs');

const target = path.join(__dirname, '../src/__tests__/__fixtures__/oas-functions.json');
const baseDir = path.join(__dirname, '../__karma__/__fixtures__/');

const fnsPath = path.join(__dirname, '../rulesets/oas/functions')
if (!fs.existsSync(baseDir)) {
fs.mkdirSync(baseDir);
}

const files = fs.readdirSync(fnsPath);
for (const spec of ['', '2', '3']) {
const target = path.join(baseDir, `oas${spec}-functions.json`);
const fnsPath = path.join(__dirname, `../rulesets/oas${spec}/functions`);
const bundledFns = {};

const bundledFns = {};
if (fs.existsSync(fnsPath)) {
const files = fs.readdirSync(fnsPath);

for (const file of files) {
bundledFns[file] = fs.readFileSync(path.join(fnsPath, file), 'utf-8')
}
for (const file of files) {
bundledFns[file] = fs.readFileSync(path.join(fnsPath, file), 'utf-8');
}
}

fs.writeFileSync(target, JSON.stringify(bundledFns, null, 2))
fs.writeFileSync(target, JSON.stringify(bundledFns, null, 2));
}
2 changes: 2 additions & 0 deletions setupJest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ let accessSpy: jest.SpyInstance;

const { readFile, access } = fs;

jest.setTimeout(10 * 1000);

beforeEach(() => {
readFileSpy = jest.spyOn(fs, 'readFile');
accessSpy = jest.spyOn(fs, 'access');
Expand Down
19 changes: 13 additions & 6 deletions setupKarma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ const oas2Schema = JSON.parse(JSON.stringify(require('./rulesets/oas2/schemas/ma
const oas3Ruleset = JSON.parse(JSON.stringify(require('./rulesets/oas3/index.json')));
const oas3Schema = JSON.parse(JSON.stringify(require('./rulesets/oas3/schemas/main.json')));

const oasFunctions = JSON.parse(JSON.stringify(require('./src/__tests__/__fixtures__/oas-functions.json')));
const oasFunctions = {
// import path used for require must be deterministic at build-time (not run-time) in case of Karma, hence no loop can be used
'': JSON.parse(JSON.stringify(require('./__karma__/__fixtures__/oas-functions.json'))),
'2': JSON.parse(JSON.stringify(require('./__karma__/__fixtures__/oas2-functions.json'))),
'3': JSON.parse(JSON.stringify(require('./__karma__/__fixtures__/oas3-functions.json'))),
};

const { fetch } = window;
let fetchMock: FetchMockSandbox;
Expand Down Expand Up @@ -40,11 +45,13 @@ beforeEach(() => {
body: JSON.parse(JSON.stringify(oas3Schema)),
});

for (const [name, fn] of Object.entries<string>(oasFunctions)) {
fetchMock.get(`https://unpkg.com/@stoplight/spectral/rulesets/oas/functions/${name}`, {
status: 200,
body: fn,
});
for (const [spec, fns] of Object.entries(oasFunctions)) {
for (const [name, fn] of Object.entries<string>(fns)) {
fetchMock.get(`https://unpkg.com/@stoplight/spectral/rulesets/oas${spec}/functions/${name}`, {
status: 200,
body: fn,
});
}
}
});

Expand Down
Loading

0 comments on commit 92f06c4

Please sign in to comment.