Skip to content

Commit

Permalink
Changelog: Request properties changed (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
blva authored Jul 31, 2023
1 parent 3eae473 commit 3a7f646
Show file tree
Hide file tree
Showing 26 changed files with 1,116 additions and 57 deletions.
19 changes: 19 additions & 0 deletions BREAKING-CHANGES-EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ These examples are automatically generated from unit tests.
[adding an enum value to request parameter](checker/check-request-parameter-enum-value-updated_test.go?plain=1#L34)
[adding an optional write-only property to a response](checker/check-response-optional-property-updated_test.go?plain=1#L34)
[adding pattern to request parameters](checker/check-request-parameter-pattern-added-or-changed_test.go?plain=1#L35)
[adding request property enum values](checker/check-request-property-enum-value-updated_test.go?plain=1#L37)
[adding request property pattern](checker/check-request-property-pattern-added-or-changed_test.go?plain=1#L36)
[adding response property pattern](checker/check-response-pattern-added-or-changed_test.go?plain=1#L37)
[changing a response property schema format](checker/check-response-property-type-changed_test.go?plain=1#L59)
Expand All @@ -182,13 +183,16 @@ These examples are automatically generated from unit tests.
[changing optional response property to write-only](checker/check-response-optional-property-write-only-read-only_test.go?plain=1#L11)
[changing optional response write-only property to required](checker/check-response-property-became-required_test.go?plain=1#L33)
[changing pattern of request parameters](checker/check-request-parameter-pattern-added-or-changed_test.go?plain=1#L11)
[changing request body type](checker/check-request-property-type-changed_test.go?plain=1#L11)
[changing request header parameter format](checker/check-request-parameters-type-changed_test.go?plain=1#L136)
[changing request header parameter type](checker/check-request-parameters-type-changed_test.go?plain=1#L61)
[changing request parameter default value](checker/check-request-parameters-default-value-changed_test.go?plain=1#L11)
[changing request parameter type to enum](checker/check-request-parameter-became-enum_test.go?plain=1#L11)
[changing request path parameter format](checker/check-request-parameters-type-changed_test.go?plain=1#L86)
[changing request path parameter type](checker/check-request-parameters-type-changed_test.go?plain=1#L11)
[changing request property format](checker/check-request-property-type-changed_test.go?plain=1#L84)
[changing request property pattern](checker/check-request-property-pattern-added-or-changed_test.go?plain=1#L11)
[changing request property type](checker/check-request-property-type-changed_test.go?plain=1#L61)
[changing request query parameter format](checker/check-request-parameters-type-changed_test.go?plain=1#L111)
[changing request query parameter type](checker/check-request-parameters-type-changed_test.go?plain=1#L36)
[changing request's body to optional](checker/check-request-body-required-value-updated_test.go?plain=1#L36)
Expand All @@ -204,19 +208,33 @@ These examples are automatically generated from unit tests.
[changing security component oauth's url](checker/check-components-security-updated_test.go?plain=1#L11)
[changing security component type](checker/check-components-security-updated_test.go?plain=1#L33)
[changing write-only required response property to optional](checker/check-response-property-became-optional_test.go?plain=1#L33)
[decreasing max length of request body](checker/check-request-property-max-length-updated_test.go?plain=1#L39)
[decreasing max length of request property](checker/check-request-property-max-length-updated_test.go?plain=1#L67)
[decreasing maxItems of request parameters](checker/check-request-parameters-max-items-updated_test.go?plain=1#L34)
[decreasing maxLength of request parameters](checker/check-request-parameters-max-length-updated_test.go?plain=1#L33)
[decreasing maximum value of request parameter](checker/check-request-parameters-max-updated_test.go?plain=1#L33)
[decreasing minItems value of request parameter](checker/check-request-parameters-min-items-updated_test.go?plain=1#L33)
[decreasing minLength of request body](checker/check-request-property-min-length-updated_test.go?plain=1#L86)
[decreasing minLength of request property](checker/check-request-property-min-length-updated_test.go?plain=1#L11)
[decreasing minLength value of request parameter](checker/check-request-parameters-min-length-updated_test.go?plain=1#L34)
[decreasing minimum value of request parameter](checker/check-request-parameters-min-updated_test.go?plain=1#L33)
[decreasing minimum value of request property](checker/check-request-property-min-updated_test.go?plain=1#L34)
[decreasing request body maximum value](checker/check-request-property-max-updated_test.go?plain=1#L91)
[decreasing request property maximum value](checker/check-request-property-max-updated_test.go?plain=1#L11)
[deprecating an operation with sunset greater than min](checker/checker_not_breaking_test.go?plain=1#L199)
[increasing max length of request body](checker/check-request-property-max-length-updated_test.go?plain=1#L11)
[increasing max length of request property](checker/check-request-property-max-length-updated_test.go?plain=1#L94)
[increasing maxItems of request parameters](checker/check-request-parameters-max-items-updated_test.go?plain=1#L11)
[increasing maxLength of request parameters](checker/check-request-parameters-max-length-updated_test.go?plain=1#L11)
[increasing maximum value of request parameter](checker/check-request-parameters-max-updated_test.go?plain=1#L11)
[increasing minItems value of request parameter](checker/check-request-parameters-min-items-updated_test.go?plain=1#L11)
[increasing minLength of request body](checker/check-request-property-min-length-updated_test.go?plain=1#L61)
[increasing minLength of request property](checker/check-request-property-min-length-updated_test.go?plain=1#L36)
[increasing minLength value of request parameter](checker/check-request-parameters-min-length-updated_test.go?plain=1#L11)
[increasing minimum value of request parameter](checker/check-request-parameters-min-updated_test.go?plain=1#L11)
[increasing minimum value of request property](checker/check-request-property-min-updated_test.go?plain=1#L11)
[increasing request body maximum value](checker/check-request-property-max-updated_test.go?plain=1#L63)
[increasing request property maximum value](checker/check-request-property-max-updated_test.go?plain=1#L37)
[new header, query and cookie request params](checker/check-new-request-non-path-parameter_test.go?plain=1#L11)
[new paths or path operations](checker/check-api-added_test.go?plain=1#L11)
[path operations that became deprecated](checker/checker_deprecation_test.go?plain=1#L324)
Expand Down Expand Up @@ -245,6 +263,7 @@ These examples are automatically generated from unit tests.
[removing an optional write-only property from a response](checker/check-response-optional-property-updated_test.go?plain=1#L11)
[removing media type from request body](checker/check-request-body-mediatype-updated_test.go?plain=1#L34)
[removing pattern from request parameters](checker/check-request-parameter-pattern-added-or-changed_test.go?plain=1#L58)
[removing request property enum values](checker/check-request-property-enum-value-updated_test.go?plain=1#L11)
[removing request property pattern](checker/check-request-property-pattern-added-or-changed_test.go?plain=1#L59)
[removing response property pattern](checker/check-response-pattern-added-or-changed_test.go?plain=1#L63)
[updating an existing operation id](checker/check-api-operation-id-updated_test.go?plain=1#L36)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/tufin/oasdiff/diff"
)

func RequestPropertyEnumValueRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config Config) Changes {
func RequestPropertyEnumValueUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config Config) Changes {
result := make(Changes, 0)
if diffReport.PathsDiff == nil {
return result
Expand All @@ -28,24 +28,38 @@ func RequestPropertyEnumValueRemovedCheck(diffReport *diff.Diff, operationsSourc
CheckModifiedPropertiesDiff(
mediaTypeDiff.SchemaDiff,
func(propertyPath string, propertyName string, propertyDiff *diff.SchemaDiff, parent *diff.SchemaDiff) {
enumDiff := mediaTypeDiff.SchemaDiff.EnumDiff
if enumDiff == nil || enumDiff.Deleted == nil {
return
}
if propertyDiff.Revision.Value.ReadOnly {
enumDiff := propertyDiff.EnumDiff
if enumDiff == nil {
return
}

for _, enumVal := range enumDiff.Deleted {
level := ERR
if propertyDiff.Revision.Value.ReadOnly {
level = INFO
}
result = append(result, ApiChange{
Id: "request-property-enum-value-removed",
Level: ERR,
Level: level,
Text: fmt.Sprintf(config.i18n("request-property-enum-value-removed"), enumVal, ColorizedValue(propertyFullName(propertyPath, propertyName))),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: source,
})
}

for _, enumVal := range enumDiff.Added {
result = append(result, ApiChange{
Id: "request-property-enum-value-added",
Level: INFO,
Text: fmt.Sprintf(config.i18n("request-property-enum-value-added"), ColorizedValue(enumVal), ColorizedValue(propertyFullName(propertyPath, propertyName))),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: source,
})
}
})
}
}
Expand Down
61 changes: 61 additions & 0 deletions checker/check-request-property-enum-value-updated_test.go
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])
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/tufin/oasdiff/diff"
)

func RequestPropertyMaxLengthDecreasedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config Config) Changes {
func RequestPropertyMaxLengthUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config Config) Changes {
result := make(Changes, 0)
if diffReport.PathsDiff == nil {
return result
Expand Down Expand Up @@ -39,6 +39,16 @@ func RequestPropertyMaxLengthDecreasedCheck(diffReport *diff.Diff, operationsSou
Path: path,
Source: source,
})
} else {
result = append(result, ApiChange{
Id: "request-body-max-length-increased",
Level: INFO,
Text: fmt.Sprintf(config.i18n("request-body-max-length-increased"), ColorizedValue(maxLengthDiff.From), ColorizedValue(maxLengthDiff.To)),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: source,
})
}
}
}
Expand All @@ -54,22 +64,29 @@ func RequestPropertyMaxLengthDecreasedCheck(diffReport *diff.Diff, operationsSou
maxLengthDiff.To == nil {
return
}
if propertyDiff.Revision.Value.ReadOnly {
return
}
if !IsDecreasedValue(maxLengthDiff) {
return

if IsDecreasedValue(maxLengthDiff) {
result = append(result, ApiChange{
Id: "request-property-max-length-decreased",
Level: ConditionalError(!propertyDiff.Revision.Value.ReadOnly),
Text: fmt.Sprintf(config.i18n("request-property-max-length-decreased"), ColorizedValue(propertyFullName(propertyPath, propertyName)), ColorizedValue(maxLengthDiff.To)),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: source,
})
} else {
result = append(result, ApiChange{
Id: "request-property-max-length-increased",
Level: INFO,
Text: fmt.Sprintf(config.i18n("request-property-max-length-increased"), ColorizedValue(propertyFullName(propertyPath, propertyName)), ColorizedValue(maxLengthDiff.From), ColorizedValue(maxLengthDiff.To)),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: source,
})
}

result = append(result, ApiChange{
Id: "request-property-max-length-decreased",
Level: ERR,
Text: fmt.Sprintf(config.i18n("request-property-max-length-decreased"), ColorizedValue(propertyFullName(propertyPath, propertyName)), ColorizedValue(maxLengthDiff.To)),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: source,
})
})
}
}
Expand Down
119 changes: 119 additions & 0 deletions checker/check-request-property-max-length-updated_test.go
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])
}
Loading

0 comments on commit 3a7f646

Please sign in to comment.