-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breaking change check: New request required default param on existing…
… path (#376)
- Loading branch information
1 parent
1bf3971
commit b3677f4
Showing
9 changed files
with
267 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package checker | ||
|
||
import ( | ||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
func NewRequestNonPathDefaultParameterCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config Config) Changes { | ||
result := make(Changes, 0) | ||
if diffReport.PathsDiff == nil || len(diffReport.PathsDiff.Modified) == 0 { | ||
return result | ||
} | ||
for path, pathItem := range diffReport.PathsDiff.Modified { | ||
if pathItem.ParametersDiff == nil || pathItem.Revision == nil || len(pathItem.Revision.Operations()) == 0 { | ||
continue | ||
} | ||
|
||
for paramLoc := range pathItem.ParametersDiff.Added { | ||
if paramLoc == "path" { | ||
continue | ||
} | ||
|
||
for _, param := range pathItem.Revision.Parameters { | ||
|
||
id := "new-required-request-default-parameter-to-existing-path" | ||
level := ERR | ||
if !param.Value.Required { | ||
id = "new-optional-request-default-parameter-to-existing-path" | ||
level = INFO | ||
} | ||
|
||
for operation, operationItem := range pathItem.Revision.Operations() { | ||
|
||
// TODO: if base operation had this param individually (not through the path) - continue | ||
|
||
result = append(result, ApiChange{ | ||
Id: id, | ||
Level: level, | ||
Text: config.Localize(id, ColorizedValue(paramLoc), ColorizedValue(param.Value.Name)), | ||
Operation: operation, | ||
OperationId: operationItem.OperationID, | ||
Path: path, | ||
Source: (*operationsSources)[operationItem], | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
return result | ||
} |
117 changes: 117 additions & 0 deletions
117
checker/check-new-request-non-path-default-parameter_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package checker_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tufin/oasdiff/checker" | ||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
// BC: new header, query and cookie required request default param is breaking | ||
func TestNewRequestNonPathParameter_DetectsNewRequiredPathsAndNewOperations(t *testing.T) { | ||
s1, err := open("../data/request_params/base.yaml") | ||
require.NoError(t, err) | ||
|
||
s2, err := open("../data/request_params/required-request-params.yaml") | ||
require.NoError(t, err) | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(&diff.Config{}, s1, s2) | ||
require.NoError(t, err) | ||
|
||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.NewRequestNonPathDefaultParameterCheck), d, osm, checker.INFO) | ||
require.NotEmpty(t, errs) | ||
require.Len(t, errs, 9) | ||
|
||
require.ElementsMatch(t, []checker.ApiChange{ | ||
{ | ||
Id: "new-required-request-default-parameter-to-existing-path", | ||
Text: "added the new required 'query' request parameter 'version' to all path's operations", | ||
Comment: "", | ||
Level: 3, | ||
Operation: "GET", | ||
OperationId: "getTest", | ||
Path: "/api/test1", | ||
Source: "../data/request_params/required-request-params.yaml", | ||
}, | ||
{ | ||
Id: "new-required-request-default-parameter-to-existing-path", | ||
Text: "added the new required 'query' request parameter 'version' to all path's operations", | ||
Comment: "", | ||
Level: 3, | ||
Operation: "POST", | ||
OperationId: "", | ||
Path: "/api/test1", | ||
Source: "../data/request_params/required-request-params.yaml", | ||
}, | ||
{ | ||
Id: "new-required-request-default-parameter-to-existing-path", | ||
Text: "added the new required 'header' request parameter 'id' to all path's operations", | ||
Comment: "", | ||
Level: 3, | ||
Operation: "GET", | ||
OperationId: "getTest", | ||
Path: "/api/test2", | ||
Source: "../data/request_params/required-request-params.yaml", | ||
}, | ||
{ | ||
Id: "new-required-request-default-parameter-to-existing-path", | ||
Text: "added the new required 'query' request parameter 'id' to all path's operations", | ||
Comment: "", | ||
Level: 3, | ||
Operation: "GET", | ||
OperationId: "getTest", | ||
Path: "/api/test2", | ||
Source: "../data/request_params/required-request-params.yaml", | ||
}, | ||
{ | ||
Id: "new-required-request-default-parameter-to-existing-path", | ||
Text: "added the new required 'header' request parameter 'If-None-Match' to all path's operations", | ||
Comment: "", | ||
Level: 3, | ||
Operation: "GET", | ||
OperationId: "getTest", | ||
Path: "/api/test3", | ||
Source: "../data/request_params/required-request-params.yaml", | ||
}, | ||
{ | ||
Id: "new-optional-request-default-parameter-to-existing-path", | ||
Text: "added the new optional 'query' request parameter 'optionalQueryParam' to all path's operations", | ||
Comment: "", | ||
Level: 1, | ||
Operation: "GET", | ||
OperationId: "getTest", | ||
Path: "/api/test1", | ||
Source: "../data/request_params/required-request-params.yaml", | ||
}, | ||
{ | ||
Id: "new-optional-request-default-parameter-to-existing-path", | ||
Text: "added the new optional 'query' request parameter 'optionalQueryParam' to all path's operations", | ||
Comment: "", | ||
Level: 1, | ||
Operation: "POST", | ||
OperationId: "", | ||
Path: "/api/test1", | ||
Source: "../data/request_params/required-request-params.yaml", | ||
}, | ||
{ | ||
Id: "new-optional-request-default-parameter-to-existing-path", | ||
Text: "added the new optional 'header' request parameter 'optionalHeaderParam' to all path's operations", | ||
Comment: "", | ||
Level: 1, | ||
Operation: "GET", | ||
OperationId: "getTest", | ||
Path: "/api/test2", | ||
Source: "../data/request_params/required-request-params.yaml", | ||
}, | ||
{ | ||
Id: "new-optional-request-default-parameter-to-existing-path", | ||
Text: "added the new optional 'query' request parameter 'optionalHeaderParam' to all path's operations", | ||
Comment: "", | ||
Level: 1, | ||
Operation: "GET", | ||
OperationId: "getTest", | ||
Path: "/api/test2", | ||
Source: "../data/request_params/required-request-params.yaml", | ||
}}, errs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
info: | ||
title: Tufin | ||
version: 1.0.0 | ||
openapi: 3.0.3 | ||
paths: | ||
/api/test1: | ||
parameters: | ||
- in: query | ||
name: version | ||
required: true | ||
schema: | ||
type: string | ||
- in: query | ||
name: optionalQueryParam | ||
required: false | ||
schema: | ||
type: string | ||
get: | ||
operationId: getTest | ||
parameters: | ||
- in: header | ||
name: X-NewRequestHeaderParam | ||
required: false | ||
schema: | ||
type: string | ||
responses: | ||
200: | ||
description: OK | ||
post: | ||
responses: | ||
201: | ||
description: OK | ||
|
||
/api/test2: | ||
parameters: | ||
- in: query | ||
name: id | ||
required: true | ||
schema: | ||
type: string | ||
- in: header | ||
name: optionalHeaderParam | ||
required: false | ||
schema: | ||
type: string | ||
get: | ||
operationId: getTest | ||
parameters: | ||
- in: query | ||
name: newQueryParam | ||
required: false | ||
schema: | ||
type: string | ||
responses: | ||
200: | ||
description: OK | ||
|
||
/api/test3: | ||
parameters: | ||
- in: header | ||
name: If-None-Match | ||
required: true | ||
get: | ||
operationId: getTest | ||
parameters: | ||
- in: cookie | ||
name: csrf-token | ||
required: false | ||
schema: | ||
type: string | ||
responses: | ||
200: | ||
description: OK | ||
|
||
/api/test4: | ||
parameters: | ||
- in: query | ||
name: emptyPath2 | ||
required: true | ||
schema: | ||
type: string |