-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changelog: Request properties changed (#345)
- Loading branch information
Showing
26 changed files
with
1,116 additions
and
57 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 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,61 @@ | ||
package checker_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tufin/oasdiff/checker" | ||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
// CL: removing request property enum values | ||
func TestRequestPropertyEnumValueRemovedCheck(t *testing.T) { | ||
s1, err := open("../data/checker/request_property_enum_value_updated_base.yaml") | ||
require.NoError(t, err) | ||
s2, err := open("../data/checker/request_property_enum_value_updated_base.yaml") | ||
require.NoError(t, err) | ||
|
||
s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["category"].Value.Enum = []interface{}{"dog", "cat"} | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) | ||
require.NoError(t, err) | ||
|
||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyEnumValueUpdatedCheck), d, osm, checker.ERR) | ||
require.Len(t, errs, 1) | ||
|
||
require.Equal(t, checker.ApiChange{ | ||
Id: "request-property-enum-value-removed", | ||
Level: checker.ERR, | ||
Text: "removed the enum value bird of the request property 'category'", | ||
Operation: "POST", | ||
OperationId: "updatePet", | ||
Path: "/pets", | ||
Source: "../data/checker/request_property_enum_value_updated_base.yaml", | ||
}, errs[0]) | ||
} | ||
|
||
// CL: adding request property enum values | ||
func TestRequestPropertyEnumValueAddedCheck(t *testing.T) { | ||
s1, err := open("../data/checker/request_property_enum_value_updated_base.yaml") | ||
require.NoError(t, err) | ||
s2, err := open("../data/checker/request_property_enum_value_updated_base.yaml") | ||
require.NoError(t, err) | ||
|
||
s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["category"].Value.Enum = []interface{}{"dog", "cat"} | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) | ||
require.NoError(t, err) | ||
|
||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyEnumValueUpdatedCheck), d, osm, checker.INFO) | ||
require.Len(t, errs, 1) | ||
|
||
require.Equal(t, checker.ApiChange{ | ||
Id: "request-property-enum-value-added", | ||
Level: checker.INFO, | ||
Text: "added the new 'bird' enum value to the request property 'category'", | ||
Operation: "POST", | ||
OperationId: "updatePet", | ||
Path: "/pets", | ||
Source: "../data/checker/request_property_enum_value_updated_base.yaml", | ||
}, 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
119 changes: 119 additions & 0 deletions
119
checker/check-request-property-max-length-updated_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,119 @@ | ||
package checker_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tufin/oasdiff/checker" | ||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
// CL: increasing max length of request body | ||
func TestRequestBodyMaxLengthDecreasedCheck(t *testing.T) { | ||
s1, err := open("../data/checker/request_body_max_length_decreased_base.yaml") | ||
require.NoError(t, err) | ||
s2, err := open("../data/checker/request_body_max_length_decreased_base.yaml") | ||
require.NoError(t, err) | ||
|
||
maxLength := uint64(50) | ||
newMaxLength := uint64(100) | ||
s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &maxLength | ||
s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &newMaxLength | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) | ||
require.NoError(t, err) | ||
|
||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.INFO) | ||
require.Len(t, errs, 1) | ||
require.Equal(t, checker.ApiChange{ | ||
Id: "request-body-max-length-increased", | ||
Text: "the request's body maxLength was increased from '50' to '100'", | ||
Level: checker.INFO, | ||
Operation: "POST", | ||
Path: "/pets", | ||
Source: "../data/checker/request_body_max_length_decreased_base.yaml", | ||
OperationId: "addPet", | ||
}, errs[0]) | ||
} | ||
|
||
// CL: decreasing max length of request body | ||
func TestRequestBodyMaxLengthIncreasedCheck(t *testing.T) { | ||
s1, err := open("../data/checker/request_body_max_length_decreased_base.yaml") | ||
require.NoError(t, err) | ||
s2, err := open("../data/checker/request_body_max_length_decreased_base.yaml") | ||
require.NoError(t, err) | ||
|
||
maxLength := uint64(100) | ||
newMaxLength := uint64(50) | ||
s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &maxLength | ||
s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &newMaxLength | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) | ||
require.NoError(t, err) | ||
|
||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.ERR) | ||
require.Len(t, errs, 1) | ||
require.Equal(t, checker.ApiChange{ | ||
Id: "request-body-max-length-decreased", | ||
Text: "the request's body maxLength was decreased to '50'", | ||
Level: checker.ERR, | ||
Operation: "POST", | ||
Path: "/pets", | ||
Source: "../data/checker/request_body_max_length_decreased_base.yaml", | ||
OperationId: "addPet", | ||
}, errs[0]) | ||
} | ||
|
||
// CL: decreasing max length of request property | ||
func TestRequestPropertyMaxLengthDecreasedCheck(t *testing.T) { | ||
s1, err := open("../data/checker/request_body_max_length_decreased_base.yaml") | ||
require.NoError(t, err) | ||
s2, err := open("../data/checker/request_body_max_length_decreased_base.yaml") | ||
require.NoError(t, err) | ||
|
||
maxLength := uint64(100) | ||
newMaxLength := uint64(50) | ||
s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &maxLength | ||
s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &newMaxLength | ||
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) | ||
require.NoError(t, err) | ||
|
||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.INFO) | ||
require.Len(t, errs, 1) | ||
require.Equal(t, checker.ApiChange{ | ||
Id: "request-property-max-length-decreased", | ||
Text: "the 'description' request property's maxLength was decreased to '50'", | ||
Level: checker.ERR, | ||
Operation: "POST", | ||
Path: "/pets", | ||
Source: "../data/checker/request_body_max_length_decreased_base.yaml", | ||
OperationId: "addPet", | ||
}, errs[0]) | ||
} | ||
|
||
// CL: increasing max length of request property | ||
func TestRequestPropertyMaxLengthIncreasedCheck(t *testing.T) { | ||
s1, err := open("../data/checker/request_body_max_length_decreased_base.yaml") | ||
require.NoError(t, err) | ||
s2, err := open("../data/checker/request_body_max_length_decreased_base.yaml") | ||
require.NoError(t, err) | ||
|
||
maxLength := uint64(50) | ||
newMaxLength := uint64(100) | ||
s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &maxLength | ||
s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &newMaxLength | ||
d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) | ||
require.NoError(t, err) | ||
|
||
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.INFO) | ||
require.Len(t, errs, 1) | ||
require.Equal(t, checker.ApiChange{ | ||
Id: "request-property-max-length-increased", | ||
Text: "the 'description' request property's maxLength was increased from '50' to '100'", | ||
Level: checker.INFO, | ||
Operation: "POST", | ||
Path: "/pets", | ||
Source: "../data/checker/request_body_max_length_decreased_base.yaml", | ||
OperationId: "addPet", | ||
}, errs[0]) | ||
} |
Oops, something went wrong.