Skip to content

Commit c68f852

Browse files
committed
chore(api): Use Spectral for linting OpenAPI
1 parent 876e200 commit c68f852

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

api-docs/.spectral.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extends: ["spectral:oas", "spectral:asyncapi", "spectral:arazzo"]

api-docs/scripts/validate-spec.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ const SwaggerParser = require('@apidevtools/swagger-parser');
55
const { execSync } = require('child_process');
66
const spec = '/Users/ja/Documents/GitHub/docs-v2/api-docs/cloud/v2/ref.yml'
77

8-
async function detectCircularRefs() {
9-
try {
10-
const api = await SwaggerParser.validate(spec);
11-
console.log('API is valid:', api);
12-
} catch (err) {
13-
if (err.message.includes('Circular $ref pointer found')) {
14-
console.error('Circular reference detected:', err);
15-
} else {
16-
console.error('API validation failed:', err);
17-
}
18-
}
19-
}
208

219
// Function to execute shell commands
2210
const execCommand = (command) => {
@@ -30,15 +18,20 @@ const execCommand = (command) => {
3018

3119
function validate() {
3220

33-
detectCircularRefs();
21+
// detectCircularRefs();
22+
23+
// // swagger-cli validate
24+
// execCommand(`npx swagger-cli validate ${spec}`);
25+
26+
// // speccy lint. Treat $ref like JSON schema and convert to OpenAPI Schema Objects.
27+
// execCommand(`npx speccy lint -j -v ${spec}`);
3428

35-
// swagger-cli validate
36-
execCommand(`npx swagger-cli validate ${spec}`);
29+
// execCommand(`npx @redocly/cli lint ${spec}`);
3730

38-
// speccy lint. Treat $ref like JSON schema and convert to OpenAPI Schema Objects.
39-
execCommand(`npx speccy lint -j -v ${spec}`);
31+
// Create a Spectral ruleset file
32+
// Spectral is a flexible JSON/YAML linter, formatter, and style checker for OpenAPI v2, v3.0, v3.1, and AsyncAPI v2.0.
33+
execCommand(`npx @stoplight/spectral-cli lint ${spec} --ruleset ./api-docs/.spectral.yaml`); // --ruleset myruleset.yaml
4034

41-
execCommand(`npx @redocly/cli lint ${spec}`);
4235
}
4336

4437
validate();

0 commit comments

Comments
 (0)