Skip to content

Commit

Permalink
remove breaking-only functionality (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven Harrison authored Jul 9, 2023
1 parent 519a522 commit 185b9a9
Show file tree
Hide file tree
Showing 48 changed files with 63 additions and 2,619 deletions.
40 changes: 20 additions & 20 deletions BREAKING-CHANGES-EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,54 +76,54 @@ These examples are automatically generated from unit tests.
[setting the default value of an optional request parameter is breaking](checker/checker_breaking_test.go?plain=1#L555)

## Examples of non-breaking changes
[adding a media-type to response is not breaking](checker/checker_not_breaking_test.go?plain=1#L179)
[adding a media-type to response is not breaking](checker/checker_not_breaking_test.go?plain=1#L185)
[adding a new required property in response body is not breaking](checker/checker_breaking_property_test.go?plain=1#L402)
[adding a new required property under AllOf in response body is not breaking](checker/checker_breaking_property_test.go?plain=1#L432)
[adding a new required read-only property in request body is not breaking](checker/checker_breaking_property_test.go?plain=1#L486)
[adding a non-existent required property in request body is not breaking](checker/checker_breaking_property_test.go?plain=1#L294)
[adding a required property to response is not breaking](checker/checker_not_breaking_test.go?plain=1#L284)
[adding a tag is not breaking](checker/checker_not_breaking_test.go?plain=1#L261)
[adding an enum value is not breaking](checker/checker_not_breaking_test.go?plain=1#L77)
[adding a required property to response is not breaking](checker/checker_not_breaking_test.go?plain=1#L290)
[adding a tag is not breaking](checker/checker_not_breaking_test.go?plain=1#L267)
[adding an enum value is not breaking](checker/checker_not_breaking_test.go?plain=1#L83)
[adding an enum value to request body is not breaking](checker/checker_breaking_property_test.go?plain=1#L138)
[adding an operation ID is not breaking](checker/checker_not_breaking_test.go?plain=1#L272)
[adding an optional request body is not breaking](checker/checker_not_breaking_test.go?plain=1#L32)
[adding an operation ID is not breaking](checker/checker_not_breaking_test.go?plain=1#L278)
[adding an optional request body is not breaking](checker/checker_not_breaking_test.go?plain=1#L38)
[both max lengths in request are nil is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L178)
[both max lengths in response are nil is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L192)
[changing a link to operation ID is not breaking](checker/checker_not_breaking_test.go?plain=1#L170)
[changing a link to operation ID is not breaking](checker/checker_not_breaking_test.go?plain=1#L176)
[changing an existing property in request body to optional is not breaking](checker/checker_breaking_property_test.go?plain=1#L322)
[changing an existing property in request header to optional is not breaking](checker/checker_breaking_property_test.go?plain=1#L82)
[changing an existing property in response body to required is not breaking](checker/checker_breaking_property_test.go?plain=1#L308)
[changing an existing read-only property in request body to required is not breaking](checker/checker_breaking_property_test.go?plain=1#L500)
[changing an existing required property in response body to write-only is not breaking](checker/checker_breaking_property_test.go?plain=1#L562)
[changing an existing write-only property in response body to optional is not breaking](checker/checker_breaking_property_test.go?plain=1#L548)
[changing comments is not breaking](checker/checker_not_breaking_test.go?plain=1#L101)
[changing extensions is not breaking](checker/checker_not_breaking_test.go?plain=1#L89)
[changing comments is not breaking](checker/checker_not_breaking_test.go?plain=1#L107)
[changing extensions is not breaking](checker/checker_not_breaking_test.go?plain=1#L95)
[changing max length in request from any value to nil is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L144)
[changing max length in response from nil to any value is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L128)
[changing operation ID is not breaking](checker/checker_not_breaking_test.go?plain=1#L161)
[changing operation ID is not breaking](checker/checker_not_breaking_test.go?plain=1#L167)
[changing request's body schema type from integer to number is not breaking](checker/checker_breaking_request_type_changed_test.go?plain=1#L71)
[changing response's body schema type from number to integer is not breaking](checker/checker_breaking_response_type_changed_test.go?plain=1#L51)
[changing response's body schema type from number/none to integer/int32 is not breaking](checker/checker_breaking_response_type_changed_test.go?plain=1#L89)
[changing servers is not breaking](checker/checker_not_breaking_test.go?plain=1#L247)
[changing servers is not breaking](checker/checker_not_breaking_test.go?plain=1#L253)
[deleting a non-required non-write-only property in response body is not breaking](checker/checker_breaking_property_test.go?plain=1#L531)
[deleting a path after sunset date of all contained operations is not breaking](checker/checker_deprecation_test.go?plain=1#L258)
[deleting a pattern from a schema is not breaking](checker/checker_breaking_test.go?plain=1#L445)
[deleting a required write-only property in response body is not breaking](checker/checker_breaking_property_test.go?plain=1#L514)
[deleting a tag is not breaking](checker/checker_not_breaking_test.go?plain=1#L65)
[deleting a tag is not breaking](checker/checker_not_breaking_test.go?plain=1#L71)
[deleting an operation after sunset date is not breaking](checker/checker_deprecation_test.go?plain=1#L69)
[deprecating a header is not breaking](checker/checker_not_breaking_test.go?plain=1#L221)
[deprecating a parameter is not breaking](checker/checker_not_breaking_test.go?plain=1#L208)
[deprecating a schema is not breaking](checker/checker_not_breaking_test.go?plain=1#L234)
[deprecating a header is not breaking](checker/checker_not_breaking_test.go?plain=1#L227)
[deprecating a parameter is not breaking](checker/checker_not_breaking_test.go?plain=1#L214)
[deprecating a schema is not breaking](checker/checker_not_breaking_test.go?plain=1#L240)
[deprecating an operation with a deprecation policy and sunset date after required deprecation period is not breaking](checker/checker_deprecation_test.go?plain=1#L237)
[deprecating an operation without a deprecation policy and without specifying sunset date is not breaking for draft level](checker/checker_deprecation_test.go?plain=1#L155)
[deprecating an operation without a deprecation policy and without specifying sunset date is not breaking](checker/checker_deprecation_test.go?plain=1#L103)
[increasing max length in request is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L76)
[increasing min items in response is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L250)
[modifying a pattern to ".*" in a schema is not breaking](checker/checker_breaking_test.go?plain=1#L523)
[modifying the default value of a required request parameter is not breaking](checker/checker_breaking_test.go?plain=1#L573)
[new optional header param is not breaking](checker/checker_not_breaking_test.go?plain=1#L113)
[new optional header param is not breaking](checker/checker_not_breaking_test.go?plain=1#L119)
[new optional property in request header is not breaking](checker/checker_breaking_property_test.go?plain=1#L38)
[new required response header param is not breaking](checker/checker_not_breaking_test.go?plain=1#L147)
[new required response header param is not breaking](checker/checker_not_breaking_test.go?plain=1#L153)
[no change is not breaking](checker/checker_not_breaking_test.go?plain=1#L27)
[reducing max in response is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L281)
[reducing max length in response is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L31)
Expand Down Expand Up @@ -172,11 +172,11 @@ These examples are automatically generated from unit tests.
[Updating an existing tag](checker/check-api-tag-updated_test.go?plain=1#L60)
[adding a required write-only property to response body is detected](checker/check-response-required-property-updated_test.go?plain=1#L57)
[changing an existing header param from required to optional](checker/checker_request_parameter_required_value_updated_test.go?plain=1#L35)
[changing an existing header param to optional](checker/checker_not_breaking_test.go?plain=1#L127)
[changing an existing request body from required to optional](checker/checker_not_breaking_test.go?plain=1#L47)
[changing an existing header param to optional](checker/checker_not_breaking_test.go?plain=1#L133)
[changing an existing request body from required to optional](checker/checker_not_breaking_test.go?plain=1#L53)
[changing request's body to optional](checker/check-request-body-required-value-updated_test.go?plain=1#L35)
[changing request's body to required is breaking](checker/check-request-body-required-value-updated_test.go?plain=1#L11)
[deprecating an operation with sunset greater than min](checker/checker_not_breaking_test.go?plain=1#L193)
[deprecating an operation with sunset greater than min](checker/checker_not_breaking_test.go?plain=1#L199)
[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
2 changes: 1 addition & 1 deletion checker/check-api-deprecation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio
continue
}

rawDate, date, err := diff.GetSunsetDate(op.Extensions)
rawDate, date, err := getSunsetDate(op.Extensions)
if err != nil {
result = append(result, ApiChange{
Id: "api-deprecated-sunset-parse",
Expand Down
4 changes: 2 additions & 2 deletions checker/check-api-removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo
})
continue
}
rawDate, date, err := diff.GetSunsetDate(op.Extensions)
rawDate, date, err := getSunsetDate(op.Extensions)
if err != nil {
source := "original_source=" + (*operationsSources)[op]
result = append(result, ApiChange{
Expand Down Expand Up @@ -81,7 +81,7 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo
})
continue
}
rawDate, date, err := diff.GetSunsetDate(op.Extensions)
rawDate, date, err := getSunsetDate(op.Extensions)
if err != nil {
source := (*operationsSources)[op]
result = append(result, ApiChange{
Expand Down
4 changes: 2 additions & 2 deletions checker/check-api-sunset-changed.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func APISunsetChangedCheck(diffReport *diff.Diff, operationsSources *diff.Operat

opBase := pathItem.Base.Operations()[operation]

rawDate, date, err := diff.GetSunsetDate(op.Extensions)
rawDate, date, err := getSunsetDate(op.Extensions)
if err != nil {
result = append(result, ApiChange{
Id: "api-deprecated-sunset-parse",
Expand All @@ -58,7 +58,7 @@ func APISunsetChangedCheck(diffReport *diff.Diff, operationsSources *diff.Operat
continue
}

rawDate, baseDate, err := diff.GetSunsetDate(opBase.Extensions)
rawDate, baseDate, err := getSunsetDate(opBase.Extensions)
if err != nil {
result = append(result, ApiChange{
Id: "api-deprecated-sunset-parse",
Expand Down
8 changes: 7 additions & 1 deletion checker/checker_not_breaking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ func verifyNonBreakingChangeIsChangelogEntry(t *testing.T, d *diff.Diff, osm *di

// BC: no change is not breaking
func TestBreaking_Same(t *testing.T) {
require.Empty(t, d(t, &diff.Config{BreakingOnly: true}, 1, 1))
s1 := l(t, 1)
s2 := l(t, 1)

d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm)
require.Empty(t, errs)
}

// BC: adding an optional request body is not breaking
Expand Down
31 changes: 31 additions & 0 deletions checker/deprecation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package checker

import (
"encoding/json"
"errors"
"time"

"cloud.google.com/go/civil"
"github.com/tufin/oasdiff/diff"
)

func getSunsetDate(Extensions map[string]interface{}) (string, civil.Date, error) {
sunset, ok := Extensions[diff.SunsetExtension].(string)
if !ok {
sunsetJson, ok := Extensions[diff.SunsetExtension].(json.RawMessage)
if !ok {
return "", civil.Date{}, errors.New("sunset header not found")
}
if err := json.Unmarshal(sunsetJson, &sunset); err != nil {
return "", civil.Date{}, errors.New("unmarshal failed")
}
}

if date, err := civil.ParseDate(sunset); err == nil {
return sunset, date, nil
} else if date, err := time.Parse(time.RFC3339, sunset); err == nil {
return sunset, civil.DateOf(date), nil
}

return sunset, civil.Date{}, errors.New("failed to parse sunset date")
}
Loading

0 comments on commit 185b9a9

Please sign in to comment.