Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

example: run custom redocly-cli rules as part of portal build #241

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions openapi/petstore.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
openapi: 3.0.3
security: []
servers:
- url: '//petstore.swagger.io/v2'
info:
Expand Down
1 change: 1 addition & 0 deletions openapi/reference.page.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ settings:
- lang: curl
- lang: JavaScript
- lang: Node.js

14 changes: 14 additions & 0 deletions plugins/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const OperationIdNotTest = require('./rules/operation-id-not-test');
const id = 'plugin';

/** @type {import('@redocly/cli').DecoratorsConfig} */
const rules = {
oas3: {
'operation-id-not-test': OperationIdNotTest,
},
};

module.exports = {
id,
rules,
};
14 changes: 14 additions & 0 deletions plugins/rules/operation-id-not-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = OperationIdNotTest;

function OperationIdNotTest() {
return {
Operation(operation, ctx) {
if (operation.operationId === 'test') {
ctx.report({
message: `operationId must be not "test"`,
location: ctx.location.child('operationId'),
});
}
},
};
}
11 changes: 11 additions & 0 deletions redocly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apis:
sample@v1:
root: openapi/petstore.yaml
rules:
plugin/operation-id-not-test:
severity: error
operation-4xx-response:
severity: off

plugins:
- "./plugins/plugin.js"