From 5318aa2cb1bd34bde897059abfd2e77baa82f88b Mon Sep 17 00:00:00 2001 From: Reuven Harrison Date: Mon, 21 Oct 2024 15:54:02 +0300 Subject: [PATCH] feat: add NONE level to allow disabling checks (#630) * add NONE level to allow disabling checks * update documentation --- checker/level.go | 5 ++++- checker/level_test.go | 12 +++++------- data/severity-levels.txt | 5 +++-- docs/BREAKING-CHANGES.md | 8 ++++++++ 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/checker/level.go b/checker/level.go index 24c4c39f..be3e7d5b 100644 --- a/checker/level.go +++ b/checker/level.go @@ -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) { @@ -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) } diff --git a/checker/level_test.go b/checker/level_test.go index 8bc92359..cf9885bf 100644 --- a/checker/level_test.go +++ b/checker/level_test.go @@ -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) } diff --git a/data/severity-levels.txt b/data/severity-levels.txt index d84a618c..e2768f6d 100644 --- a/data/severity-levels.txt +++ b/data/severity-levels.txt @@ -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 diff --git a/docs/BREAKING-CHANGES.md b/docs/BREAKING-CHANGES.md index 8c1cd40c..8476d59d 100644 --- a/docs/BREAKING-CHANGES.md +++ b/docs/BREAKING-CHANGES.md @@ -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).