Skip to content

Commit 5ffcd43

Browse files
authored
feat(validation): add support for ignoring errors (#126)
Refs #3
1 parent 9332777 commit 5ffcd43

File tree

6 files changed

+752
-12
lines changed

6 files changed

+752
-12
lines changed

.github/workflows/main.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,15 @@ jobs:
5252
uses: char0n/swagger-editor-validate@master
5353
with:
5454
definition-file: examples/openapi-2-0.yaml
55+
56+
test_swagger_editor_ignore_error:
57+
runs-on: ubuntu-latest
58+
name: Swagger Editor Ignore Errors
59+
60+
steps:
61+
- uses: actions/checkout@v2
62+
- name: Validate OpenAPI definition
63+
uses: char0n/swagger-editor-validate@master
64+
with:
65+
definition-file: examples/openapi-2-0-ignore-error.yaml
66+
ignore-error: examples/ignore-error.js

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ file is going to be validated. Default `https://editor.swagger.io/`.
2626
**Required** Defines path of [OAS](https://github.com/OAI/OpenAPI-Specification) definition file that exists
2727
as a physical file in your repository.
2828

29+
### `ignore-error`
30+
31+
**Optional** Defines path to JavaScript file containing predicate for determining if the error should be ignored or not.
32+
2933

3034
## Example usage
3135

action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ inputs:
99
definition-file:
1010
description: Path to definition file
1111
required: true
12+
ignore-error:
13+
description: JavaScript file containing predicate for determining if the error should be ignored or not
14+
required: false
1215
runs:
1316
using: composite
1417
steps:
1518
- run: cd ${{ github.action_path }} && npm install
1619
shell: bash
17-
- run: cd ${{ github.action_path }} && SWAGGER_EDITOR_URL=${{ inputs.swagger-editor-url }} DEFINITION_FILE=${{ inputs.definition-file }} node src/index.js
20+
- run: cd ${{ github.action_path }} && SWAGGER_EDITOR_URL=${{ inputs.swagger-editor-url }} DEFINITION_FILE=${{ inputs.definition-file }} IGNORE_ERROR=${{ inputs.ignore-error }} node src/index.js
1821
shell: bash
1922
branding:
2023
icon: 'file-text'

examples/ignore-error.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const shouldIgnoreError = (error) => {
2+
if (error.lineNo === 2) {
3+
if (/should NOT have additional properties\s*additionalProperty: contact1/mg.test(error.message)) {
4+
return true;
5+
}
6+
}
7+
8+
return false;
9+
}
10+
11+
module.exports = shouldIgnoreError;

0 commit comments

Comments
 (0)