Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add NONE level to allow disabling checks #630

Merged
merged 2 commits into from
Oct 21, 2024
Merged
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
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
Loading