Skip to content

Commit

Permalink
feat: add NONE level to allow disabling checks (#630)
Browse files Browse the repository at this point in the history
* add NONE level to allow disabling checks

* update documentation
  • Loading branch information
reuvenharrison authored Oct 21, 2024
1 parent 2d9310d commit 5318aa2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
5 changes: 4 additions & 1 deletion checker/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const (
ERR Level = 3
WARN Level = 2
INFO Level = 1
INVALID Level = 0
NONE Level = 0
INVALID Level = -1
)

func NewLevel(level string) (Level, error) {
Expand All @@ -28,6 +29,8 @@ func NewLevel(level string) (Level, error) {
return WARN, nil
case "INFO", "info":
return INFO, nil
case "NONE", "none":
return NONE, nil
}
return INVALID, fmt.Errorf("invalid level %s", level)
}
Expand Down
12 changes: 5 additions & 7 deletions checker/level_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ func TestProcessSeverityLevels_InvalidFile(t *testing.T) {

func TestProcessSeverityLevels_OK(t *testing.T) {
m, err := checker.ProcessSeverityLevels("../data/severity-levels.txt")
require.Equal(t, map[string]checker.Level{"api-security-removed": 2, "request-parameter-enum-value-added": 3}, m)
require.NoError(t, err)
}

func TestProcessSeverityLevels_WrongFlags(t *testing.T) {
m, err := checker.ProcessSeverityLevels("../data/severity-levels.txt")
require.Equal(t, map[string]checker.Level{"api-security-removed": 2, "request-parameter-enum-value-added": 3}, m)
require.Equal(t, map[string]checker.Level{
"api-security-removed": checker.WARN,
"request-parameter-enum-value-added": checker.ERR,
"request-read-only-property-enum-value-removed": checker.NONE,
}, m)
require.NoError(t, err)
}

Expand Down
5 changes: 3 additions & 2 deletions data/severity-levels.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
api-security-removed warn
request-parameter-enum-value-added err
api-security-removed warn
request-parameter-enum-value-added err
request-read-only-property-enum-value-removed none
8 changes: 8 additions & 0 deletions docs/BREAKING-CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ Where the file `oasdiff-levels.txt` contains a single line:
api-security-removed err
```

Checks can be customized with the following levels:
| Custom Level | Check Status |
| ------------- | ------------- |
| err | Enabled with level ERR |
| warn | Enabled with level WARN |
| info | Enabled with level INFO |
| none | Disabled |

### Customizing Breaking Changes Checks
If you encounter a change that isn't reported, you may:
1. Run `oasdiff checks` to see if the check is available, and [customize the level as needed](#customizing-severity-levels).
Expand Down

0 comments on commit 5318aa2

Please sign in to comment.