-
Notifications
You must be signed in to change notification settings - Fork 66
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
implement request/response allOf checkers #340
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c16bf61
implement request/response allOf checkers
tibulca 55aa919
implement request/response allOf checkers
tibulca b3f0998
implement request/response allOf checkers - PR comments
tibulca 1080077
Merge branch 'main' into allOf
tibulca 8a3acab
Merge branch 'main' into allOf
tibulca 7c5f6bd
implement request/response allOf checkers - PR comments
tibulca 5b9fcd7
Merge branch 'main' into allOf
tibulca 40a9f9a
Merge branch 'main' into allOf
tibulca d76b6a0
implement request/response allOf checkers - PR comments
tibulca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,103 @@ | ||
package checker | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
func RequestPropertyAllOfUpdated(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config Config) Changes { | ||
result := make(Changes, 0) | ||
if diffReport.PathsDiff == nil { | ||
return result | ||
} | ||
|
||
for path, pathItem := range diffReport.PathsDiff.Modified { | ||
if pathItem.OperationsDiff == nil { | ||
continue | ||
} | ||
|
||
for operation, operationItem := range pathItem.OperationsDiff.Modified { | ||
if operationItem.RequestBodyDiff == nil || | ||
operationItem.RequestBodyDiff.ContentDiff == nil || | ||
operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { | ||
continue | ||
} | ||
source := (*operationsSources)[operationItem.Revision] | ||
|
||
modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified | ||
for _, mediaTypeDiff := range modifiedMediaTypes { | ||
if mediaTypeDiff.SchemaDiff == nil { | ||
continue | ||
} | ||
|
||
if mediaTypeDiff.SchemaDiff.AllOfDiff != nil && len(mediaTypeDiff.SchemaDiff.AllOfDiff.Added) > 0 { | ||
result = append(result, ApiChange{ | ||
Id: "request-body-all-of-added", | ||
Level: ERR, | ||
Text: fmt.Sprintf( | ||
config.i18n("request-body-all-of-added"), | ||
ColorizedValue(mediaTypeDiff.SchemaDiff.AllOfDiff.Added.String())), | ||
Operation: operation, | ||
OperationId: operationItem.Revision.OperationID, | ||
Path: path, | ||
Source: source, | ||
}) | ||
} | ||
|
||
if mediaTypeDiff.SchemaDiff.AllOfDiff != nil && len(mediaTypeDiff.SchemaDiff.AllOfDiff.Deleted) > 0 { | ||
result = append(result, ApiChange{ | ||
Id: "request-body-all-of-removed", | ||
Level: WARN, | ||
Text: fmt.Sprintf( | ||
config.i18n("request-body-all-of-removed"), | ||
ColorizedValue(mediaTypeDiff.SchemaDiff.AllOfDiff.Deleted.String())), | ||
Operation: operation, | ||
OperationId: operationItem.Revision.OperationID, | ||
Path: path, | ||
Source: source, | ||
}) | ||
} | ||
|
||
CheckModifiedPropertiesDiff( | ||
mediaTypeDiff.SchemaDiff, | ||
func(propertyPath string, propertyName string, propertyDiff *diff.SchemaDiff, parent *diff.SchemaDiff) { | ||
if propertyDiff.AllOfDiff == nil { | ||
return | ||
} | ||
|
||
if len(propertyDiff.AllOfDiff.Added) > 0 { | ||
result = append(result, ApiChange{ | ||
Id: "request-property-all-of-added", | ||
Level: ERR, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. breaking change |
||
Text: fmt.Sprintf( | ||
config.i18n("request-property-all-of-added"), | ||
ColorizedValue(propertyDiff.AllOfDiff.Added.String()), | ||
ColorizedValue(propertyFullName(propertyPath, propertyName))), | ||
Operation: operation, | ||
OperationId: operationItem.Revision.OperationID, | ||
Path: path, | ||
Source: source, | ||
}) | ||
} | ||
|
||
if len(propertyDiff.AllOfDiff.Deleted) > 0 { | ||
result = append(result, ApiChange{ | ||
Id: "request-property-all-of-removed", | ||
Level: WARN, | ||
Text: fmt.Sprintf( | ||
config.i18n("request-property-all-of-removed"), | ||
ColorizedValue(propertyDiff.AllOfDiff.Deleted.String()), | ||
ColorizedValue(propertyFullName(propertyPath, propertyName))), | ||
Operation: operation, | ||
OperationId: operationItem.Revision.OperationID, | ||
Path: path, | ||
Source: source, | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
return result | ||
} |
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 @@ | ||
package checker_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tufin/oasdiff/checker" | ||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
// CL: adding 'allOf' schema to the request body or request body property | ||
func TestRequestPropertyAllOfAdded(t *testing.T) { | ||
s1, err := open("../data/checker/request_property_all_of_added_base.yaml") | ||
require.NoError(t, err) | ||
s2, err := open("../data/checker/request_property_all_of_added_revision.yaml") | ||
require.NoError(t, err) | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) | ||
require.NoError(t, err) | ||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyAllOfUpdated), d, osm, checker.INFO) | ||
|
||
require.Len(t, errs, 2) | ||
|
||
require.ElementsMatch(t, []checker.ApiChange{ | ||
{ | ||
Id: "request-body-all-of-added", | ||
Text: "added 'Rabbit' to the request body 'allOf' list", | ||
Comment: "", | ||
Level: checker.ERR, | ||
Operation: "POST", | ||
Path: "/pets", | ||
Source: "../data/checker/request_property_all_of_added_revision.yaml", | ||
OperationId: "updatePets", | ||
}, | ||
{ | ||
Id: "request-property-all-of-added", | ||
Text: "added 'Breed3' to the '/allOf[#/components/schemas/Dog]/breed' request property 'allOf' list", | ||
Comment: "", | ||
Level: checker.ERR, | ||
Operation: "POST", | ||
Path: "/pets", | ||
Source: "../data/checker/request_property_all_of_added_revision.yaml", | ||
OperationId: "updatePets", | ||
}}, errs) | ||
} | ||
|
||
// CL: removing 'allOf' schema from the request body or request body property | ||
func TestRequestPropertyAllOfRemoved(t *testing.T) { | ||
s1, err := open("../data/checker/request_property_all_of_removed_base.yaml") | ||
require.NoError(t, err) | ||
s2, err := open("../data/checker/request_property_all_of_removed_revision.yaml") | ||
require.NoError(t, err) | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) | ||
require.NoError(t, err) | ||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyAllOfUpdated), d, osm, checker.INFO) | ||
|
||
require.Len(t, errs, 2) | ||
|
||
require.ElementsMatch(t, []checker.ApiChange{ | ||
{ | ||
Id: "request-body-all-of-removed", | ||
Text: "removed 'Rabbit' from the request body 'allOf' list", | ||
Comment: "", | ||
Level: checker.WARN, | ||
Operation: "POST", | ||
Path: "/pets", | ||
Source: "../data/checker/request_property_all_of_removed_revision.yaml", | ||
OperationId: "updatePets", | ||
}, | ||
{ | ||
Id: "request-property-all-of-removed", | ||
Text: "removed 'Breed3' from the '/allOf[#/components/schemas/Dog]/breed' request property 'allOf' list", | ||
Comment: "", | ||
Level: checker.WARN, | ||
Operation: "POST", | ||
Path: "/pets", | ||
Source: "../data/checker/request_property_all_of_removed_revision.yaml", | ||
OperationId: "updatePets", | ||
}}, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package checker | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
func ResponsePropertyAllOfUpdated(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config Config) Changes { | ||
result := make(Changes, 0) | ||
if diffReport.PathsDiff == nil { | ||
return result | ||
} | ||
|
||
for path, pathItem := range diffReport.PathsDiff.Modified { | ||
if pathItem.OperationsDiff == nil { | ||
continue | ||
} | ||
|
||
for operation, operationItem := range pathItem.OperationsDiff.Modified { | ||
if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { | ||
continue | ||
} | ||
source := (*operationsSources)[operationItem.Revision] | ||
|
||
for responseStatus, responsesDiff := range operationItem.ResponsesDiff.Modified { | ||
if responsesDiff.ContentDiff == nil || responsesDiff.ContentDiff.MediaTypeModified == nil { | ||
continue | ||
} | ||
|
||
modifiedMediaTypes := responsesDiff.ContentDiff.MediaTypeModified | ||
for _, mediaTypeDiff := range modifiedMediaTypes { | ||
if mediaTypeDiff.SchemaDiff == nil { | ||
continue | ||
} | ||
|
||
if mediaTypeDiff.SchemaDiff.AllOfDiff != nil && len(mediaTypeDiff.SchemaDiff.AllOfDiff.Added) > 0 { | ||
result = append(result, ApiChange{ | ||
Id: "response-body-all-of-added", | ||
Level: INFO, | ||
Text: fmt.Sprintf( | ||
config.i18n("response-body-all-of-added"), | ||
ColorizedValue(mediaTypeDiff.SchemaDiff.AllOfDiff.Added.String()), | ||
responseStatus), | ||
Operation: operation, | ||
OperationId: operationItem.Revision.OperationID, | ||
Path: path, | ||
Source: source, | ||
}) | ||
} | ||
|
||
if mediaTypeDiff.SchemaDiff.AllOfDiff != nil && len(mediaTypeDiff.SchemaDiff.AllOfDiff.Deleted) > 0 { | ||
result = append(result, ApiChange{ | ||
Id: "response-body-all-of-removed", | ||
Level: INFO, | ||
Text: fmt.Sprintf( | ||
config.i18n("response-body-all-of-removed"), | ||
ColorizedValue(mediaTypeDiff.SchemaDiff.AllOfDiff.Deleted.String()), | ||
responseStatus), | ||
Operation: operation, | ||
OperationId: operationItem.Revision.OperationID, | ||
Path: path, | ||
Source: source, | ||
}) | ||
} | ||
|
||
CheckModifiedPropertiesDiff( | ||
mediaTypeDiff.SchemaDiff, | ||
func(propertyPath string, propertyName string, propertyDiff *diff.SchemaDiff, parent *diff.SchemaDiff) { | ||
if propertyDiff.AllOfDiff == nil { | ||
return | ||
} | ||
|
||
if len(propertyDiff.AllOfDiff.Added) > 0 { | ||
result = append(result, ApiChange{ | ||
Id: "response-property-all-of-added", | ||
Level: INFO, | ||
Text: fmt.Sprintf( | ||
config.i18n("response-property-all-of-added"), | ||
ColorizedValue(propertyDiff.AllOfDiff.Added.String()), | ||
ColorizedValue(propertyFullName(propertyPath, propertyName)), | ||
responseStatus), | ||
Operation: operation, | ||
OperationId: operationItem.Revision.OperationID, | ||
Path: path, | ||
Source: source, | ||
}) | ||
} | ||
|
||
if len(propertyDiff.AllOfDiff.Deleted) > 0 { | ||
result = append(result, ApiChange{ | ||
Id: "response-property-all-of-removed", | ||
Level: INFO, | ||
Text: fmt.Sprintf( | ||
config.i18n("response-property-all-of-removed"), | ||
ColorizedValue(propertyDiff.AllOfDiff.Deleted.String()), | ||
ColorizedValue(propertyFullName(propertyPath, propertyName)), | ||
responseStatus), | ||
Operation: operation, | ||
OperationId: operationItem.Revision.OperationID, | ||
Path: path, | ||
Source: source, | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
return result | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
breaking change