Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ module.exports = {
// set max line length to 120
'max-len': ['error', { code: 120 }],
},
overrides: [
{
files: ['scripts/**/*.js'],
rules: {
'import/no-extraneous-dependencies': ['error', { devDependencies: true }],
},
},
],
};
1 change: 1 addition & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm run validate
- run: npm test
- run: npm run lint

Expand Down
1 change: 1 addition & 0 deletions aep/0004.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
rules:
aep-0004-x-aep-resource-structure:
description: x-aep-resource must have correct structure with required fields (singular, plural)
Expand Down
1 change: 1 addition & 0 deletions aep/0122.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
aliases:
AepResource:
description: A schema that represents an AEP resource
Expand Down
1 change: 1 addition & 0 deletions aep/0131.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
aliases:
GetOperation:
description: A Get operation is a get on path that ends in a path parameter
Expand Down
1 change: 1 addition & 0 deletions aep/0132.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
aliases:
ListOperation:
description: A list operation is a get on path that does not end in a path parameter
Expand Down
1 change: 1 addition & 0 deletions aep/0133.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
aliases:
CreateOperation:
description: A create operation is a post on path without a ":" in the final segment
Expand Down
1 change: 1 addition & 0 deletions aep/0134.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
aliases:
UpdateOperation:
description: An Update method is a patch on path that ends in a path parameter
Expand Down
1 change: 1 addition & 0 deletions aep/0135.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
aliases:
DeleteOperation:
description: A Delete operation is a delete on path that ends in a path parameter
Expand Down
1 change: 1 addition & 0 deletions aep/0136.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
aliases:
CustomOperation:
description: A custom method is identified by a path containing a colon (:) before the verb
Expand Down
1 change: 1 addition & 0 deletions aep/0137.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
aliases:
ApplyOperation:
description: An Apply method is a put on path that ends in a path parameter
Expand Down
1 change: 1 addition & 0 deletions aep/0140.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
rules:
aep-140-boolean-property-naming:
description: 'Boolean properties should omit the prefix "is".'
Expand Down
1 change: 1 addition & 0 deletions aep/0142.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
functionsDir: ../functions
functions:
- aep-142-time-field-type
Expand Down
1 change: 1 addition & 0 deletions aep/0143.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
functionsDir: ../functions
functions:
- standardized-codes
Expand Down
1 change: 1 addition & 0 deletions aep/0144.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
aliases:
AddRemovePathItem:
description: An Update Array operation is a post request that updates an array with add or remove operation
Expand Down
1 change: 1 addition & 0 deletions aep/0151.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
aliases:
LongRunningOperation:
description: An operation that returns 202 Accepted for long-running operations
Expand Down
1 change: 1 addition & 0 deletions aep/0158.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
aliases:
ListOperation:
description: A list operation is a get on path that does not end in a path parameter
Expand Down
1 change: 1 addition & 0 deletions aep/0193.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
rules:
aep-193-error-response-schema:
description: Error response body should contain all required fields according to AEP-193.
Expand Down
68 changes: 58 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
"access": "public"
},
"scripts": {
"lint": "prettier --check . && eslint --cache --quiet --ext '.js' functions test",
"lint-fix": "prettier --write . && eslint --cache --quiet --ext '.js' --fix functions test",
"lint": "prettier --check . && eslint --cache --quiet --ext '.js' functions scripts test",
"lint-fix": "prettier --write . && eslint --cache --quiet --ext '.js' --fix functions scripts test",
"test": "jest --coverage",
"validate": "node scripts/validate-ruleset.js",
"release:patch": "./scripts/prepare-release.sh patch",
"release:minor": "./scripts/prepare-release.sh minor",
"release:major": "./scripts/prepare-release.sh major"
Expand All @@ -31,11 +32,13 @@
"@stoplight/spectral-ruleset-migrator": "^1.11.1",
"@stoplight/spectral-rulesets": "^1.21.3",
"ajv": "^8.6.2",
"ajv-formats": "^3.0.1",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.23.4",
"jest": "^29.7.0",
"js-yaml": "^4.1.1",
"prettier": "^3.2.5"
},
"jest": {
Expand Down
56 changes: 56 additions & 0 deletions scripts/validate-ruleset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env node
// Validates spectral.yaml and aep/*.yaml against the remote Spectral ruleset
// JSON schema so authoring mistakes are caught in CI.

const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');
const Ajv2020 = require('ajv/dist/2020');
const addFormats = require('ajv-formats');

const SCHEMA_URL = 'https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json';

const ROOT = path.join(__dirname, '..');
const FILES = [
'spectral.yaml',
...fs
.readdirSync(path.join(ROOT, 'aep'))
.filter((f) => f.endsWith('.yaml'))
.map((f) => path.join('aep', f)),
];

async function main() {
const res = await fetch(SCHEMA_URL);
if (!res.ok) {
throw new Error(`Failed to fetch ruleset schema: ${res.status} ${res.statusText}`);
}
const schema = await res.json();

const ajv = new Ajv2020({ allErrors: true, strict: false });
addFormats(ajv);
const validate = ajv.compile(schema);

let hasErrors = false;
FILES.forEach((file) => {
const fullPath = path.join(ROOT, file);
const doc = yaml.load(fs.readFileSync(fullPath, 'utf8'));
if (!validate(doc)) {
hasErrors = true;
console.error(`\n${file} failed schema validation:`);
validate.errors.forEach((err) => {
console.error(` ${err.instancePath || '/'} ${err.message}`);
});
} else {
console.log(`${file}: OK`);
}
});

if (hasErrors) {
process.exitCode = 1;
}
}

main().catch((err) => {
console.error(err.message);
process.exitCode = 1;
});
1 change: 1 addition & 0 deletions spectral.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# yaml-language-server: $schema=https://spec.spotlight-rules.com/schema/v1/spectral-ruleset.schema.json
extends:
- spectral:oas
- ./aep/0004.yaml
Expand Down
Loading