forked from Tufin/oasdiff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into discriminators-2
- Loading branch information
Showing
26 changed files
with
1,136 additions
and
118 deletions.
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 was deleted.
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
108 changes: 108 additions & 0 deletions
108
checker/check-request-property-became-not-nuallable_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,108 @@ | ||
package checker_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tufin/oasdiff/checker" | ||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
// CL: changing request property to not nullable | ||
func TestRequestPropertyBecameNotNullable(t *testing.T) { | ||
s1, err := open("../data/checker/request_property_became_nullable_revision.yaml") | ||
require.NoError(t, err) | ||
s2, err := open("../data/checker/request_property_became_nullable_base.yaml") | ||
require.NoError(t, err) | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) | ||
require.NoError(t, err) | ||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyBecameNotNullableCheck), d, osm, checker.INFO) | ||
require.Len(t, errs, 1) | ||
require.Equal(t, checker.ApiChange{ | ||
Id: "request-property-became-not-nullable", | ||
Text: "the request property 'name' became not nullable", | ||
Comment: "", | ||
Level: checker.ERR, | ||
Operation: "POST", | ||
Path: "/products", | ||
Source: "../data/checker/request_property_became_nullable_base.yaml", | ||
OperationId: "addProduct", | ||
}, errs[0]) | ||
} | ||
|
||
// CL: changing request property to nullable | ||
func TestRequestPropertyBecameNullable(t *testing.T) { | ||
s1, err := open("../data/checker/request_property_became_nullable_base.yaml") | ||
require.NoError(t, err) | ||
s2, err := open("../data/checker/request_property_became_nullable_revision.yaml") | ||
require.NoError(t, err) | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) | ||
require.NoError(t, err) | ||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyBecameNotNullableCheck), d, osm, checker.INFO) | ||
require.Len(t, errs, 1) | ||
require.Equal(t, checker.ApiChange{ | ||
Id: "request-property-became-nullable", | ||
Text: "the request property 'name' became nullable", | ||
Comment: "", | ||
Level: checker.INFO, | ||
Operation: "POST", | ||
Path: "/products", | ||
Source: "../data/checker/request_property_became_nullable_revision.yaml", | ||
OperationId: "addProduct", | ||
}, errs[0]) | ||
|
||
} | ||
|
||
// CL: changing request body to nullable | ||
func TestRequestBodyBecameNullable(t *testing.T) { | ||
s1, err := open("../data/checker/request_property_became_nullable_base.yaml") | ||
require.NoError(t, err) | ||
s2, err := open("../data/checker/request_property_became_nullable_base.yaml") | ||
require.NoError(t, err) | ||
|
||
s2.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Nullable = true | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) | ||
require.NoError(t, err) | ||
|
||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyBecameNotNullableCheck), d, osm, checker.INFO) | ||
require.Len(t, errs, 1) | ||
require.Equal(t, checker.ApiChange{ | ||
Id: "request-body-became-nullable", | ||
Text: "the request's body became nullable", | ||
Comment: "", | ||
Level: checker.INFO, | ||
Operation: "POST", | ||
Path: "/products", | ||
Source: "../data/checker/request_property_became_nullable_base.yaml", | ||
OperationId: "addProduct", | ||
}, errs[0]) | ||
} | ||
|
||
// CL: changing request body to not nullable | ||
func TestRequestBodyBecameNotNullable(t *testing.T) { | ||
s1, err := open("../data/checker/request_property_became_nullable_base.yaml") | ||
require.NoError(t, err) | ||
s2, err := open("../data/checker/request_property_became_nullable_base.yaml") | ||
require.NoError(t, err) | ||
|
||
s1.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Nullable = true | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) | ||
require.NoError(t, err) | ||
|
||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyBecameNotNullableCheck), d, osm, checker.ERR) | ||
require.Len(t, errs, 1) | ||
require.Equal(t, checker.ApiChange{ | ||
Id: "request-body-became-not-nullable", | ||
Text: "the request's body became not nullable", | ||
Comment: "", | ||
Level: checker.ERR, | ||
Operation: "POST", | ||
Path: "/products", | ||
Source: "../data/checker/request_property_became_nullable_base.yaml", | ||
OperationId: "addProduct", | ||
}, errs[0]) | ||
} |
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,64 @@ | ||
package checker | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
func RequestPropertyDefaultValueChangedCheck(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 mediaType, mediaTypeDiff := range modifiedMediaTypes { | ||
if mediaTypeDiff.SchemaDiff != nil && mediaTypeDiff.SchemaDiff.DefaultDiff != nil { | ||
defaultValueDiff := mediaTypeDiff.SchemaDiff.DefaultDiff | ||
result = append(result, ApiChange{ | ||
Id: "request-body-default-value-changed", | ||
Level: INFO, | ||
Text: fmt.Sprintf(config.i18n("request-body-default-value-changed"), ColorizedValue(mediaType), empty2none(defaultValueDiff.From), empty2none(defaultValueDiff.To)), | ||
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 == nil || propertyDiff.Revision == nil || propertyDiff.Revision.Value == nil || propertyDiff.DefaultDiff == nil { | ||
return | ||
} | ||
|
||
defaultValueDiff := propertyDiff.DefaultDiff | ||
|
||
result = append(result, ApiChange{ | ||
Id: "request-property-default-value-changed", | ||
Level: INFO, | ||
Text: fmt.Sprintf(config.i18n("request-property-default-value-changed"), ColorizedValue(propertyName), empty2none(defaultValueDiff.From), empty2none(defaultValueDiff.To)), | ||
Operation: operation, | ||
OperationId: operationItem.Revision.OperationID, | ||
Path: path, | ||
Source: source, | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
return result | ||
} |
Oops, something went wrong.