diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 52de4896..94eb3218 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -15,7 +15,7 @@ jobs: strategy: fail-fast: true matrix: - go: ['1.22.1'] + go: ['1.22.2'] os: - ubuntu-latest - windows-latest @@ -88,10 +88,11 @@ jobs: run: | ! git grep -InE 'json:"' | grep -v _test.go | grep -v yaml: - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v4 with: files: ./coverage.txt flags: unittests # optional name: codecov-umbrella # optional - fail_ci_if_error: true # optional (default = false) - verbose: true # optional (default = false) \ No newline at end of file + fail_ci_if_error: false # optional (default = false) + verbose: true # optional (default = false) + token: ${{ secrets.CODECOV_TOKEN }} # required diff --git a/.github/workflows/vuln.yaml b/.github/workflows/vuln.yaml index f81f5304..ac00d82b 100644 --- a/.github/workflows/vuln.yaml +++ b/.github/workflows/vuln.yaml @@ -16,4 +16,4 @@ jobs: - id: govulncheck uses: golang/govulncheck-action@v1 with: - go-version-input: 1.22.1 + go-version-input: 1.22.2 diff --git a/BREAKING-CHANGES-EXAMPLES.md b/BREAKING-CHANGES-EXAMPLES.md index 1c86ad48..93f47891 100644 --- a/BREAKING-CHANGES-EXAMPLES.md +++ b/BREAKING-CHANGES-EXAMPLES.md @@ -1,11 +1,11 @@ # Examples of Breaking and Non-Breaking Changes These examples are automatically generated from unit tests. ## Examples of breaking changes -[adding 'allOf' subschema to the request body or request body property is breaking](checker/checker_breaking_test.go?plain=1#L717) +[adding 'allOf' subschema to the request body or request body property is breaking](checker/checker_breaking_test.go?plain=1#L713) [adding a new required property in request body is breaking](checker/checker_breaking_property_test.go?plain=1#L353) -[adding a pattern to a schema is breaking for recursive properties](checker/checker_breaking_test.go?plain=1#L495) -[adding a pattern to a schema is breaking](checker/checker_breaking_test.go?plain=1#L478) -[adding a required request body is breaking](checker/checker_breaking_test.go?plain=1#L66) +[adding a pattern to a schema is breaking for recursive properties](checker/checker_breaking_test.go?plain=1#L491) +[adding a pattern to a schema is breaking](checker/checker_breaking_test.go?plain=1#L474) +[adding a required request body is breaking](checker/checker_breaking_test.go?plain=1#L62) [changing a request body to enum is breaking](checker/checker_breaking_property_test.go?plain=1#L123) [changing a request body type and changing it to enum simultaneously is breaking](checker/checker_breaking_property_test.go?plain=1#L153) [changing a request property to not nullable is breaking](checker/checker_breaking_property_test.go?plain=1#L233) @@ -14,7 +14,7 @@ These examples are automatically generated from unit tests. [changing a response property to nullable is breaking](checker/checker_breaking_property_test.go?plain=1#L249) [changing a response property to optional under AllOf, AnyOf or OneOf is breaking](checker/checker_breaking_property_test.go?plain=1#L644) [changing an embedded response property to nullable is breaking](checker/checker_breaking_property_test.go?plain=1#L265) -[changing an existing header param from optional to required is breaking](checker/checker_breaking_test.go?plain=1#L195) +[changing an existing header param from optional to required is breaking](checker/checker_breaking_test.go?plain=1#L191) [changing an existing header param to enum is breaking](checker/checker_breaking_property_test.go?plain=1#L185) [changing an existing property in request body anyOf to required is breaking](checker/checker_breaking_property_test.go?plain=1#L612) [changing an existing property in request body items to required is breaking](checker/checker_breaking_property_test.go?plain=1#L596) @@ -24,9 +24,9 @@ These examples are automatically generated from unit tests. [changing an existing property in request header to required is breaking](checker/checker_breaking_property_test.go?plain=1#L57) [changing an existing property in response body to optional is breaking](checker/checker_breaking_property_test.go?plain=1#L107) [changing an existing property under another property in request body to required is breaking](checker/checker_breaking_property_test.go?plain=1#L628) -[changing an existing request body from optional to required is breaking](checker/checker_breaking_test.go?plain=1#L84) +[changing an existing request body from optional to required is breaking](checker/checker_breaking_test.go?plain=1#L80) [changing an existing required property in response body to not-write-only is breaking](checker/checker_breaking_property_test.go?plain=1#L561) -[changing an existing response header from required to optional is breaking](checker/checker_breaking_test.go?plain=1#L219) +[changing an existing response header from required to optional is breaking](checker/checker_breaking_test.go?plain=1#L215) [changing max length in request from nil to any value is breaking](checker/checker_breaking_min_max_test.go?plain=1#L110) [changing max length in response from any value to nil is breaking](checker/checker_breaking_min_max_test.go?plain=1#L160) [changing request's body schema type from number to integer is breaking](checker/checker_breaking_request_type_changed_test.go?plain=1#L51) @@ -37,52 +37,52 @@ These examples are automatically generated from unit tests. [changing response's body schema type from number to string is breaking](checker/checker_breaking_response_type_changed_test.go?plain=1#L31) [changing response's body schema type from string to number is breaking](checker/checker_breaking_response_type_changed_test.go?plain=1#L11) [changing response's embedded property schema type from string/none to integer/int32 is breaking](checker/checker_breaking_response_type_changed_test.go?plain=1#L108) -[deleting a media-type from response is breaking](checker/checker_breaking_test.go?plain=1#L447) +[deleting a media-type from response is breaking](checker/checker_breaking_test.go?plain=1#L443) [deleting a non-required non-write-only property in response body is breaking with warning](checker/checker_breaking_property_test.go?plain=1#L512) -[deleting a path is breaking](checker/checker_breaking_test.go?plain=1#L42) +[deleting a path is breaking](checker/checker_breaking_test.go?plain=1#L38) [deleting a path with some operations having sunset date in the future is breaking](checker/checker_deprecation_test.go?plain=1#L281) [deleting a required property in request is breaking with warn](checker/checker_breaking_property_test.go?plain=1#L369) [deleting a required property in response body is breaking](checker/checker_breaking_property_test.go?plain=1#L421) [deleting a required property under AllOf in response body is breaking](checker/checker_breaking_property_test.go?plain=1#L451) [deleting an embedded optional property in request is breaking with warn](checker/checker_breaking_property_test.go?plain=1#L386) -[deleting an enum value is breaking](checker/checker_breaking_test.go?plain=1#L106) +[deleting an enum value is breaking](checker/checker_breaking_test.go?plain=1#L102) [deleting an operation before sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L33) -[deleting an operation is breaking](checker/checker_breaking_test.go?plain=1#L50) +[deleting an operation is breaking](checker/checker_breaking_test.go?plain=1#L46) [deleting an operation without sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L51) [deleting sunset header for a deprecated endpoint is breaking](checker/checker_deprecation_test.go?plain=1#L299) [deprecating an operation with a deprecation policy and sunset date before required deprecation period is breaking](checker/checker_deprecation_test.go?plain=1#L223) [deprecating an operation with a deprecation policy but without specifying sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L84) [increasing max length in response is breaking](checker/checker_breaking_min_max_test.go?plain=1#L93) [increasing min items in request is breaking](checker/checker_breaking_min_max_test.go?plain=1#L236) -[modifying a pattern in a schema is breaking](checker/checker_breaking_test.go?plain=1#L512) -[modifying a pattern in request parameter is breaking](checker/checker_breaking_test.go?plain=1#L529) -[modifying the default value of an optional request parameter is breaking](checker/checker_breaking_test.go?plain=1#L560) +[modifying a pattern in a schema is breaking](checker/checker_breaking_test.go?plain=1#L508) +[modifying a pattern in request parameter is breaking](checker/checker_breaking_test.go?plain=1#L525) +[modifying the default value of an optional request parameter is breaking](checker/checker_breaking_test.go?plain=1#L556) [new header, query and cookie required request default param is breaking](checker/check-new-request-non-path-default-parameter_test.go?plain=1#L12) -[new required header param is breaking](checker/checker_breaking_test.go?plain=1#L178) -[new required path param is breaking](checker/checker_breaking_test.go?plain=1#L161) +[new required header param is breaking](checker/checker_breaking_test.go?plain=1#L174) +[new required path param is breaking](checker/checker_breaking_test.go?plain=1#L157) [new required property in request header is breaking](checker/checker_breaking_property_test.go?plain=1#L18) [reducing max in request is breaking](checker/checker_breaking_min_max_test.go?plain=1#L264) [reducing max length in request is breaking](checker/checker_breaking_min_max_test.go?plain=1#L12) [reducing min items in response is breaking](checker/checker_breaking_min_max_test.go?plain=1#L220) [reducing min length in response is breaking](checker/checker_breaking_min_max_test.go?plain=1#L62) -[removing 'allOf' subschema from the request body or request body property is breaking with warn](checker/checker_breaking_test.go?plain=1#L739) -[removing 'anyOf' schema from the request body or request body property is breaking](checker/checker_breaking_test.go?plain=1#L674) -[removing 'oneOf' schema from the request body or request body property is breaking](checker/checker_breaking_test.go?plain=1#L696) -[removing a media type from request body is breaking](checker/checker_breaking_test.go?plain=1#L658) +[removing 'allOf' subschema from the request body or request body property is breaking with warn](checker/checker_breaking_test.go?plain=1#L735) +[removing 'anyOf' schema from the request body or request body property is breaking](checker/checker_breaking_test.go?plain=1#L670) +[removing 'oneOf' schema from the request body or request body property is breaking](checker/checker_breaking_test.go?plain=1#L692) +[removing a media type from request body is breaking](checker/checker_breaking_test.go?plain=1#L654) [removing a success status is breaking](checker/check-response-status-updated_test.go?plain=1#L87) -[removing an existing optional response header is breaking as warn](checker/checker_breaking_test.go?plain=1#L427) -[removing an existing required response header is breaking as error](checker/checker_breaking_test.go?plain=1#L236) -[removing an existing response with non-successful status is breaking (optional)](checker/checker_breaking_test.go?plain=1#L275) -[removing an existing response with successful status is breaking](checker/checker_breaking_test.go?plain=1#L256) -[removing an schema object from components is breaking (optional)](checker/checker_breaking_test.go?plain=1#L633) -[removing the default value of an optional request parameter is breaking](checker/checker_breaking_test.go?plain=1#L596) +[removing an existing optional response header is breaking as warn](checker/checker_breaking_test.go?plain=1#L423) +[removing an existing required response header is breaking as error](checker/checker_breaking_test.go?plain=1#L232) +[removing an existing response with non-successful status is breaking (optional)](checker/checker_breaking_test.go?plain=1#L271) +[removing an existing response with successful status is breaking](checker/checker_breaking_test.go?plain=1#L252) +[removing an schema object from components is breaking (optional)](checker/checker_breaking_test.go?plain=1#L629) +[removing the default value of an optional request parameter is breaking](checker/checker_breaking_test.go?plain=1#L592) [removing the path without a deprecation policy and without specifying sunset date is breaking if some APIs are not alpha stability level](checker/checker_deprecation_test.go?plain=1#L138) [removing the path without a deprecation policy and without specifying sunset date is breaking if some APIs are not draft stability level](checker/checker_deprecation_test.go?plain=1#L194) -[removing/updating a property enum in response is breaking (optional)](checker/checker_breaking_test.go?plain=1#L338) -[removing/updating a tag is breaking (optional)](checker/checker_breaking_test.go?plain=1#L356) -[removing/updating an enum in request body is breaking (optional)](checker/checker_breaking_test.go?plain=1#L315) -[removing/updating an operation id is breaking (optional)](checker/checker_breaking_test.go?plain=1#L294) -[setting the default value of an optional request parameter is breaking](checker/checker_breaking_test.go?plain=1#L578) +[removing/updating a property enum in response is breaking (optional)](checker/checker_breaking_test.go?plain=1#L334) +[removing/updating a tag is breaking (optional)](checker/checker_breaking_test.go?plain=1#L352) +[removing/updating an enum in request body is breaking (optional)](checker/checker_breaking_test.go?plain=1#L311) +[removing/updating an operation id is breaking (optional)](checker/checker_breaking_test.go?plain=1#L290) +[setting the default value of an optional request parameter is breaking](checker/checker_breaking_test.go?plain=1#L574) ## Examples of non-breaking changes [adding a media-type to response is not breaking](checker/checker_not_breaking_test.go?plain=1#L185) @@ -115,7 +115,7 @@ These examples are automatically generated from unit tests. [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#L253) [deleting a path after sunset date of all contained operations is not breaking](checker/checker_deprecation_test.go?plain=1#L266) -[deleting a pattern from a schema is not breaking](checker/checker_breaking_test.go?plain=1#L464) +[deleting a pattern from a schema is not breaking](checker/checker_breaking_test.go?plain=1#L460) [deleting a required write-only property in response body is not breaking](checker/checker_breaking_property_test.go?plain=1#L495) [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) @@ -127,8 +127,8 @@ These examples are automatically generated from unit tests. [deprecating an operation without a deprecation policy and without specifying sunset date is not breaking](checker/checker_deprecation_test.go?plain=1#L104) [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#L546) -[modifying the default value of a required request parameter is not breaking](checker/checker_breaking_test.go?plain=1#L614) +[modifying a pattern to ".*" in a schema is not breaking](checker/checker_breaking_test.go?plain=1#L542) +[modifying the default value of a required request parameter is not breaking](checker/checker_breaking_test.go?plain=1#L610) [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#L39) [new required response header param is not breaking](checker/checker_not_breaking_test.go?plain=1#L153) @@ -137,11 +137,11 @@ These examples are automatically generated from unit tests. [reducing max length in response is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L31) [reducing min items in request is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L206) [reducing min length in request is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L48) -[removing an existing response with error status is not breaking](checker/checker_breaking_test.go?plain=1#L411) -[removing an existing response with unparseable status is not breaking](checker/checker_breaking_test.go?plain=1#L395) +[removing an existing response with error status is not breaking](checker/checker_breaking_test.go?plain=1#L407) +[removing an existing response with unparseable status is not breaking](checker/checker_breaking_test.go?plain=1#L391) [removing the path without a deprecation policy and without specifying sunset date is not breaking for alpha level](checker/checker_deprecation_test.go?plain=1#L119) [removing the path without a deprecation policy and without specifying sunset date is not breaking for draft level](checker/checker_deprecation_test.go?plain=1#L175) -[renaming a path parameter is not breaking](checker/checker_breaking_test.go?plain=1#L141) +[renaming a path parameter is not breaking](checker/checker_breaking_test.go?plain=1#L137) ## Examples of info-level changes for changelog [adding 'allOf' subschema to the request body or request body property](checker/check-request-property-all-of-updated_test.go?plain=1#L12) diff --git a/Dockerfile b/Dockerfile index b8de2aab..93cad639 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ ### Go get dependecies and build ### -FROM golang:1.22.1 as builder +FROM golang:1.22.2 as builder ENV PLATFORM docker WORKDIR /go/src/app COPY go.mod go.sum ./ diff --git a/README.md b/README.md index 77f5a940..0c3ca12a 100644 --- a/README.md +++ b/README.md @@ -254,13 +254,13 @@ oasdiff diff data/header-case/base.yaml data/header-case/revision.yaml --case-in ## Excluding Specific Kinds of Changes You can use the `--exclude-elements` flag to exclude certain kinds of changes: - Use `--exclude-elements examples` to exclude [Examples](https://swagger.io/specification/#example-object) +- Use `--exclude-elements extensions` to exclude [Extensions](https://swagger.io/specification/#specification-extensions) - Use `--exclude-elements description` to exclude description fields - Use `--exclude-elements title` to exclude title fields - Use `--exclude-elements summary` to exclude summary fields - Use `--exclude-elements endpoints` to exclude the [endpoints diff](#paths-vs-endpoints) You can ignore multiple elements with a comma-separated list of excluded elements as in [this example](#ignore-changes-to-description-and-examples). -Note that [Extensions](https://swagger.io/specification/#specification-extensions) are always excluded from the diff. ## Excluding Specific Endpoints You can filter endpoints in two ways: diff --git a/checker/check-api-added_test.go b/checker/check-api-added_test.go index e1957e11..c1067743 100644 --- a/checker/check-api-added_test.go +++ b/checker/check-api-added_test.go @@ -16,7 +16,7 @@ func TestApiAdded_DetectsNewPathsAndNewOperations(t *testing.T) { s2, err := open("../data/new_endpoints/revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIAddedCheck), d, osm, checker.INFO) @@ -44,7 +44,7 @@ func TestApiAdded_DetectsModifiedPathsWithPathParam(t *testing.T) { s2, err := open("../data/new_endpoints/revision_with_path_param.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIAddedCheck), d, osm, checker.INFO) diff --git a/checker/check-api-operation-id-updated_test.go b/checker/check-api-operation-id-updated_test.go index d2188370..50a3e0cd 100644 --- a/checker/check-api-operation-id-updated_test.go +++ b/checker/check-api-operation-id-updated_test.go @@ -18,7 +18,7 @@ func TestOperationIdRemoved(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.OperationID = "" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIOperationIdUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -42,7 +42,7 @@ func TestOperationIdUpdated(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.OperationID = "newOperationId" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIOperationIdUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -68,7 +68,7 @@ func TestOperationIdAdded(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.OperationID = "NewOperationId" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig().WithCheckBreaking(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIOperationIdUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-api-security-updated_test.go b/checker/check-api-security-updated_test.go index 87393588..70cfe244 100644 --- a/checker/check-api-security-updated_test.go +++ b/checker/check-api-security-updated_test.go @@ -16,7 +16,7 @@ func TestAPIGlobalSecurityyAdded(t *testing.T) { s2, err := open("../data/checker/api_security_global_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -35,7 +35,7 @@ func TestAPIGlobalSecurityyDeleted(t *testing.T) { s2, err := open("../data/checker/api_security_global_added_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -55,7 +55,7 @@ func TestAPIGlobalSecurityScopeRemoved(t *testing.T) { require.NoError(t, err) s2.Spec.Security[0]["petstore_auth"] = s2.Spec.Security[0]["petstore_auth"][:1] - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -75,7 +75,7 @@ func TestAPIGlobalSecurityScopeAdded(t *testing.T) { require.NoError(t, err) s1.Spec.Security[0]["petstore_auth"] = s2.Spec.Security[0]["petstore_auth"][:1] - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -94,7 +94,7 @@ func TestAPISecurityAdded(t *testing.T) { s2, err := open("../data/checker/api_security_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -116,7 +116,7 @@ func TestAPISecurityDeleted(t *testing.T) { s2, err := open("../data/checker/api_security_added_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -138,7 +138,7 @@ func TestAPISecurityScopeRemoved(t *testing.T) { s2, err := open("../data/checker/api_security_updated_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -160,7 +160,7 @@ func TestAPISecurityScopeAdded(t *testing.T) { s2, err := open("../data/checker/api_security_updated_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APISecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-api-tag-updated_test.go b/checker/check-api-tag-updated_test.go index 547490f1..620b3b95 100644 --- a/checker/check-api-tag-updated_test.go +++ b/checker/check-api-tag-updated_test.go @@ -18,7 +18,7 @@ func TestTagAdded(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Tags = []string{"newTag"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APITagUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -43,7 +43,7 @@ func TestTagRemoved(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Tags = []string{} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APITagUpdatedCheck), d, osm, checker.INFO) require.NotEmpty(t, errs) @@ -70,7 +70,7 @@ func TestTagUpdated(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Tags = []string{"newTag"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APITagUpdatedCheck), d, osm, checker.INFO) require.NotEmpty(t, errs) diff --git a/checker/check-components-security-updated_test.go b/checker/check-components-security-updated_test.go index 45e4fafc..c6799eb1 100644 --- a/checker/check-components-security-updated_test.go +++ b/checker/check-components-security-updated_test.go @@ -17,7 +17,7 @@ func TestComponentSecurityOauthURLUpdated(t *testing.T) { s2.Spec.Components.SecuritySchemes["petstore_auth"].Value.Flows.Implicit.AuthorizationURL = "http://example.new.org/api/oauth/dialog" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIComponentsSecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -39,7 +39,7 @@ func TestComponentSecurityOauthTokenUpdated(t *testing.T) { s2.Spec.Components.SecuritySchemes["petstore_auth"].Value.Flows.Implicit.TokenURL = "http://example.new.org/api/oauth/dialog" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIComponentsSecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -61,7 +61,7 @@ func TestComponentSecurityTypeUpdated(t *testing.T) { s2.Spec.Components.SecuritySchemes["petstore_auth"].Value.Type = "http" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIComponentsSecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -81,7 +81,7 @@ func TestComponentSecurityAdded(t *testing.T) { s2, err := open("../data/checker/component_security_updated_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIComponentsSecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -101,7 +101,7 @@ func TestComponentSecurityRemoved(t *testing.T) { s2, err := open("../data/checker/component_security_updated_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIComponentsSecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -123,7 +123,7 @@ func TestComponentSecurityOauthScopeAdded(t *testing.T) { s2.Spec.Components.SecuritySchemes["petstore_auth"].Value.Flows.Implicit.Scopes["admin:pets"] = "grants access to admin operations" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIComponentsSecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -146,7 +146,7 @@ func TestComponentSecurityOauthScopeRemoved(t *testing.T) { // Add to s1 so that it's deletion is identified s1.Spec.Components.SecuritySchemes["petstore_auth"].Value.Flows.Implicit.Scopes["admin:pets"] = "grants access to admin operations" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIComponentsSecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -168,7 +168,7 @@ func TestComponentSecurityOauthScopeUpdated(t *testing.T) { s2.Spec.Components.SecuritySchemes["petstore_auth"].Value.Flows.Implicit.Scopes["read:pets"] = "grants access to pets (deprecated)" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIComponentsSecurityUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-body-mediatype-updated_test.go b/checker/check-request-body-mediatype-updated_test.go index e61fc058..61c337d9 100644 --- a/checker/check-request-body-mediatype-updated_test.go +++ b/checker/check-request-body-mediatype-updated_test.go @@ -16,7 +16,7 @@ func TestRequestBodyMediaTypeAdded(t *testing.T) { s2, err := open("../data/checker/request_body_media_type_updated_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestBodyMediaTypeChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -38,7 +38,7 @@ func TestRequestBodyMediaTypeRemoved(t *testing.T) { s2, err := open("../data/checker/request_body_media_type_updated_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestBodyMediaTypeChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-body-required-value-updated_test.go b/checker/check-request-body-required-value-updated_test.go index d1f3a39d..67950e66 100644 --- a/checker/check-request-body-required-value-updated_test.go +++ b/checker/check-request-body-required-value-updated_test.go @@ -18,7 +18,7 @@ func TestRequestBodyBecameRequired(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.RequestBody.Value.Required = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.RequestBodyRequiredUpdatedCheck), d, osm) require.Len(t, errs, 1) @@ -41,7 +41,7 @@ func TestRequestBodyBecameOptional(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.RequestBody.Value.Required = false - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig().WithCheckBreaking(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestBodyRequiredUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-discriminator-updated_test.go b/checker/check-request-discriminator-updated_test.go index d007d161..c75ac798 100644 --- a/checker/check-request-discriminator-updated_test.go +++ b/checker/check-request-discriminator-updated_test.go @@ -17,7 +17,7 @@ func TestRequestDiscriminatorUpdatedCheckAdded(t *testing.T) { s2, err := open("../data/checker/request_property_discriminator_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestDiscriminatorUpdatedCheck), d, osm, checker.INFO) @@ -50,7 +50,7 @@ func TestRequestDiscriminatorUpdatedCheckRemoved(t *testing.T) { s2, err := open("../data/checker/request_property_discriminator_added_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestDiscriminatorUpdatedCheck), d, osm, checker.INFO) @@ -83,7 +83,7 @@ func TestRequestDiscriminatorUpdatedCheckPropertyNameChanging(t *testing.T) { s2, err := open("../data/checker/request_property_discriminator_added_property_name_changed.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestDiscriminatorUpdatedCheck), d, osm, checker.INFO) @@ -117,7 +117,7 @@ func TestRequestDiscriminatorUpdatedCheckMappingChanging(t *testing.T) { s2, err := open("../data/checker/request_property_discriminator_mapping_changed.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestDiscriminatorUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-request-parameter-became-enum_test.go b/checker/check-request-parameter-became-enum_test.go index e9427a0e..d046c087 100644 --- a/checker/check-request-parameter-became-enum_test.go +++ b/checker/check-request-parameter-became-enum_test.go @@ -16,7 +16,7 @@ func TestRequestParameterBecameEnum(t *testing.T) { s2, err := open("../data/checker/request_parameter_became_enum_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterBecameEnumCheck), d, osm, checker.ERR) require.Len(t, errs, 1) diff --git a/checker/check-request-parameter-enum-value-updated_test.go b/checker/check-request-parameter-enum-value-updated_test.go index c7682825..997a754d 100644 --- a/checker/check-request-parameter-enum-value-updated_test.go +++ b/checker/check-request-parameter-enum-value-updated_test.go @@ -16,7 +16,7 @@ func TestRequestParameterEnumValueRemovedCheck(t *testing.T) { s2, err := open("../data/checker/request_parameter_enum_value_updated_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterEnumValueUpdatedCheck), d, osm, checker.ERR) @@ -39,7 +39,7 @@ func TestRequestParameterEnumValueAddedCheck(t *testing.T) { s2, err := open("../data/checker/request_parameter_enum_value_updated_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterEnumValueUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-request-parameter-pattern-added-or-changed_test.go b/checker/check-request-parameter-pattern-added-or-changed_test.go index 45b152b6..050b8153 100644 --- a/checker/check-request-parameter-pattern-added-or-changed_test.go +++ b/checker/check-request-parameter-pattern-added-or-changed_test.go @@ -17,7 +17,7 @@ func TestRequestParameterPatternChanged(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/test").Post.Parameters[0].Value.Schema.Value.Pattern = "^[\\w\\s]+$" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterPatternAddedOrChangedCheck), d, osm, checker.WARN) require.Len(t, errs, 1) @@ -40,7 +40,7 @@ func TestRequestParameterPatternAdded(t *testing.T) { s2, err := open("../data/checker/request_parameter_pattern_added_or_changed_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterPatternAddedOrChangedCheck), d, osm, checker.WARN) require.Len(t, errs, 1) @@ -63,7 +63,7 @@ func TestRequestParameterPatternRemoved(t *testing.T) { s2, err := open("../data/checker/request_parameter_pattern_added_or_changed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterPatternAddedOrChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-parameter-x-extensible-enum-value-removed.go b/checker/check-request-parameter-x-extensible-enum-value-removed.go index c50de9ab..06e99556 100644 --- a/checker/check-request-parameter-x-extensible-enum-value-removed.go +++ b/checker/check-request-parameter-x-extensible-enum-value-removed.go @@ -45,11 +45,11 @@ func RequestParameterXExtensibleEnumValueRemovedCheck(diffReport *diff.Diff, ope if paramItem.SchemaDiff.ExtensionsDiff.Modified[diff.XExtensibleEnumExtension] == nil { continue } - from, ok := paramItem.SchemaDiff.ExtensionsDiff.Modified[diff.XExtensibleEnumExtension].From.(json.RawMessage) + from, ok := paramItem.SchemaDiff.Base.Extensions[diff.XExtensibleEnumExtension].(json.RawMessage) if !ok { continue } - to, ok := paramItem.SchemaDiff.ExtensionsDiff.Modified[diff.XExtensibleEnumExtension].To.(json.RawMessage) + to, ok := paramItem.SchemaDiff.Revision.Extensions[diff.XExtensibleEnumExtension].(json.RawMessage) if !ok { continue } diff --git a/checker/check-request-parameters-default-value-changed_test.go b/checker/check-request-parameters-default-value-changed_test.go index f8dde67b..6f3ce0a8 100644 --- a/checker/check-request-parameters-default-value-changed_test.go +++ b/checker/check-request-parameters-default-value-changed_test.go @@ -16,7 +16,7 @@ func TestRequestParameterDefaultValueChanged(t *testing.T) { s2, err := open("../data/checker/request_parameter_default_value_changed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterDefaultValueChangedCheck), d, osm, checker.ERR) require.Len(t, errs, 1) @@ -40,7 +40,7 @@ func TestRequestParameterDefaultValueAdded(t *testing.T) { s1.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[1].Value.Schema.Value.Default = nil - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterDefaultValueChangedCheck), d, osm, checker.ERR) require.Len(t, errs, 1) @@ -64,7 +64,7 @@ func TestRequestParameterDefaultValueRemoved(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[1].Value.Schema.Value.Default = nil - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterDefaultValueChangedCheck), d, osm, checker.ERR) require.Len(t, errs, 1) diff --git a/checker/check-request-parameters-max-items-updated_test.go b/checker/check-request-parameters-max-items-updated_test.go index 99a87549..ebfba6bb 100644 --- a/checker/check-request-parameters-max-items-updated_test.go +++ b/checker/check-request-parameters-max-items-updated_test.go @@ -16,7 +16,7 @@ func TestRequestParameterMaxItemsIncreased(t *testing.T) { s2, err := open("../data/checker/request_parameter_max_items_updated_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMaxItemsUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -38,7 +38,7 @@ func TestRequestParameterMaxItemsDecreased(t *testing.T) { s2, err := open("../data/checker/request_parameter_max_items_updated_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMaxItemsUpdatedCheck), d, osm, checker.ERR) require.Len(t, errs, 1) diff --git a/checker/check-request-parameters-max-length-updated_test.go b/checker/check-request-parameters-max-length-updated_test.go index 51d110f8..55726c64 100644 --- a/checker/check-request-parameters-max-length-updated_test.go +++ b/checker/check-request-parameters-max-length-updated_test.go @@ -16,7 +16,7 @@ func TestRequestParameterMaxLengthIncreasedCheck(t *testing.T) { s2, err := open("../data/checker/request_parameter_max_length_updated_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMaxLengthUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -37,7 +37,7 @@ func TestRequestParameterMaxLengthDecreasedCheck(t *testing.T) { s2, err := open("../data/checker/request_parameter_max_length_updated_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMaxLengthUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-parameters-max-updated_test.go b/checker/check-request-parameters-max-updated_test.go index d068e647..8027896d 100644 --- a/checker/check-request-parameters-max-updated_test.go +++ b/checker/check-request-parameters-max-updated_test.go @@ -16,7 +16,7 @@ func TestRequestParameterMaxIncreased(t *testing.T) { s2, err := open("../data/checker/request_parameter_max_updated_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMaxUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -38,7 +38,7 @@ func TestRequestParameterMaxDecreased(t *testing.T) { s2, err := open("../data/checker/request_parameter_max_updated_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMaxUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-parameters-min-items-updated_test.go b/checker/check-request-parameters-min-items-updated_test.go index d1bf0993..7c0a0ee6 100644 --- a/checker/check-request-parameters-min-items-updated_test.go +++ b/checker/check-request-parameters-min-items-updated_test.go @@ -16,7 +16,7 @@ func TestRequestParameterMinItemsIncreased(t *testing.T) { s2, err := open("../data/checker/request_parameter_min_items_increased_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMinItemsUpdatedCheck), d, osm, checker.ERR) require.Len(t, errs, 1) @@ -38,7 +38,7 @@ func TestRequestParameterMinItemsDecreased(t *testing.T) { s2, err := open("../data/checker/request_parameter_min_items_increased_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMinItemsUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-parameters-min-length-updated_test.go b/checker/check-request-parameters-min-length-updated_test.go index ee54851f..68d587fc 100644 --- a/checker/check-request-parameters-min-length-updated_test.go +++ b/checker/check-request-parameters-min-length-updated_test.go @@ -16,7 +16,7 @@ func TestRequestParameterMinLengthIncreasedCheck(t *testing.T) { s2, err := open("../data/checker/request_parameter_min_length_increased_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMinLengthUpdatedCheck), d, osm, checker.INFO) @@ -39,7 +39,7 @@ func TestRequestParameterMinLengthDecreasedCheck(t *testing.T) { s2, err := open("../data/checker/request_parameter_min_length_increased_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMinLengthUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-request-parameters-min-updated_test.go b/checker/check-request-parameters-min-updated_test.go index 56ca5a76..02d3d11a 100644 --- a/checker/check-request-parameters-min-updated_test.go +++ b/checker/check-request-parameters-min-updated_test.go @@ -16,7 +16,7 @@ func TestRequestParameterMinIncreased(t *testing.T) { s2, err := open("../data/checker/request_parameter_min_increased_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMinUpdatedCheck), d, osm, checker.ERR) require.Len(t, errs, 1) @@ -38,7 +38,7 @@ func TestRequestParameterMinDecreased(t *testing.T) { s2, err := open("../data/checker/request_parameter_min_increased_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMinUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-parameters-type-changed_test.go b/checker/check-request-parameters-type-changed_test.go index 6dc5db3c..b504dd74 100644 --- a/checker/check-request-parameters-type-changed_test.go +++ b/checker/check-request-parameters-type-changed_test.go @@ -18,7 +18,7 @@ func TestRequestPathParamTypeChanged(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[0].Value.Schema.Value.Type = "int" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterTypeChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -42,7 +42,7 @@ func TestRequestQueryParamTypeChanged(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[1].Value.Schema.Value.Type = "int" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterTypeChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -66,7 +66,7 @@ func TestRequestQueryHeaderTypeChanged(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[2].Value.Schema.Value.Type = "int" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterTypeChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -90,7 +90,7 @@ func TestRequestPathParamFormatChanged(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[0].Value.Schema.Value.Format = "uuid" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterTypeChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -114,7 +114,7 @@ func TestRequestQueryParamFormatChanged(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[1].Value.Schema.Value.Format = "uri" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterTypeChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -138,7 +138,7 @@ func TestRequestQueryHeaderFormatChanged(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[2].Value.Schema.Value.Format = "uri" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterTypeChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-property-all-of-updated_test.go b/checker/check-request-property-all-of-updated_test.go index c8d837e0..cd3064a2 100644 --- a/checker/check-request-property-all-of-updated_test.go +++ b/checker/check-request-property-all-of-updated_test.go @@ -16,7 +16,7 @@ func TestRequestPropertyAllOfAdded(t *testing.T) { s2, err := open("../data/checker/request_property_all_of_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyAllOfUpdatedCheck), d, osm, checker.INFO) @@ -50,7 +50,7 @@ func TestRequestPropertyAllOfRemoved(t *testing.T) { s2, err := open("../data/checker/request_property_all_of_removed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyAllOfUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-request-property-any-of-updated_test.go b/checker/check-request-property-any-of-updated_test.go index b2a7219c..5960ec8e 100644 --- a/checker/check-request-property-any-of-updated_test.go +++ b/checker/check-request-property-any-of-updated_test.go @@ -16,7 +16,7 @@ func TestRequestPropertyAnyOfAdded(t *testing.T) { s2, err := open("../data/checker/request_property_any_of_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyAnyOfUpdatedCheck), d, osm, checker.INFO) @@ -50,7 +50,7 @@ func TestRequestPropertyAnyOfRemoved(t *testing.T) { s2, err := open("../data/checker/request_property_any_of_removed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyAnyOfUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-request-property-became-not-nuallable_test.go b/checker/check-request-property-became-not-nuallable_test.go index cd846380..dbd64069 100644 --- a/checker/check-request-property-became-not-nuallable_test.go +++ b/checker/check-request-property-became-not-nuallable_test.go @@ -16,7 +16,7 @@ func TestRequestPropertyBecameNotNullable(t *testing.T) { s2, err := open("../data/checker/request_property_became_nullable_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyBecameNotNullableCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -38,7 +38,7 @@ func TestRequestPropertyBecameNullable(t *testing.T) { s2, err := open("../data/checker/request_property_became_nullable_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyBecameNotNullableCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -63,7 +63,7 @@ func TestRequestBodyBecameNullable(t *testing.T) { s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Nullable = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyBecameNotNullableCheck), d, osm, checker.INFO) @@ -87,7 +87,7 @@ func TestRequestBodyBecameNotNullable(t *testing.T) { s1.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Nullable = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyBecameNotNullableCheck), d, osm, checker.ERR) diff --git a/checker/check-request-property-default-value-changed_test.go b/checker/check-request-property-default-value-changed_test.go index 524c5082..9b48bd49 100644 --- a/checker/check-request-property-default-value-changed_test.go +++ b/checker/check-request-property-default-value-changed_test.go @@ -16,7 +16,7 @@ func TestRequestBodyDefaultValueChanged(t *testing.T) { s2, err := open("../data/checker/request_body_default_value_changed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyDefaultValueChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -40,7 +40,7 @@ func TestRequestPropertyDefaultValueChanged(t *testing.T) { s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["price"].Value.Default = 20.0 - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyDefaultValueChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -65,7 +65,7 @@ func TestRequestBodyDefaultValueAdded(t *testing.T) { s1.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["text/plain"].Schema.Value.Default = nil s1.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["price"].Value.Default = nil - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyDefaultValueChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 2) @@ -98,7 +98,7 @@ func TestRequestBodyDefaultValueRemoving(t *testing.T) { s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["text/plain"].Schema.Value.Default = nil s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["price"].Value.Default = nil - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyDefaultValueChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 2) diff --git a/checker/check-request-property-enum-value-updated_test.go b/checker/check-request-property-enum-value-updated_test.go index 26eb171b..8813f9ec 100644 --- a/checker/check-request-property-enum-value-updated_test.go +++ b/checker/check-request-property-enum-value-updated_test.go @@ -18,7 +18,7 @@ func TestRequestPropertyEnumValueRemovedCheck(t *testing.T) { s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["category"].Value.Enum = []interface{}{"dog", "cat"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyEnumValueUpdatedCheck), d, osm, checker.ERR) @@ -45,7 +45,7 @@ func TestRequestPropertyEnumValueAddedCheck(t *testing.T) { s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["category"].Value.Enum = []interface{}{"dog", "cat"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyEnumValueUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-request-property-max-length-updated_test.go b/checker/check-request-property-max-length-updated_test.go index 3c6dd787..69e1bca2 100644 --- a/checker/check-request-property-max-length-updated_test.go +++ b/checker/check-request-property-max-length-updated_test.go @@ -21,7 +21,7 @@ func TestRequestBodyMaxLengthDecreasedCheck(t *testing.T) { s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &maxLength s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &newMaxLength - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.INFO) @@ -49,7 +49,7 @@ func TestRequestBodyMaxLengthIncreasedCheck(t *testing.T) { s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &maxLength s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &newMaxLength - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.ERR) @@ -76,7 +76,7 @@ func TestRequestPropertyMaxLengthDecreasedCheck(t *testing.T) { newMaxLength := uint64(50) s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &maxLength s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &newMaxLength - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.INFO) @@ -103,7 +103,7 @@ func TestRequestPropertyMaxLengthIncreasedCheck(t *testing.T) { newMaxLength := uint64(100) s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &maxLength s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &newMaxLength - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-request-property-max-updated_test.go b/checker/check-request-property-max-updated_test.go index 63524763..f09e6713 100644 --- a/checker/check-request-property-max-updated_test.go +++ b/checker/check-request-property-max-updated_test.go @@ -19,7 +19,7 @@ func TestRequestPropertyMaxDecreasedCheck(t *testing.T) { max := float64(10) s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.Max = &max - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxDecreasedCheck), d, osm, checker.INFO) @@ -45,7 +45,7 @@ func TestRequestPropertyMaxIncreasingCheck(t *testing.T) { max := float64(20) s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.Max = &max - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxDecreasedCheck), d, osm, checker.INFO) @@ -73,7 +73,7 @@ func TestRequestBodyMaxIncreasingCheck(t *testing.T) { s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &max s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &newMax - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxDecreasedCheck), d, osm, checker.INFO) @@ -101,7 +101,7 @@ func TestRequestBodyMaxDecreasedCheck(t *testing.T) { s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &max s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &newMax - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxDecreasedCheck), d, osm, checker.INFO) diff --git a/checker/check-request-property-min-length-updated_test.go b/checker/check-request-property-min-length-updated_test.go index 0d3b514d..ee6ce5bd 100644 --- a/checker/check-request-property-min-length-updated_test.go +++ b/checker/check-request-property-min-length-updated_test.go @@ -18,7 +18,7 @@ func TestRequestPropertyMinLengthDecreased(t *testing.T) { s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.MinLength = uint64(2) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMinLengthUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -42,7 +42,7 @@ func TestRequestPropertyMinLengthIncreased(t *testing.T) { s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.MinLength = uint64(5) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMinLengthUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -66,7 +66,7 @@ func TestRequestBodyMinLengthIncreased(t *testing.T) { s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.MinLength = uint64(100) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMinLengthUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -90,7 +90,7 @@ func TestRequestBodyMinLengthDecreased(t *testing.T) { s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.MinLength = uint64(1) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMinLengthUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-property-min-updated_test.go b/checker/check-request-property-min-updated_test.go index 37f88fce..c28d439d 100644 --- a/checker/check-request-property-min-updated_test.go +++ b/checker/check-request-property-min-updated_test.go @@ -16,7 +16,7 @@ func TestRequestPropertyMinIncreasedCheck(t *testing.T) { s2, err := open("../data/checker/request_property_min_increased_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMinIncreasedCheck), d, osm, checker.ERR) @@ -39,7 +39,7 @@ func TestRequestPropertyMinDecreasedCheck(t *testing.T) { s2, err := open("../data/checker/request_property_min_increased_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMinIncreasedCheck), d, osm, checker.INFO) diff --git a/checker/check-request-property-one-of-updated_test.go b/checker/check-request-property-one-of-updated_test.go index 5a394240..0a5a924e 100644 --- a/checker/check-request-property-one-of-updated_test.go +++ b/checker/check-request-property-one-of-updated_test.go @@ -16,7 +16,7 @@ func TestRequestPropertyOneOfAdded(t *testing.T) { s2, err := open("../data/checker/request_property_one_of_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyOneOfUpdatedCheck), d, osm, checker.INFO) @@ -50,7 +50,7 @@ func TestRequestPropertyOneOfRemoved(t *testing.T) { s2, err := open("../data/checker/request_property_one_of_removed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyOneOfUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-request-property-pattern-added-or-changed_test.go b/checker/check-request-property-pattern-added-or-changed_test.go index 8229fe8a..573f3d67 100644 --- a/checker/check-request-property-pattern-added-or-changed_test.go +++ b/checker/check-request-property-pattern-added-or-changed_test.go @@ -18,7 +18,7 @@ func TestRequestPropertyPatternChanged(t *testing.T) { s2.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.Pattern = "^[\\w\\s]+$" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyPatternUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -41,7 +41,7 @@ func TestRequestPropertyPatternAdded(t *testing.T) { s2, err := open("../data/checker/request_property_pattern_added_or_changed_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyPatternUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -64,7 +64,7 @@ func TestRequestPropertyPatternRemoved(t *testing.T) { s2, err := open("../data/checker/request_property_pattern_added_or_changed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyPatternUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-property-required-updated_test.go b/checker/check-request-property-required-updated_test.go index 72353318..7ab69fc4 100644 --- a/checker/check-request-property-required-updated_test.go +++ b/checker/check-request-property-required-updated_test.go @@ -17,7 +17,7 @@ func TestRequestPropertyMarkedRequired(t *testing.T) { require.NoError(t, err) s1.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Required = []string{""} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyRequiredUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -40,7 +40,7 @@ func TestRequestPropertyMarkedOptional(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Required = []string{""} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyRequiredUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-property-type-changed_test.go b/checker/check-request-property-type-changed_test.go index f5a1f24a..a0543d95 100644 --- a/checker/check-request-property-type-changed_test.go +++ b/checker/check-request-property-type-changed_test.go @@ -18,7 +18,7 @@ func TestRequestBodyTypeChangedCheck(t *testing.T) { s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "array" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyTypeChangedCheck), d, osm, checker.ERR) @@ -43,7 +43,7 @@ func TestRequestBodyFormatChangedCheck(t *testing.T) { s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Format = "uuid" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyTypeChangedCheck), d, osm, checker.ERR) @@ -66,7 +66,7 @@ func TestRequestPropertyTypeChangedCheck(t *testing.T) { s2, err := open("../data/checker/request_property_type_changed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyTypeChangedCheck), d, osm, checker.ERR) @@ -89,7 +89,7 @@ func TestRequestBodyAndPropertyTypesChangedCheckArrayToObject(t *testing.T) { s2, err := open("../data/checker/request_property_type_changed_revision_array_to_object.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyTypeChangedCheck), d, osm, checker.ERR) @@ -121,7 +121,7 @@ func TestRequestBodyAndPropertyTypesChangedCheckObjectToArray(t *testing.T) { s2, err := open("../data/checker/request_property_type_changed_base_array_to_object.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyTypeChangedCheck), d, osm, checker.ERR) @@ -155,7 +155,7 @@ func TestRequestPropertyFormatChangedCheck(t *testing.T) { s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["age"].Value.Format = "uuid" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyTypeChangedCheck), d, osm, checker.ERR) @@ -180,7 +180,7 @@ func TestRequestPropertyFormatChangedCheckNonBreaking(t *testing.T) { s1.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["age"].Value.Type = "integer" s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["age"].Value.Type = "number" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyTypeChangedCheck), d, osm, checker.INFO) diff --git a/checker/check-request-property-updated_test.go b/checker/check-request-property-updated_test.go index 8ef8ad11..58785d58 100644 --- a/checker/check-request-property-updated_test.go +++ b/checker/check-request-property-updated_test.go @@ -16,7 +16,7 @@ func TestRequiredRequestPropertyAdded(t *testing.T) { s2, err := open("../data/checker/request_property_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -38,7 +38,7 @@ func TestRequiredRequestPropertiesAdded(t *testing.T) { s2, err := open("../data/checker/request_property_added_revision2.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyUpdatedCheck), d, osm, checker.INFO) require.ElementsMatch(t, []checker.ApiChange{ @@ -70,7 +70,7 @@ func TestRequiredOptionalPropertyAdded(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Required = []string{"name"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -92,7 +92,7 @@ func TestRequiredRequestPropertyRemoved(t *testing.T) { s2, err := open("../data/checker/request_property_added_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-property-write-only-read-only_test.go b/checker/check-request-property-write-only-read-only_test.go index 3557f971..4f8553b8 100644 --- a/checker/check-request-property-write-only-read-only_test.go +++ b/checker/check-request-property-write-only-read-only_test.go @@ -19,7 +19,7 @@ func TestRequestOptionalPropertyBecameWriteOnly(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.WriteOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -44,7 +44,7 @@ func TestRequestOptionalPropertyBecameNotWriteOnly(t *testing.T) { s1.Spec.Paths.Value("/api/v1.0/groups").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.WriteOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -69,7 +69,7 @@ func TestRequestOptionalPropertyBecameReadOnly(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.ReadOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -94,7 +94,7 @@ func TestRequestOptionalPropertyBecameNonReadOnly(t *testing.T) { s1.Spec.Paths.Value("/api/v1.0/groups").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.ReadOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -119,7 +119,7 @@ func TestRequestRequiredPropertyBecameWriteOnly(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["id"].Value.WriteOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -144,7 +144,7 @@ func TestRequestRequiredPropertyBecameNotWriteOnly(t *testing.T) { s1.Spec.Paths.Value("/api/v1.0/groups").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["id"].Value.WriteOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -169,7 +169,7 @@ func TestRequestRequiredPropertyBecameReadOnly(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["id"].Value.ReadOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -194,7 +194,7 @@ func TestRequestRequiredPropertyBecameNonReadOnly(t *testing.T) { s1.Spec.Paths.Value("/api/v1.0/groups").Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["id"].Value.ReadOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-request-property-x-extensible-enum-value-removed.go b/checker/check-request-property-x-extensible-enum-value-removed.go index fdf8b25c..d8e2f73a 100644 --- a/checker/check-request-property-x-extensible-enum-value-removed.go +++ b/checker/check-request-property-x-extensible-enum-value-removed.go @@ -45,11 +45,11 @@ func RequestPropertyXExtensibleEnumValueRemovedCheck(diffReport *diff.Diff, oper if propertyDiff.ExtensionsDiff.Modified[diff.XExtensibleEnumExtension] == nil { return } - from, ok := propertyDiff.ExtensionsDiff.Modified[diff.XExtensibleEnumExtension].From.(json.RawMessage) + from, ok := propertyDiff.Base.Extensions[diff.XExtensibleEnumExtension].(json.RawMessage) if !ok { return } - to, ok := propertyDiff.ExtensionsDiff.Modified[diff.XExtensibleEnumExtension].To.(json.RawMessage) + to, ok := propertyDiff.Base.Extensions[diff.XExtensibleEnumExtension].(json.RawMessage) if !ok { return } diff --git a/checker/check-response-discriminator-updated_test.go b/checker/check-response-discriminator-updated_test.go index 956323fa..f9b2529f 100644 --- a/checker/check-response-discriminator-updated_test.go +++ b/checker/check-response-discriminator-updated_test.go @@ -17,7 +17,7 @@ func TestResponseDiscriminatorUpdatedCheckAdded(t *testing.T) { s2, err := open("../data/checker/response_property_discriminator_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseDiscriminatorUpdatedCheck), d, osm, checker.INFO) @@ -51,7 +51,7 @@ func TestResponseDiscriminatorUpdatedCheckRemoved(t *testing.T) { s2, err := open("../data/checker/response_property_discriminator_added_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseDiscriminatorUpdatedCheck), d, osm, checker.INFO) @@ -85,7 +85,7 @@ func TestResponseDiscriminatorUpdatedCheckPropertyNameChanging(t *testing.T) { s2, err := open("../data/checker/response_property_discriminator_added_property_name_changed.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseDiscriminatorUpdatedCheck), d, osm, checker.INFO) @@ -119,7 +119,7 @@ func TestResponseDiscriminatorUpdatedCheckMappingChanging(t *testing.T) { s2, err := open("../data/checker/response_property_discriminator_mapping_changed.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseDiscriminatorUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-response-mediatype-updated_test.go b/checker/check-response-mediatype-updated_test.go index 06a4f52f..e14c4eef 100644 --- a/checker/check-response-mediatype-updated_test.go +++ b/checker/check-response-mediatype-updated_test.go @@ -16,7 +16,7 @@ func TestAddNewMediaType(t *testing.T) { s2, err := open("../data/checker/add_new_media_type_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseMediaTypeUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -38,7 +38,7 @@ func TestDeleteNewMediaType(t *testing.T) { s2, err := open("../data/checker/add_new_media_type_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseMediaTypeUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-response-optional-property-updated_test.go b/checker/check-response-optional-property-updated_test.go index d2205d32..3e7e882c 100644 --- a/checker/check-response-optional-property-updated_test.go +++ b/checker/check-response-optional-property-updated_test.go @@ -16,7 +16,7 @@ func TestResponseOptionalPropertyUpdatedCheck(t *testing.T) { s2, err := open("../data/checker/response_optional_property_removed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseOptionalPropertyUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -38,7 +38,7 @@ func TestResponseOptionalPropertyAddedCheck(t *testing.T) { s2, err := open("../data/checker/response_optional_property_removed_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseOptionalPropertyUpdatedCheck), d, osm, checker.INFO) @@ -62,7 +62,7 @@ func TestResponseOptionalWriteOnlyPropertyRemovedCheck(t *testing.T) { require.NoError(t, err) s1.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Value("200").Value.Content["application/json"].Schema.Value.Properties["data"].Value.Properties["id"].Value.WriteOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseOptionalPropertyUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -85,7 +85,7 @@ func TestResponseOptionalWriteOnlyPropertyAddedCheck(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Value("200").Value.Content["application/json"].Schema.Value.Properties["data"].Value.Properties["id"].Value.WriteOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseOptionalPropertyUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-response-optional-property-write-only-read-only_test.go b/checker/check-response-optional-property-write-only-read-only_test.go index b08b4ef4..9ea88862 100644 --- a/checker/check-response-optional-property-write-only-read-only_test.go +++ b/checker/check-response-optional-property-write-only-read-only_test.go @@ -18,7 +18,7 @@ func TestResponseOptionalPropertyBecameWriteOnly(t *testing.T) { require.NoError(t, err) s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["name"].Value.WriteOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseOptionalPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -43,7 +43,7 @@ func TestResponseOptionalPropertyBecameNotWriteOnly(t *testing.T) { require.NoError(t, err) s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["writeOnlyName"].Value.WriteOnly = false - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseOptionalPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -68,7 +68,7 @@ func TestResponseOptionalPropertyBecameReadOnly(t *testing.T) { require.NoError(t, err) s1.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["id"].Value.ReadOnly = false - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseOptionalPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -94,7 +94,7 @@ func TestResponseOptionalPropertyBecameNonReadOnly(t *testing.T) { s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["id"].Value.ReadOnly = false - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseOptionalPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-response-pattern-added-or-changed_test.go b/checker/check-response-pattern-added-or-changed_test.go index ad4c8672..340c830f 100644 --- a/checker/check-response-pattern-added-or-changed_test.go +++ b/checker/check-response-pattern-added-or-changed_test.go @@ -18,7 +18,7 @@ func TestResponsePropertyPatternChanged(t *testing.T) { require.NoError(t, err) s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["name"].Value.WriteOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePatternAddedOrChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -43,7 +43,7 @@ func TestResponsePropertyPatternAdded(t *testing.T) { require.NoError(t, err) s1.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["created"].Value.Pattern = "" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePatternAddedOrChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -68,7 +68,7 @@ func TestResponsePropertyPatternRemoved(t *testing.T) { require.NoError(t, err) s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["created"].Value.Pattern = "" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePatternAddedOrChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-response-property-all-of-updated_test.go b/checker/check-response-property-all-of-updated_test.go index 6dd1e84a..1012aebd 100644 --- a/checker/check-response-property-all-of-updated_test.go +++ b/checker/check-response-property-all-of-updated_test.go @@ -16,7 +16,7 @@ func TestResponsePropertyAllOfAdded(t *testing.T) { s2, err := open("../data/checker/response_property_all_of_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyAllOfUpdatedCheck), d, osm, checker.INFO) @@ -50,7 +50,7 @@ func TestResponsePropertyAllOfRemoved(t *testing.T) { s2, err := open("../data/checker/response_property_all_of_removed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyAllOfUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-response-property-any-of-updated_test.go b/checker/check-response-property-any-of-updated_test.go index 66c88b35..7c70a408 100644 --- a/checker/check-response-property-any-of-updated_test.go +++ b/checker/check-response-property-any-of-updated_test.go @@ -16,7 +16,7 @@ func TestResponsePropertyAnyOfAdded(t *testing.T) { s2, err := open("../data/checker/response_property_any_of_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyAnyOfUpdatedCheck), d, osm, checker.INFO) @@ -50,7 +50,7 @@ func TestResponsePropertyAnyOfRemoved(t *testing.T) { s2, err := open("../data/checker/response_property_any_of_removed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyAnyOfUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-response-property-became-optional_test.go b/checker/check-response-property-became-optional_test.go index d8703ef9..6c4f7655 100644 --- a/checker/check-response-property-became-optional_test.go +++ b/checker/check-response-property-became-optional_test.go @@ -15,7 +15,7 @@ func TestResponsePropertyBecameOptionalCheck(t *testing.T) { require.NoError(t, err) s2, err := open("../data/checker/response_property_became_optional_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyBecameOptionalCheck), d, osm, checker.ERR) require.Len(t, errs, 1) @@ -36,7 +36,7 @@ func TestResponseWriteOnlyPropertyBecameOptionalCheck(t *testing.T) { require.NoError(t, err) s2, err := open("../data/checker/response_property_became_optional_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) s1.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["name"].Value.WriteOnly = true diff --git a/checker/check-response-property-became-required_test.go b/checker/check-response-property-became-required_test.go index 87cf5154..656aa4de 100644 --- a/checker/check-response-property-became-required_test.go +++ b/checker/check-response-property-became-required_test.go @@ -15,7 +15,7 @@ func TestResponsePropertyBecameRequiredlCheck(t *testing.T) { require.NoError(t, err) s2, err := open("../data/checker/response_property_became_optional_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyBecameRequiredCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -36,7 +36,7 @@ func TestResponseWriteOnlyPropertyBecameRequiredCheck(t *testing.T) { require.NoError(t, err) s2, err := open("../data/checker/response_property_became_optional_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) s1.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["name"].Value.WriteOnly = true diff --git a/checker/check-response-property-default-value-changed_test.go b/checker/check-response-property-default-value-changed_test.go index 8e2e2bb5..c65b859e 100644 --- a/checker/check-response-property-default-value-changed_test.go +++ b/checker/check-response-property-default-value-changed_test.go @@ -15,7 +15,7 @@ func TestResponsePropertyDefaultValueUpdatedCheck(t *testing.T) { require.NoError(t, err) s2, err := open("../data/checker/response_property_default_value_changed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 2) @@ -46,7 +46,7 @@ func TestResponseSchemaDefaultValueUpdatedCheck(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Value("404").Value.Content["text/plain"].Schema.Value.Default = "new default value" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -71,7 +71,7 @@ func TestResponsePropertyDefaultValueAddedCheck(t *testing.T) { s1.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Value("404").Value.Content["text/plain"].Schema.Value.Default = nil s1.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["created"].Value.Default = nil - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 2) @@ -104,7 +104,7 @@ func TestResponsePropertyDefaultValueRemovedCheck(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Value("404").Value.Content["text/plain"].Schema.Value.Default = nil s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["created"].Value.Default = nil - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO) require.Len(t, errs, 2) diff --git a/checker/check-response-property-enum-value-added_test.go b/checker/check-response-property-enum-value-added_test.go index c4c87f73..277397aa 100644 --- a/checker/check-response-property-enum-value-added_test.go +++ b/checker/check-response-property-enum-value-added_test.go @@ -18,7 +18,7 @@ func TestResponsePropertyEnumValueAdded(t *testing.T) { s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["typeEnum"].Value.Enum = []interface{}{"Test"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyEnumValueAddedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -44,7 +44,7 @@ func TestResponseWriteOnlyPropertyEnumValueAdded(t *testing.T) { s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["writeOnlyEnum"].Value.Enum = []interface{}{"Test"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyEnumValueAddedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-response-property-enum-value-removed_test.go b/checker/check-response-property-enum-value-removed_test.go index e57f1c44..36598668 100644 --- a/checker/check-response-property-enum-value-removed_test.go +++ b/checker/check-response-property-enum-value-removed_test.go @@ -18,7 +18,7 @@ func TestResponsePropertyEnumValueRemoved(t *testing.T) { s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["typeEnum"].Value.Enum = []interface{}{"TYPE1"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseParameterEnumValueRemovedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -42,7 +42,7 @@ func TestResponseWriteOnlyPropertyEnumValueRemoved(t *testing.T) { s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["writeOnlyEnum"].Value.Enum = []interface{}{"TYPE1"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseParameterEnumValueRemovedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-response-property-one-of-updated_test.go b/checker/check-response-property-one-of-updated_test.go index efcd1f96..48535739 100644 --- a/checker/check-response-property-one-of-updated_test.go +++ b/checker/check-response-property-one-of-updated_test.go @@ -16,7 +16,7 @@ func TestResponsePropertyOneOfAdded(t *testing.T) { s2, err := open("../data/checker/response_property_one_of_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyOneOfUpdated), d, osm, checker.INFO) @@ -59,7 +59,7 @@ func TestResponsePropertyOneOfRemoved(t *testing.T) { s2, err := open("../data/checker/response_property_one_of_removed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyOneOfUpdated), d, osm, checker.INFO) diff --git a/checker/check-response-property-type-changed_test.go b/checker/check-response-property-type-changed_test.go index 88fb6421..ae3ef16b 100644 --- a/checker/check-response-property-type-changed_test.go +++ b/checker/check-response-property-type-changed_test.go @@ -16,7 +16,7 @@ func TestResponseSchemaTypeChangedCheck(t *testing.T) { s2, err := open("../data/checker/response_schema_type_changed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyTypeChangedCheck), d, osm, checker.ERR) require.Len(t, errs, 1) @@ -40,7 +40,7 @@ func TestResponsePropertyTypeChangedCheck(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Value("200").Value.Content["application/json"].Schema.Value.Properties["data"].Value.Properties["name"].Value.Type = "integer" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyTypeChangedCheck), d, osm, checker.ERR) require.Len(t, errs, 1) @@ -64,7 +64,7 @@ func TestResponsePropertyFormatChangedCheck(t *testing.T) { s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Value("200").Value.Content["application/json"].Schema.Value.Properties["data"].Value.Properties["name"].Value.Format = "uuid" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyTypeChangedCheck), d, osm, checker.ERR) require.Len(t, errs, 1) diff --git a/checker/check-response-required-property-updated_test.go b/checker/check-response-required-property-updated_test.go index f5d3b1ee..edf7ca75 100644 --- a/checker/check-response-required-property-updated_test.go +++ b/checker/check-response-required-property-updated_test.go @@ -16,7 +16,7 @@ func TestResponseRequiredPropertyAdded(t *testing.T) { s2, err := open("../data/checker/response_required_property_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseRequiredPropertyUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -40,7 +40,7 @@ func TestResponseRequiredPropertyRemoved(t *testing.T) { require.NoError(t, err) s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Required = []string{"name", "id"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseRequiredPropertyUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -64,7 +64,7 @@ func TestResponseRequiredWriteOnlyPropertyAdded(t *testing.T) { s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["new"].Value.WriteOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseRequiredPropertyUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -89,7 +89,7 @@ func TestResponseRequiredWriteOnlyPropertyRemoved(t *testing.T) { s1.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["new"].Value.WriteOnly = true s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Required = []string{"name", "id"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseRequiredPropertyUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-response-required-property-write-only-read-only_test.go b/checker/check-response-required-property-write-only-read-only_test.go index 94210ef1..99a5d6ab 100644 --- a/checker/check-response-required-property-write-only-read-only_test.go +++ b/checker/check-response-required-property-write-only-read-only_test.go @@ -18,7 +18,7 @@ func TestResponseRequiredPropertyBecameWriteOnly(t *testing.T) { require.NoError(t, err) s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["name"].Value.WriteOnly = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseRequiredPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -43,7 +43,7 @@ func TestResponseRequiredPropertyBecameNotWriteOnly(t *testing.T) { require.NoError(t, err) s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["writeOnlyName"].Value.WriteOnly = false - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseRequiredPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -71,7 +71,7 @@ func TestResponseRequiredPropertyBecameReadOnly(t *testing.T) { require.NoError(t, err) s1.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["id"].Value.ReadOnly = false - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseRequiredPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -97,7 +97,7 @@ func TestResponseRequiredPropertyBecameNonReadOnly(t *testing.T) { s2.Spec.Components.Schemas["GroupView"].Value.Properties["data"].Value.Properties["id"].Value.ReadOnly = false - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseRequiredPropertyWriteOnlyReadOnlyCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/check-response-status-updated_test.go b/checker/check-response-status-updated_test.go index 714e83ca..a875b6f1 100644 --- a/checker/check-response-status-updated_test.go +++ b/checker/check-response-status-updated_test.go @@ -19,7 +19,7 @@ func TestResponseSuccessStatusAdded(t *testing.T) { // Add new success response s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Set("201", s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Value("200")) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseSuccessStatusUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -44,7 +44,7 @@ func TestResponseNonSuccessStatusAdded(t *testing.T) { // Add new non-success response s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Set("400", s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Value("409")) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseNonSuccessStatusUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -68,7 +68,7 @@ func TestResponseNonSuccessStatusRemoved(t *testing.T) { delete(s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Map(), "409") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseNonSuccessStatusUpdatedCheck), d, osm, checker.INFO) require.NotEmpty(t, errs) @@ -93,7 +93,7 @@ func TestResponseSuccessStatusRemoved(t *testing.T) { delete(s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Map(), "200") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseSuccessStatusUpdatedCheck), d, osm, checker.INFO) require.NotEmpty(t, errs) diff --git a/checker/checker_breaking_min_max_test.go b/checker/checker_breaking_min_max_test.go index 6227b161..5d79d80d 100644 --- a/checker/checker_breaking_min_max_test.go +++ b/checker/checker_breaking_min_max_test.go @@ -20,7 +20,7 @@ func TestBreaking_RequestMaxLengthSmaller(t *testing.T) { maxLengthTo := uint64(11) s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthTo - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -39,7 +39,7 @@ func TestBreaking_ResponseMaxLengthSmaller(t *testing.T) { maxLengthTo := uint64(11) s2.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MaxLength = &maxLengthTo - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -53,7 +53,7 @@ func TestBreaking_RequestMinLengthSmaller(t *testing.T) { s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MinLength = uint64(13) s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MinLength = uint64(11) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -67,7 +67,7 @@ func TestBreaking_MinLengthSmaller(t *testing.T) { s1.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MinLength = uint64(13) s2.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MinLength = uint64(11) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Equal(t, checker.ResponseBodyMinLengthDecreasedId, errs[0].GetId()) @@ -84,7 +84,7 @@ func TestBreaking_RequestMaxLengthGreater(t *testing.T) { maxLengthTo := uint64(14) s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthTo - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -101,7 +101,7 @@ func TestBreaking_ResponseMaxLengthGreater(t *testing.T) { maxLengthTo := uint64(14) s2.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MaxLength = &maxLengthTo - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -117,7 +117,7 @@ func TestBreaking_MaxLengthFromNil(t *testing.T) { maxLengthTo := uint64(14) s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthTo - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -135,7 +135,7 @@ func TestBreaking_ResponseMaxLengthFromNil(t *testing.T) { maxLengthTo := uint64(14) s2.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MaxLength = &maxLengthTo - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -151,7 +151,7 @@ func TestBreaking_RequestMaxLengthToNil(t *testing.T) { s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = nil - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -167,7 +167,7 @@ func TestBreaking_ResponseMaxLengthToNil(t *testing.T) { s2.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MaxLength = nil - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -183,7 +183,7 @@ func TestBreaking_MaxLengthBothNil(t *testing.T) { s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = nil s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = nil - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -197,7 +197,7 @@ func TestBreaking_ResponseMaxLengthBothNil(t *testing.T) { s1.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MaxLength = nil s2.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MaxLength = nil - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -211,7 +211,7 @@ func TestBreaking_RequestMinItemsSmaller(t *testing.T) { s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MinItems = 13 s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MinItems = 11 - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -225,7 +225,7 @@ func TestBreaking_ResponseMinItemsSmaller(t *testing.T) { s1.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MinItems = 13 s2.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MinItems = 11 - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -241,7 +241,7 @@ func TestBreaking_RequeatMinItemsGreater(t *testing.T) { s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MinItems = 13 s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MinItems = 14 - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -255,7 +255,7 @@ func TestBreaking_ResponseMinItemsGreater(t *testing.T) { s1.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MinItems = 13 s2.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MinItems = 14 - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -272,7 +272,7 @@ func TestBreaking_MaxSmaller(t *testing.T) { maxTo := float64(11) s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.Max = &maxTo - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -289,7 +289,7 @@ func TestBreaking_MaxSmallerInResponse(t *testing.T) { maxTo := float64(11) s2.Spec.Paths.Value(installCommandPath).Get.Responses.Value("default").Value.Headers["X-RateLimit-Limit"].Value.Schema.Value.Max = &maxTo - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) diff --git a/checker/checker_breaking_property_test.go b/checker/checker_breaking_property_test.go index 48c5cec9..81f416e6 100644 --- a/checker/checker_breaking_property_test.go +++ b/checker/checker_breaking_property_test.go @@ -28,7 +28,7 @@ func TestBreaking_NewRequiredProperty(t *testing.T) { } s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Required = []string{"courseId"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -48,7 +48,7 @@ func TestBreaking_NewNonRequiredProperty(t *testing.T) { }, } - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -72,7 +72,7 @@ func TestBreaking_PropertyRequiredEnabled(t *testing.T) { s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Properties["courseId"] = &sr s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Required = []string{"courseId"} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -98,7 +98,7 @@ func TestBreaking_PropertyRequiredDisabled(t *testing.T) { s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Properties["courseId"] = &sr s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Required = []string{} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -112,7 +112,7 @@ func TestBreaking_RespBodyRequiredPropertyDisabled(t *testing.T) { s2, err := open(getReqPropFile("response-revision.json")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -128,7 +128,7 @@ func TestBreaking_ReqBodyBecameEnum(t *testing.T) { s2, err := open("../data/enums/request-body-enum.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -144,7 +144,7 @@ func TestBreaking_ReqBodyEnumValueAdded(t *testing.T) { s2, err := open("../data/enums/request-body-enum-revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -158,7 +158,7 @@ func TestBreaking_ReqBodyBecameEnumAndTypeChanged(t *testing.T) { s2, err := open("../data/enums/request-body-enum-int.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 2) @@ -174,7 +174,7 @@ func TestBreaking_ReqPropertyBecameEnum(t *testing.T) { s2, err := open("../data/enums/request-property-enum.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -190,7 +190,7 @@ func TestBreaking_ReqParameterBecameEnum(t *testing.T) { s2, err := open("../data/enums/request-parameter-op-enum.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -206,7 +206,7 @@ func TestBreaking_ReqParameterHeaderPropertyBecameEnum(t *testing.T) { s2, err := open("../data/enums/request-parameter-property-enum.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -222,7 +222,7 @@ func TestBreaking_RespBodyNullable(t *testing.T) { s2, err := open("../data/nullable/revision-body.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -238,7 +238,7 @@ func TestBreaking_ReqBodyPropertyNotNullable(t *testing.T) { s2, err := open("../data/nullable/revision-req.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -254,7 +254,7 @@ func TestBreaking_RespBodyPropertyNullable(t *testing.T) { s2, err := open("../data/nullable/revision-property.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -270,7 +270,7 @@ func TestBreaking_RespBodyEmbeddedPropertyNullable(t *testing.T) { s2, err := open("../data/nullable/revision-embedded-property.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -286,7 +286,7 @@ func TestBreaking_RespBodyDeleteAndDisableRequiredProperty(t *testing.T) { s2, err := open(getReqPropFile("response-del-required-prop-revision.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -300,7 +300,7 @@ func TestBreaking_ReqBodyNewRequiredPropertyNew(t *testing.T) { s2, err := open(getReqPropFile("request-new-required-prop-revision.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -314,7 +314,7 @@ func TestBreaking_RespBodyRequiredPropertyEnabled(t *testing.T) { s2, err := open(getReqPropFile("response-base.json")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -328,7 +328,7 @@ func TestBreaking_ReqBodyRequiredPropertyDisabled(t *testing.T) { s2, err := open(getReqPropFile("request-revision.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -342,7 +342,7 @@ func TestBreaking_ReqBodyRequiredPropertyEnabled(t *testing.T) { s2, err := open(getReqPropFile("request-base.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -358,7 +358,7 @@ func TestBreaking_ReqBodyNewRequiredProperty(t *testing.T) { s2, err := open(getReqPropFile("request-new-revision.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -374,7 +374,7 @@ func TestBreaking_ReqBodyDeleteRequiredProperty(t *testing.T) { s2, err := open(getReqPropFile("request-new-base.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -391,7 +391,7 @@ func TestBreaking_ReqBodyDeleteRequiredProperty2(t *testing.T) { s2, err := open(getReqPropFile("request-property-items-2.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Contains(t, errs, checker.ApiChange{ @@ -412,7 +412,7 @@ func TestBreaking_RespBodyNewRequiredProperty(t *testing.T) { s2, err := open(getReqPropFile("response-new-revision.json")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -426,7 +426,7 @@ func TestBreaking_RespBodyDeleteRequiredProperty(t *testing.T) { s2, err := open(getReqPropFile("response-new-base.json")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -442,7 +442,7 @@ func TestBreaking_RespBodyNewAllOfRequiredProperty(t *testing.T) { s2, err := open(getReqPropFile("response-allof-revision.json")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -456,7 +456,7 @@ func TestBreaking_RespBodyDeleteAllOfRequiredProperty(t *testing.T) { s2, err := open(getReqPropFile("response-allof-base.json")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -472,7 +472,7 @@ func TestBreaking_ReadOnlyNewRequiredProperty(t *testing.T) { s2, err := open(getReqPropFile("read-only-new-revision.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -486,7 +486,7 @@ func TestBreaking_ReadOnlyPropertyRequiredEnabled(t *testing.T) { s2, err := open(getReqPropFile("read-only-revision.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -500,7 +500,7 @@ func TestBreaking_WriteOnlyDeleteRequiredProperty(t *testing.T) { s2, err := open(getReqPropFile("write-only-delete-revision.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -517,7 +517,7 @@ func TestBreaking_WriteOnlyDeleteNonRequiredProperty(t *testing.T) { s2, err := open(getReqPropFile("write-only-delete-partial-revision.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -538,7 +538,7 @@ func TestBreaking_WriteOnlyPropertyRequiredDisabled(t *testing.T) { s2, err := open(getReqPropFile("write-only-revision.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -552,7 +552,7 @@ func TestBreaking_RequiredPropertyWriteOnlyEnabled(t *testing.T) { s2, err := open(getReqPropFile("write-only-changed-revision.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -566,7 +566,7 @@ func TestBreaking_RequiredPropertyWriteOnlyDisabled(t *testing.T) { s2, err := open(getReqPropFile("write-only-changed-base.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -585,7 +585,7 @@ func TestBreaking_Body(t *testing.T) { s2, err := open(getReqPropFile("body2.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -601,7 +601,7 @@ func TestBreaking_Items(t *testing.T) { s2, err := open(getReqPropFile("items2.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -617,7 +617,7 @@ func TestBreaking_AnyOf(t *testing.T) { s2, err := open(getReqPropFile("anyOf2.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -633,7 +633,7 @@ func TestBreaking_NestedProp(t *testing.T) { s2, err := open(getReqPropFile("nested-property2.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -649,7 +649,7 @@ func TestBreaking_OneOf(t *testing.T) { s2, err := open("../data/x-of/revision.json") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 3) diff --git a/checker/checker_breaking_request_type_changed_test.go b/checker/checker_breaking_request_type_changed_test.go index 527f5ffe..ab391209 100644 --- a/checker/checker_breaking_request_type_changed_test.go +++ b/checker/checker_breaking_request_type_changed_test.go @@ -20,7 +20,7 @@ func TestBreaking_ReqTypeStringToNumber(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "number" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 1) @@ -40,7 +40,7 @@ func TestBreaking_ReqTypeNumberToString(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "string" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 1) @@ -60,7 +60,7 @@ func TestBreaking_ReqTypeNumberToInteger(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "integer" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 1) @@ -80,7 +80,7 @@ func TestBreaking_ReqTypeIntegerToNumber(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "number" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -99,7 +99,7 @@ func TestBreaking_ReqTypeNumberToInt32(t *testing.T) { s2.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "integer" s2.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Format = "int32" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 1) diff --git a/checker/checker_breaking_response_type_changed_test.go b/checker/checker_breaking_response_type_changed_test.go index 0eec5103..c0af0cee 100644 --- a/checker/checker_breaking_response_type_changed_test.go +++ b/checker/checker_breaking_response_type_changed_test.go @@ -20,7 +20,7 @@ func TestBreaking_RespTypeStringToNumber(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/test").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Type = "number" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 1) @@ -40,7 +40,7 @@ func TestBreaking_RespTypeNumberToString(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/test").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Type = "string" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 1) @@ -60,7 +60,7 @@ func TestBreaking_RespTypeNumberToInteger(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/test").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Type = "integer" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -78,7 +78,7 @@ func TestBreaking_RespTypeIntegerToNumber(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/test").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Type = "number" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 1) @@ -99,7 +99,7 @@ func TestBreaking_RespTypeNumberToInt32(t *testing.T) { s2.Spec.Paths.Value("/test").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Type = "integer" s2.Spec.Paths.Value("/test").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Format = "int32" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -113,7 +113,7 @@ func TestBreaking_RespTypeChanged(t *testing.T) { s2, err := open("../data/type-change/revision-response.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 1) diff --git a/checker/checker_breaking_test.go b/checker/checker_breaking_test.go index 00c4291f..cdab30b0 100644 --- a/checker/checker_breaking_test.go +++ b/checker/checker_breaking_test.go @@ -35,13 +35,9 @@ func d(t *testing.T, config *diff.Config, v1, v2 int) checker.Changes { return errs } -func getConfig() *diff.Config { - return diff.NewConfig().WithCheckBreaking() -} - // BC: deleting a path is breaking func TestBreaking_DeletedPath(t *testing.T) { - errs := d(t, getConfig(), 1, 701) + errs := d(t, diff.NewConfig(), 1, 701) require.Len(t, errs, 1) require.Equal(t, checker.APIPathRemovedWithoutDeprecationId, errs[0].GetId()) require.Equal(t, "api path removed without deprecation", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer())) @@ -54,7 +50,7 @@ func TestBreaking_DeletedOp(t *testing.T) { s1.Spec.Paths.Value(installCommandPath).Put = openapi3.NewOperation() - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -72,7 +68,7 @@ func TestBreaking_AddingRequiredRequestBody(t *testing.T) { Value: openapi3.NewRequestBody().WithRequired(true), } - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -94,7 +90,7 @@ func TestBreaking_RequestBodyRequiredEnabled(t *testing.T) { Value: openapi3.NewRequestBody().WithRequired(true), } - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -105,7 +101,7 @@ func TestBreaking_RequestBodyRequiredEnabled(t *testing.T) { // BC: deleting an enum value is breaking func TestBreaking_DeletedEnum(t *testing.T) { - errs := d(t, getConfig(), 702, 1) + errs := d(t, diff.NewConfig(), 702, 1) require.NotEmpty(t, errs) require.Len(t, errs, 1) require.Equal(t, checker.RequestParameterEnumValueRemovedId, errs[0].GetId()) @@ -114,7 +110,7 @@ func TestBreaking_DeletedEnum(t *testing.T) { // BC: added an enum value to response breaking func TestBreaking_AddedResponseEnum(t *testing.T) { - errs := d(t, getConfig(), 703, 704) + errs := d(t, diff.NewConfig(), 703, 704) require.NotEmpty(t, errs) require.Len(t, errs, 2) require.Equal(t, checker.ResponsePropertyEnumValueAddedId, errs[0].GetId()) @@ -148,7 +144,7 @@ func TestBreaking_PathParamRename(t *testing.T) { s2, err := loader.LoadFromFile("../data/param-rename/method-revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), &load.SpecInfo{Spec: s1}, &load.SpecInfo{Spec: s2}, ) @@ -166,7 +162,7 @@ func TestBreaking_NewPathParam(t *testing.T) { deleteParam(s1.Spec.Paths.Value(installCommandPath).Get, openapi3.ParameterInPath, "project") // note: path params are always required - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) @@ -183,7 +179,7 @@ func TestBreaking_NewRequiredHeaderParam(t *testing.T) { deleteParam(s1.Spec.Paths.Value(installCommandPath).Get, openapi3.ParameterInHeader, "network-policies") s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -200,7 +196,7 @@ func TestBreaking_HeaderParamRequiredEnabled(t *testing.T) { s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = false s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 1) @@ -224,7 +220,7 @@ func TestBreaking_ResponseHeaderParamRequiredDisabled(t *testing.T) { s1.Spec.Paths.Value(installCommandPath).Get.Responses.Value("default").Value.Headers["X-RateLimit-Limit"].Value.Required = true s2.Spec.Paths.Value(installCommandPath).Get.Responses.Value("default").Value.Headers["X-RateLimit-Limit"].Value.Required = false - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -241,7 +237,7 @@ func TestBreaking_ResponseHeaderRemoved(t *testing.T) { s1.Spec.Paths.Value(installCommandPath).Get.Responses.Value("default").Value.Headers["X-RateLimit-Limit"].Value.Required = true delete(s2.Spec.Paths.Value(installCommandPath).Get.Responses.Value("default").Value.Headers, "X-RateLimit-Limit") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) for _, err := range errs { @@ -260,7 +256,7 @@ func TestBreaking_ResponseSuccessStatusUpdated(t *testing.T) { delete(s2.Spec.Paths.Value(securityScorePath).Get.Responses.Map(), "200") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) for _, err := range errs { @@ -279,7 +275,7 @@ func TestBreaking_ResponseNonSuccessStatusUpdated(t *testing.T) { delete(s2.Spec.Paths.Value(securityScorePath).Get.Responses.Map(), "400") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetChecks(utils.StringList{checker.ResponseNonSuccessStatusRemovedId}), d, osm) for _, err := range errs { @@ -298,7 +294,7 @@ func TestBreaking_OperationIdRemoved(t *testing.T) { s2.Spec.Paths.Value(securityScorePath).Get.OperationID = "newOperationId" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetChecks(utils.StringList{checker.APIOperationIdRemovedId}), d, osm) @@ -322,7 +318,7 @@ func TestBreaking_RequestBodyEnumRemoved(t *testing.T) { s2.Spec.Paths.Value("/api/v2/changeOfRequestFieldValueTiedToEnumTest").Get.RequestBody.Value.Content["application/json"].Schema.Value.Enum = []interface{}{} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetChecks(utils.StringList{checker.RequestBodyEnumValueRemovedId}), d, osm) @@ -340,7 +336,7 @@ func TestBreaking_ResponsePropertyEnumRemoved(t *testing.T) { s1 := l(t, 704) s2 := l(t, 703) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetChecks(utils.StringList{checker.ResponsePropertyEnumValueRemovedId}), d, osm) @@ -360,7 +356,7 @@ func TestBreaking_TagRemoved(t *testing.T) { s2.Spec.Paths.Value(securityScorePath).Get.Tags[0] = "newTag" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetChecks(utils.StringList{checker.APITagRemovedId}), d, osm) for _, err := range errs { @@ -380,7 +376,7 @@ func TestBreaking_ResponseMediaTypeEnumRemoved(t *testing.T) { s2, err := open("../data/enums/response-enum-2.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetChecks(utils.StringList{checker.ResponseMediaTypeEnumValueRemovedId}), d, osm) for _, err := range errs { @@ -399,7 +395,7 @@ func TestBreaking_ResponseUnparseableStatusRemoved(t *testing.T) { delete(s2.Spec.Paths.Value(installCommandPath).Get.Responses.Map(), "default") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) for _, err := range errs { @@ -415,7 +411,7 @@ func TestBreaking_ResponseErrorStatusRemoved(t *testing.T) { delete(s2.Spec.Paths.Value(securityScorePath).Get.Responses.Map(), "400") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) for _, err := range errs { @@ -432,7 +428,7 @@ func TestBreaking_OptionalResponseHeaderRemoved(t *testing.T) { s1.Spec.Paths.Value(installCommandPath).Get.Responses.Value("default").Value.Headers["X-RateLimit-Limit"].Value.Required = false delete(s2.Spec.Paths.Value(installCommandPath).Get.Responses.Value("default").Value.Headers, "X-RateLimit-Limit") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) for _, err := range errs { @@ -452,7 +448,7 @@ func TestBreaking_ResponseDeleteMediaType(t *testing.T) { s2, err := open("../data/response-media-type-revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -469,7 +465,7 @@ func TestBreaking_DeletePatten(t *testing.T) { s2, err := open("../data/pattern-revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -483,7 +479,7 @@ func TestBreaking_AddPattern(t *testing.T) { s2, err := open("../data/pattern-base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -500,7 +496,7 @@ func TestBreaking_AddPatternRecursive(t *testing.T) { s2, err := open("../data/pattern-base-recursive.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -517,7 +513,7 @@ func TestBreaking_ModifyPattern(t *testing.T) { s2, err := open("../data/pattern-modified-not-anystring.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -534,7 +530,7 @@ func TestBreaking_ModifyParameterPattern(t *testing.T) { s2, err := open("../data/pattern-parameter-modified-not-anystring.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -551,7 +547,7 @@ func TestBreaking_ModifyPatternToAnyString(t *testing.T) { s2, err := open("../data/pattern-modified.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -567,7 +563,7 @@ func TestBreaking_ModifyRequiredOptionalParamDefaultValue(t *testing.T) { // By default, OpenAPI treats all request parameters as optional - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 1) @@ -585,7 +581,7 @@ func TestBreaking_SettingOptionalParamDefaultValue(t *testing.T) { // By default, OpenAPI treats all request parameters as optional - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 1) @@ -603,7 +599,7 @@ func TestBreaking_RemovingOptionalParamDefaultValue(t *testing.T) { // By default, OpenAPI treats all request parameters as optional - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Len(t, errs, 1) @@ -624,7 +620,7 @@ func TestBreaking_ModifyRequiredRequiredParamDefaultValue(t *testing.T) { paramRevision.Required = true paramRevision.Schema.Value.Default = "Y" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -641,7 +637,7 @@ func TestBreaking_SchemaRemoved(t *testing.T) { delete(s2.Spec.Components.Schemas, k) } - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) checks := checker.GetChecks(utils.StringList{checker.APISchemasRemovedId}) errs := checker.CheckBackwardCompatibility(checks, d, osm) @@ -663,7 +659,7 @@ func TestBreaking_RequestBodyMediaTypeRemoved(t *testing.T) { s2, err := open("../data/checker/request_body_media_type_updated_base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.NotEmpty(t, errs) @@ -678,7 +674,7 @@ func TestBreaking_RequestPropertyAnyOfRemoved(t *testing.T) { s2, err := open("../data/checker/request_property_any_of_removed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) @@ -700,7 +696,7 @@ func TestBreaking_RequestPropertyOneOfRemoved(t *testing.T) { s2, err := open("../data/checker/request_property_one_of_removed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) @@ -721,7 +717,7 @@ func TestBreaking_RequestPropertyAllOfAdded(t *testing.T) { s2, err := open("../data/checker/request_property_all_of_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) @@ -743,7 +739,7 @@ func TestBreaking_RequestPropertyAllOfRemoved(t *testing.T) { s2, err := open("../data/checker/request_property_all_of_removed_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) diff --git a/checker/checker_deprecation_test.go b/checker/checker_deprecation_test.go index 23fd34f4..fcf7de0f 100644 --- a/checker/checker_deprecation_test.go +++ b/checker/checker_deprecation_test.go @@ -39,7 +39,7 @@ func TestBreaking_RemoveBeforeSunset(t *testing.T) { s2, err := open(getDeprecationFile("sunset.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIRemovedCheck), d, osm) require.NotEmpty(t, errs) @@ -57,7 +57,7 @@ func TestBreaking_DeprecationNoSunset(t *testing.T) { s2, err := open(getDeprecationFile("sunset.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIRemovedCheck), d, osm) require.NoError(t, err) require.NotEmpty(t, errs) @@ -75,7 +75,7 @@ func TestBreaking_DeprecationPast(t *testing.T) { s2, err := open(getDeprecationFile("sunset.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIDeprecationCheck), d, osm) require.Empty(t, errs) @@ -90,7 +90,7 @@ func TestBreaking_DeprecationWithoutSunset(t *testing.T) { s2, err := open(getDeprecationFile("deprecated-no-sunset.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) c := singleCheckConfig(checker.APIDeprecationCheck) c.MinSunsetStableDays = 10 @@ -110,7 +110,7 @@ func TestBreaking_DeprecationForAlpha(t *testing.T) { s2, err := open(getDeprecationFile("deprecated-no-sunset-alpha-stability.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIDeprecationCheck), d, osm) require.Empty(t, errs) @@ -129,7 +129,7 @@ func TestBreaking_RemovedPathForAlpha(t *testing.T) { delete(s2.Spec.Paths.Map(), "/api/test") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIDeprecationCheck), d, osm) require.Empty(t, errs) @@ -145,7 +145,7 @@ func TestBreaking_RemovedPathForAlphaBreaking(t *testing.T) { delete(s2.Spec.Paths.Map(), "/api/test") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIRemovedCheck), d, osm) require.Len(t, errs, 2) @@ -166,7 +166,7 @@ func TestBreaking_DeprecationForDraft(t *testing.T) { require.NoError(t, err) s2.Spec.Paths.Value("/api/test").Get.Extensions["x-stability-level"] = draft - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIDeprecationCheck), d, osm) require.Empty(t, errs) @@ -185,7 +185,7 @@ func TestBreaking_RemovedPathForDraft(t *testing.T) { delete(s2.Spec.Paths.Map(), "/api/test") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIDeprecationCheck), d, osm) require.Empty(t, errs) @@ -203,7 +203,7 @@ func TestBreaking_RemovedPathForDraftBreaking(t *testing.T) { delete(s2.Spec.Paths.Map(), "/api/test") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIRemovedCheck), d, osm) require.Len(t, errs, 2) @@ -230,7 +230,7 @@ func TestBreaking_DeprecationWithEarlySunset(t *testing.T) { sunsetDate := civil.DateOf(time.Now()).AddDays(9).String() s2.Spec.Paths.Value("/api/test").Get.Extensions[diff.SunsetExtension] = toJson(t, sunsetDate) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) c := singleCheckConfig(checker.APIDeprecationCheck) c.MinSunsetStableDays = 10 @@ -252,7 +252,7 @@ func TestBreaking_DeprecationWithProperSunset(t *testing.T) { s2.Spec.Paths.Value("/api/test").Get.Extensions[diff.SunsetExtension] = toJson(t, civil.DateOf(time.Now()).AddDays(10).String()) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) c := singleCheckConfig(checker.APIDeprecationCheck) c.MinSunsetStableDays = 10 @@ -272,7 +272,7 @@ func TestBreaking_DeprecationPathPast(t *testing.T) { s2, err := open(getDeprecationFile("sunset-path.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIDeprecationCheck), d, osm) require.Empty(t, errs) @@ -287,7 +287,7 @@ func TestBreaking_DeprecationPathMixed(t *testing.T) { s2, err := open(getDeprecationFile("sunset-path.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIRemovedCheck), d, osm) require.NotEmpty(t, errs) @@ -305,7 +305,7 @@ func TestBreaking_SunsetDeletedForDeprecatedEndpoint(t *testing.T) { s2, err := open(getDeprecationFile("deprecated-no-sunset.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APISunsetChangedCheck), d, osm) require.NotEmpty(t, errs) @@ -323,7 +323,7 @@ func TestBreaking_DeprecationPathMixed_RFC3339_Sunset(t *testing.T) { s2, err := open(getDeprecationFile("sunset-path.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIRemovedCheck), d, osm) require.NotEmpty(t, errs) @@ -340,7 +340,7 @@ func TestApiDeprecated_DetectsDeprecatedOperations(t *testing.T) { s2, err := open("../data/deprecation/deprecated-future.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIDeprecationCheck), d, osm, checker.INFO) @@ -363,7 +363,7 @@ func TestApiDeprecated_DetectsReactivatedOperations(t *testing.T) { s2, err := open("../data/deprecation/base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.APIDeprecationCheck), d, osm, checker.INFO) @@ -386,7 +386,7 @@ func TestBreaking_InvaidStability(t *testing.T) { s2, err := open(getDeprecationFile("base-alpha-stability.yaml")) require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIDeprecationCheck), d, osm) require.Len(t, errs, 1) diff --git a/checker/checker_not_breaking_test.go b/checker/checker_not_breaking_test.go index b63d9734..6861ce0d 100644 --- a/checker/checker_not_breaking_test.go +++ b/checker/checker_not_breaking_test.go @@ -29,7 +29,7 @@ func TestBreaking_Same(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -44,7 +44,7 @@ func TestBreaking_AddingOptionalRequestBody(t *testing.T) { Value: openapi3.NewRequestBody().WithRequired(false), } - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -63,14 +63,14 @@ func TestBreaking_RequestBodyRequiredDisabled(t *testing.T) { Value: openapi3.NewRequestBody().WithRequired(false), } - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) verifyNonBreakingChangeIsChangelogEntry(t, d, osm, checker.RequestBodyBecameOptionalId) } // BC: deleting a tag is not breaking func TestBreaking_DeletedTag(t *testing.T) { - r := d(t, getConfig(), 1, 5) + r := d(t, diff.NewConfig(), 1, 5) require.Len(t, r, 6) require.Equal(t, checker.ResponseBodyTypeChangedId, r[0].GetId()) require.Equal(t, checker.ResponseSuccessStatusRemovedId, r[1].GetId()) @@ -82,7 +82,7 @@ func TestBreaking_DeletedTag(t *testing.T) { // BC: adding an enum value is not breaking func TestBreaking_AddedEnum(t *testing.T) { - r := d(t, getConfig(), 1, 3) + r := d(t, diff.NewConfig(), 1, 3) require.Len(t, r, 6) require.Equal(t, checker.ResponseSuccessStatusRemovedId, r[0].GetId()) require.Equal(t, checker.ResponseSuccessStatusRemovedId, r[1].GetId()) @@ -94,7 +94,7 @@ func TestBreaking_AddedEnum(t *testing.T) { // BC: changing extensions is not breaking func TestBreaking_ModifiedExtension(t *testing.T) { - r := d(t, getConfig(), 1, 3) + r := d(t, diff.NewConfig(), 1, 3) require.Len(t, r, 6) require.Equal(t, checker.ResponseSuccessStatusRemovedId, r[0].GetId()) require.Equal(t, checker.ResponseSuccessStatusRemovedId, r[1].GetId()) @@ -106,7 +106,7 @@ func TestBreaking_ModifiedExtension(t *testing.T) { // BC: changing comments is not breaking func TestBreaking_Comments(t *testing.T) { - r := d(t, getConfig(), 1, 3) + r := d(t, diff.NewConfig(), 1, 3) require.Len(t, r, 6) require.Equal(t, checker.ResponseSuccessStatusRemovedId, r[0].GetId()) require.Equal(t, checker.ResponseSuccessStatusRemovedId, r[1].GetId()) @@ -124,7 +124,7 @@ func TestBreaking_NewOptionalHeaderParam(t *testing.T) { deleteParam(s1.Spec.Paths.Value(installCommandPath).Get, openapi3.ParameterInHeader, "network-policies") s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = false - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -138,7 +138,7 @@ func TestBreaking_HeaderParamRequiredDisabled(t *testing.T) { s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = true s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = false - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) changes := checker.CheckBackwardCompatibilityUntilLevel(checker.GetDefaultChecks(), d, osm, checker.INFO) require.NotEmpty(t, changes) @@ -158,7 +158,7 @@ func TestBreaking_NewRequiredResponseHeader(t *testing.T) { deleteResponseHeader(s1.Spec.Paths.Value(installCommandPath).Get.Responses.Value("default").Value, "X-RateLimit-Limit") s2.Spec.Paths.Value(installCommandPath).Get.Responses.Value("default").Value.Headers["X-RateLimit-Limit"].Value.Required = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -166,7 +166,7 @@ func TestBreaking_NewRequiredResponseHeader(t *testing.T) { // BC: changing operation ID is not breaking func TestBreaking_OperationID(t *testing.T) { - r := d(t, getConfig(), 3, 1) + r := d(t, diff.NewConfig(), 3, 1) require.Len(t, r, 3) require.Equal(t, checker.RequestParameterMaxLengthDecreasedId, r[0].GetId()) require.Equal(t, checker.RequestParameterEnumValueRemovedId, r[1].GetId()) @@ -175,7 +175,7 @@ func TestBreaking_OperationID(t *testing.T) { // BC: changing a link to operation ID is not breaking func TestBreaking_LinkOperationID(t *testing.T) { - r := d(t, getConfig(), 3, 1) + r := d(t, diff.NewConfig(), 3, 1) require.Len(t, r, 3) require.Equal(t, checker.RequestParameterMaxLengthDecreasedId, r[0].GetId()) require.Equal(t, checker.RequestParameterEnumValueRemovedId, r[1].GetId()) @@ -190,7 +190,7 @@ func TestBreaking_ResponseAddMediaType(t *testing.T) { s2, err := open("../data/response-media-type-base.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -204,7 +204,7 @@ func TestBreaking_DeprecatedOperation(t *testing.T) { s2.Spec.Paths.Value(installCommandPath).Get.Deprecated = true s2.Spec.Paths.Value(installCommandPath).Get.Extensions = map[string]interface{}{diff.SunsetExtension: toJson(t, civil.DateOf(time.Now()).AddDays(180).String())} - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(checker.GetDefaultChecks(), d, osm, checker.INFO) require.Len(t, errs, 1) @@ -218,7 +218,7 @@ func TestBreaking_DeprecatedParameter(t *testing.T) { s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Deprecated = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -231,7 +231,7 @@ func TestBreaking_DeprecatedHeader(t *testing.T) { s2.Spec.Paths.Value(installCommandPath).Get.Responses.Value("default").Value.Headers["X-RateLimit-Limit"].Value.Deprecated = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -244,7 +244,7 @@ func TestBreaking_DeprecatedSchema(t *testing.T) { s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Deprecated = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -258,7 +258,7 @@ func TestBreaking_Servers(t *testing.T) { s2, err := open("../data/servers/revisionswagger.json") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Empty(t, errs) @@ -270,7 +270,7 @@ func TestBreaking_TagAdded(t *testing.T) { s2 := l(t, 1) s2.Spec.Paths.Value(securityScorePath).Get.Tags = append(s2.Spec.Paths.Value(securityScorePath).Get.Tags, "newTag") - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) verifyNonBreakingChangeIsChangelogEntry(t, d, osm, checker.APITagAddedId) } @@ -282,7 +282,7 @@ func TestBreaking_OperationIdAdded(t *testing.T) { s1.Spec.Paths.Value(securityScorePath).Get.OperationID = "" - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) verifyNonBreakingChangeIsChangelogEntry(t, d, osm, checker.APIOperationIdAddId) } @@ -295,7 +295,7 @@ func TestBreaking_RequiredResponsePropertyAdded(t *testing.T) { s2, err := open("../data/checker/response_required_property_added_revision.yaml") require.NoError(t, err) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) verifyNonBreakingChangeIsChangelogEntry(t, d, osm, "response-required-property-added") } diff --git a/checker/checker_request_parameter_required_value_updated_test.go b/checker/checker_request_parameter_required_value_updated_test.go index aeed9927..824cca02 100644 --- a/checker/checker_request_parameter_required_value_updated_test.go +++ b/checker/checker_request_parameter_required_value_updated_test.go @@ -18,7 +18,7 @@ func TestBreaking_HeaderParamBecameRequired(t *testing.T) { s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = false s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = true - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.RequestParameterRequiredValueUpdatedCheck), d, osm) require.Len(t, errs, 1) @@ -40,7 +40,7 @@ func TestBreaking_HeaderParamBecameOptional(t *testing.T) { s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = true s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = false - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterRequiredValueUpdatedCheck), d, osm, checker.INFO) require.Len(t, errs, 1) diff --git a/checker/composed_test.go b/checker/composed_test.go index dfedcd65..dba00218 100644 --- a/checker/composed_test.go +++ b/checker/composed_test.go @@ -29,8 +29,7 @@ func TestComposed_Empty(t *testing.T) { loadFrom(t, "../data/composed/base/", 1), } - config := diff.NewConfig() - diffReport, _, err := diff.GetPathsDiff(config, s1, s2) + diffReport, _, err := diff.GetPathsDiff(diff.NewConfig().WithExcludeExtensions(), s1, s2) require.NoError(t, err) require.Nil(t, diffReport) } @@ -70,8 +69,7 @@ func TestComposed_CompareMostRecent(t *testing.T) { loadFrom(t, "../data/composed/revision/", 2), } - config := diff.NewConfig() - diffReport, _, err := diff.GetPathsDiff(config, s1, s2) + diffReport, _, err := diff.GetPathsDiff(diff.NewConfig().WithExcludeExtensions(), s1, s2) require.NoError(t, err) require.Nil(t, diffReport) } diff --git a/checker/ignore_test.go b/checker/ignore_test.go index 4f01850a..bfe20bdd 100644 --- a/checker/ignore_test.go +++ b/checker/ignore_test.go @@ -13,7 +13,7 @@ func TestIgnore(t *testing.T) { s1 := l(t, 1) s2 := l(t, 3) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Equal(t, 6, len(errs)) @@ -27,7 +27,7 @@ func TestIgnoreSubpath(t *testing.T) { s1 := l(t, 6) s2 := l(t, 7) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Equal(t, 3, len(errs)) @@ -41,7 +41,7 @@ func TestIgnoreOnlyIncludedSubpaths(t *testing.T) { s1 := l(t, 8) s2 := l(t, 7) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetDefaultChecks(), d, osm) require.Equal(t, 2, len(errs)) // detect new and newest were deleted @@ -58,7 +58,7 @@ func TestIgnoreComponent(t *testing.T) { s1 := l(t, 1) s2 := l(t, 3) - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(checker.GetChecks(utils.StringList{checker.APISchemasRemovedId}), d, osm) require.Equal(t, 8, len(errs)) diff --git a/data/extensions/base.yaml b/data/extensions/base.yaml new file mode 100644 index 00000000..f88797b2 --- /dev/null +++ b/data/extensions/base.yaml @@ -0,0 +1,31 @@ +info: + title: Tufin + version: 1.0.0 +openapi: 3.0.3 +paths: + /example/callback: + post: + responses: + '200': + description: 200 response + content: + application/json: + schema: + $ref: '#/components/schemas/Empty' + x-amazon-apigateway-integration: + type: http_proxy + connectionId: ${vpc_link_id} + httpMethod: POST + uri: http://api.example.com/v1/example/callback + responses: + default: + statusCode: '201' + passthroughBehavior: when_no_match + connectionType: VPC_LINK +components: + schemas: + Empty: + type: object + title: Empty Schema + properties: {} + required: [] diff --git a/data/extensions/revision.yaml b/data/extensions/revision.yaml new file mode 100644 index 00000000..0f0d57c9 --- /dev/null +++ b/data/extensions/revision.yaml @@ -0,0 +1,31 @@ +info: + title: Tufin + version: 1.0.0 +openapi: 3.0.3 +paths: + /example/callback: + post: + responses: + '200': + description: 200 response + content: + application/json: + schema: + $ref: '#/components/schemas/Empty' + x-amazon-apigateway-integration: + type: http_proxy + connectionId: ${vpc_link_id} + httpMethod: POST + uri: http://api.example.com/v1/example/calllllllllback + responses: + default: + statusCode: '200' + passthroughBehavior: when_no_match + connectionType: VPC_LINK +components: + schemas: + Empty: + type: object + title: Empty Schema + properties: {} + required: [] \ No newline at end of file diff --git a/diff/config.go b/diff/config.go index e3052c8e..8bb6be70 100644 --- a/diff/config.go +++ b/diff/config.go @@ -6,7 +6,6 @@ import ( // Config includes various settings to control the diff type Config struct { - IncludeExtensions utils.StringSet PathFilter string FilterExtension string PathPrefixBase string @@ -23,6 +22,7 @@ const ( ExcludeEndpointsOption = "endpoints" ExcludeTitleOption = "title" ExcludeSummaryOption = "summary" + ExcludeExtensionsOption = "extensions" ) var ExcludeDiffOptions = []string{ @@ -31,13 +31,13 @@ var ExcludeDiffOptions = []string{ ExcludeEndpointsOption, ExcludeTitleOption, ExcludeSummaryOption, + ExcludeExtensionsOption, } // NewConfig returns a default configuration func NewConfig() *Config { return &Config{ - IncludeExtensions: utils.StringSet{}, - ExcludeElements: utils.StringSet{}, + ExcludeElements: utils.StringSet{}, } } @@ -46,6 +46,11 @@ func (config *Config) WithExcludeElements(excludeElements []string) *Config { return config } +func (config *Config) WithExcludeExtensions() *Config { + config.ExcludeElements.Add(ExcludeExtensionsOption) + return config +} + func (config *Config) IsExcludeExamples() bool { return config.ExcludeElements.Contains(ExcludeExamplesOption) } @@ -66,16 +71,12 @@ func (config *Config) IsExcludeSummary() bool { return config.ExcludeElements.Contains(ExcludeSummaryOption) } +func (config *Config) IsExcludeExtensions() bool { + return config.ExcludeElements.Contains(ExcludeExtensionsOption) +} + const ( SunsetExtension = "x-sunset" XStabilityLevelExtension = "x-stability-level" XExtensibleEnumExtension = "x-extensible-enum" ) - -func (config *Config) WithCheckBreaking() *Config { - config.IncludeExtensions.Add(XStabilityLevelExtension) - config.IncludeExtensions.Add(SunsetExtension) - config.IncludeExtensions.Add(XExtensibleEnumExtension) - - return config -} diff --git a/diff/contact.go b/diff/contact.go index 7a31d6ff..e202673a 100644 --- a/diff/contact.go +++ b/diff/contact.go @@ -19,38 +19,45 @@ func (diff *ContactDiff) Empty() bool { return diff == nil || *diff == ContactDiff{} } -func getContactDiff(config *Config, state *state, contact1, contact2 *openapi3.Contact) *ContactDiff { - diff := getContactDiffInternal(config, state, contact1, contact2) +func getContactDiff(config *Config, state *state, contact1, contact2 *openapi3.Contact) (*ContactDiff, error) { + diff, err := getContactDiffInternal(config, state, contact1, contact2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getContactDiffInternal(config *Config, state *state, contact1, contact2 *openapi3.Contact) *ContactDiff { +func getContactDiffInternal(config *Config, state *state, contact1, contact2 *openapi3.Contact) (*ContactDiff, error) { result := ContactDiff{} + var err error if contact1 == nil && contact2 == nil { - return &result + return &result, nil } if contact1 == nil && contact2 != nil { result.Added = true - return &result + return &result, nil } if contact1 != nil && contact2 == nil { result.Deleted = true - return &result + return &result, nil } - result.ExtensionsDiff = getExtensionsDiff(config, state, contact1.Extensions, contact2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, contact1.Extensions, contact2.Extensions) + if err != nil { + return nil, err + } result.NameDiff = getValueDiff(contact1.Name, contact2.Name) result.URLDiff = getValueDiff(contact1.URL, contact2.URL) result.EmailDiff = getValueDiff(contact1.Email, contact2.Email) - return &result + return &result, nil } diff --git a/diff/diff.go b/diff/diff.go index 5c1fdb71..899bf15d 100644 --- a/diff/diff.go +++ b/diff/diff.go @@ -265,9 +265,15 @@ func getDiffInternal(config *Config, state *state, s1, s2 *openapi3.T) (*Diff, e result := newDiff() var err error - result.ExtensionsDiff = getExtensionsDiff(config, state, s1.Extensions, s2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, s1.Extensions, s2.Extensions) + if err != nil { + return nil, err + } result.OpenAPIDiff = getValueDiff(s1.OpenAPI, s2.OpenAPI) - result.InfoDiff = getInfoDiff(config, state, s1.Info, s2.Info) + result.InfoDiff, err = getInfoDiff(config, state, s1.Info, s2.Info) + if err != nil { + return nil, err + } if result.PathsDiff, err = getPathsDiff(config, state, s1.Paths, s2.Paths); err != nil { return nil, err @@ -280,7 +286,10 @@ func getDiffInternal(config *Config, state *state, s1, s2 *openapi3.T) (*Diff, e result.SecurityDiff = getSecurityRequirementsDiff(config, state, &s1.Security, &s2.Security) result.ServersDiff = getServersDiff(config, state, &s1.Servers, &s2.Servers) result.TagsDiff = getTagsDiff(config, state, s1.Tags, s2.Tags) - result.ExternalDocsDiff = getExternalDocsDiff(config, state, s1.ExternalDocs, s2.ExternalDocs) + result.ExternalDocsDiff, err = getExternalDocsDiff(config, state, s1.ExternalDocs, s2.ExternalDocs) + if err != nil { + return nil, err + } if result.ComponentsDiff, err = getComponentsDiff(config, state, s1.Components, s2.Components); err != nil { return nil, err diff --git a/diff/diff_common_params_test.go b/diff/diff_common_params_test.go index 3b304144..822ad4a0 100644 --- a/diff/diff_common_params_test.go +++ b/diff/diff_common_params_test.go @@ -32,7 +32,7 @@ func TestDiff_CommonParamsMoved(t *testing.T) { s2, err := load.NewSpecInfo(loader, load.NewSource("../data/common-params/params_in_op.yaml"), load.WithFlattenParams()) require.NoError(t, err) - d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) + d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig().WithExcludeExtensions(), s1, s2) require.NoError(t, err) require.Empty(t, d) } diff --git a/diff/diff_test.go b/diff/diff_test.go index 32be3376..1b89f68b 100644 --- a/diff/diff_test.go +++ b/diff/diff_test.go @@ -32,7 +32,7 @@ func d(t *testing.T, config *diff.Config, v1, v2 int) *diff.Diff { } func TestDiff_Same(t *testing.T) { - require.Nil(t, d(t, diff.NewConfig(), 1, 1)) + require.Nil(t, d(t, diff.NewConfig().WithExcludeExtensions(), 1, 1)) } func TestDiff_Empty(t *testing.T) { @@ -94,37 +94,19 @@ func TestDiff_ModifiedOperation(t *testing.T) { } func TestAddedExtension(t *testing.T) { - config := diff.Config{ - IncludeExtensions: utils.StringSet{"x-extension-test": struct{}{}}, - } - - require.Contains(t, - d(t, &config, 3, 1).ExtensionsDiff.Added, - "x-extension-test") + require.Contains(t, d(t, diff.NewConfig(), 3, 1).ExtensionsDiff.Added, "x-extension-test") } func TestDeletedExtension(t *testing.T) { - config := diff.Config{ - IncludeExtensions: utils.StringSet{"x-extension-test": struct{}{}}, - } - - require.Contains(t, - d(t, &config, 1, 3).ExtensionsDiff.Deleted, - "x-extension-test") + require.Contains(t, d(t, diff.NewConfig(), 1, 3).ExtensionsDiff.Deleted, "x-extension-test") } func TestModifiedExtension(t *testing.T) { - config := diff.Config{ - IncludeExtensions: utils.StringSet{"x-extension-test2": struct{}{}}, - } - - require.NotNil(t, - d(t, &config, 1, 3).ExtensionsDiff.Modified["x-extension-test2"]) + require.NotNil(t, d(t, diff.NewConfig(), 1, 3).ExtensionsDiff.Modified["x-extension-test2"]) } func TestExcludedExtension(t *testing.T) { - require.Nil(t, - d(t, diff.NewConfig(), 1, 3).ExtensionsDiff) + require.Nil(t, d(t, diff.NewConfig().WithExcludeExtensions(), 1, 3).ExtensionsDiff) } func TestDiff_AddedGlobalTag(t *testing.T) { @@ -311,16 +293,13 @@ func TestResponseDeleted(t *testing.T) { } func TestResponseDescriptionModified(t *testing.T) { - config := diff.Config{ - IncludeExtensions: utils.StringSet{"x-extension-test": struct{}{}}, - } require.Equal(t, &diff.ValueDiff{ From: "Tufin", To: "Tufin1", }, - d(t, &config, 3, 1).PathsDiff.Modified[installCommandPath].OperationsDiff.Modified["GET"].ResponsesDiff.Modified["default"].DescriptionDiff) + d(t, diff.NewConfig(), 3, 1).PathsDiff.Modified[installCommandPath].OperationsDiff.Modified["GET"].ResponsesDiff.Modified["default"].DescriptionDiff) } func TestResponseHeadersModified(t *testing.T) { @@ -345,12 +324,9 @@ func TestServerDeleted(t *testing.T) { } func TestServerModified(t *testing.T) { - config := diff.Config{ - IncludeExtensions: utils.StringSet{"x-extension-test": struct{}{}}, - } require.Contains(t, - d(t, &config, 5, 3).PathsDiff.Modified[installCommandPath].OperationsDiff.Modified["GET"].ServersDiff.Modified, + d(t, diff.NewConfig(), 5, 3).PathsDiff.Modified[installCommandPath].OperationsDiff.Modified["GET"].ServersDiff.Modified, "https://www.oasdiff.com") } @@ -730,19 +706,13 @@ func TestDiff_InfoDeleted(t *testing.T) { func TestDiff_PathParamInMethodRenamed(t *testing.T) { loader := openapi3.NewLoader() - s1, err := loader.LoadFromFile("../data/param-rename/method-base.yaml") + s1, err := load.NewSpecInfo(loader, load.NewSource("../data/param-rename/method-base.yaml")) require.NoError(t, err) - s2, err := loader.LoadFromFile("../data/param-rename/method-revision.yaml") + s2, err := load.NewSpecInfo(loader, load.NewSource("../data/param-rename/method-revision.yaml")) require.NoError(t, err) - d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), - &load.SpecInfo{ - Spec: s1, - }, - &load.SpecInfo{ - Spec: s2, - }) + d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) dd := d.PathsDiff.Modified["/books/{bookId}"].ParametersDiff.Modified["path"]["bookId"].NameDiff @@ -753,19 +723,13 @@ func TestDiff_PathParamInMethodRenamed(t *testing.T) { func TestDiff_PathParamInOperationRenamed(t *testing.T) { loader := openapi3.NewLoader() - s1, err := loader.LoadFromFile("../data/param-rename/op-base.yaml") + s1, err := load.NewSpecInfo(loader, load.NewSource("../data/param-rename/op-base.yaml")) require.NoError(t, err) - s2, err := loader.LoadFromFile("../data/param-rename/op-revision.yaml") + s2, err := load.NewSpecInfo(loader, load.NewSource("../data/param-rename/op-revision.yaml")) require.NoError(t, err) - d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), - &load.SpecInfo{ - Spec: s1, - }, - &load.SpecInfo{ - Spec: s2, - }) + d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) dd := d.PathsDiff.Modified["/books/{bookId}"].OperationsDiff.Modified["GET"].ParametersDiff.Modified["path"]["bookId"].NameDiff @@ -776,19 +740,13 @@ func TestDiff_PathParamInOperationRenamed(t *testing.T) { func TestDiff_PathParamRefInOperationRenamed(t *testing.T) { loader := openapi3.NewLoader() - s1, err := loader.LoadFromFile("../data/param-rename/op-base.yaml") + s1, err := load.NewSpecInfo(loader, load.NewSource("../data/param-rename/op-base.yaml")) require.NoError(t, err) - s2, err := loader.LoadFromFile("../data/param-rename/op-revision-ref.yaml") + s2, err := load.NewSpecInfo(loader, load.NewSource("../data/param-rename/op-revision-ref.yaml")) require.NoError(t, err) - d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), - &load.SpecInfo{ - Spec: s1, - }, - &load.SpecInfo{ - Spec: s2, - }) + d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) dd := d.PathsDiff.Modified["/books/{bookId}"].OperationsDiff.Modified["GET"].ParametersDiff.Modified["path"]["bookId"].NameDiff @@ -799,19 +757,13 @@ func TestDiff_PathParamRefInOperationRenamed(t *testing.T) { func TestDiff_TwoPathParamsRenamed(t *testing.T) { loader := openapi3.NewLoader() - s1, err := loader.LoadFromFile("../data/param-rename/two-base.yaml") + s1, err := load.NewSpecInfo(loader, load.NewSource("../data/param-rename/two-base.yaml")) require.NoError(t, err) - s2, err := loader.LoadFromFile("../data/param-rename/two-revision.yaml") + s2, err := load.NewSpecInfo(loader, load.NewSource("../data/param-rename/two-revision.yaml")) require.NoError(t, err) - d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), - &load.SpecInfo{ - Spec: s1, - }, - &load.SpecInfo{ - Spec: s2, - }) + d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) dd := d.PathsDiff.Modified["/books/{bookId}/{libraryId}"].OperationsDiff.Modified["GET"].ParametersDiff.Modified["path"]["bookId"].NameDiff @@ -826,19 +778,13 @@ func TestDiff_TwoPathParamsRenamed(t *testing.T) { func TestDiff_TwoPathParamsOneRenamed(t *testing.T) { loader := openapi3.NewLoader() - s1, err := loader.LoadFromFile("../data/param-rename/one-of-two-base.yaml") + s1, err := load.NewSpecInfo(loader, load.NewSource("../data/param-rename/one-of-two-base.yaml")) require.NoError(t, err) - s2, err := loader.LoadFromFile("../data/param-rename/one-of-two-revision.yaml") + s2, err := load.NewSpecInfo(loader, load.NewSource("../data/param-rename/one-of-two-revision.yaml")) require.NoError(t, err) - d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), - &load.SpecInfo{ - Spec: s1, - }, - &load.SpecInfo{ - Spec: s2, - }) + d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) dd := d.PathsDiff.Modified["/books/{bookId}/{libraryId}"].OperationsDiff.Modified["GET"].ParametersDiff.Modified["path"]["libraryId"].NameDiff @@ -849,16 +795,10 @@ func TestDiff_TwoPathParamsOneRenamed(t *testing.T) { func TestDiff_DifferentComponentSameParam(t *testing.T) { loader := openapi3.NewLoader() - s1, err := loader.LoadFromFile("../data/different_component_same_parameter.yaml") + s1, err := load.NewSpecInfo(loader, load.NewSource("../data/different_component_same_parameter.yaml")) require.NoError(t, err) - d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), - &load.SpecInfo{ - Spec: s1, - }, - &load.SpecInfo{ - Spec: s1, - }) + d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s1) require.NoError(t, err) require.Empty(t, d) } @@ -866,19 +806,13 @@ func TestDiff_DifferentComponentSameParam(t *testing.T) { func TestDiff_DifferentComponentModifiedParam(t *testing.T) { loader := openapi3.NewLoader() - s1, err := loader.LoadFromFile("../data/different_component_same_parameter.yaml") + s1, err := load.NewSpecInfo(loader, load.NewSource("../data/different_component_same_parameter.yaml")) require.NoError(t, err) - s2, err := loader.LoadFromFile("../data/different_component_modified_parameter.yaml") + s2, err := load.NewSpecInfo(loader, load.NewSource("../data/different_component_modified_parameter.yaml")) require.NoError(t, err) - d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), - &load.SpecInfo{ - Spec: s1, - }, - &load.SpecInfo{ - Spec: s2, - }) + d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) dd := d.ComponentsDiff.ParametersDiff.Modified["differentComponentName_A"].InDiff require.Equal(t, "header", dd.From) @@ -889,7 +823,7 @@ func TestDiff_DifferentComponentSameSchema(t *testing.T) { s1, err := load.NewSpecInfo(openapi3.NewLoader(), load.NewSource("../data/different_component_same_schema.yaml")) require.NoError(t, err) - d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s1) + d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig().WithExcludeExtensions(), s1, s1) require.NoError(t, err) require.Empty(t, d) } @@ -902,3 +836,82 @@ func TestDiff_DifferentComponentSameHeader(t *testing.T) { require.NoError(t, err) require.Empty(t, d) } + +func TestDiff_Extensions(t *testing.T) { + loader := openapi3.NewLoader() + + s1, err := load.NewSpecInfo(loader, load.NewSource("../data/extensions/base.yaml")) + require.NoError(t, err) + + s2, err := load.NewSpecInfo(loader, load.NewSource("../data/extensions/revision.yaml")) + require.NoError(t, err) + + d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) + require.NoError(t, err) + dd := d.PathsDiff.Modified["/example/callback"].OperationsDiff.Modified["POST"].ExtensionsDiff.Modified["x-amazon-apigateway-integration"] + require.Len(t, dd, 2) + require.Equal(t, "200", dd[0].Value) + require.Equal(t, "201", dd[0].OldValue) + require.Equal(t, "http://api.example.com/v1/example/calllllllllback", dd[1].Value) + require.Equal(t, "http://api.example.com/v1/example/callback", dd[1].OldValue) +} + +func TestDiff_ExtensionsExcluded(t *testing.T) { + loader := openapi3.NewLoader() + + s1, err := load.NewSpecInfo(loader, load.NewSource("../data/extensions/base.yaml")) + require.NoError(t, err) + + s2, err := load.NewSpecInfo(loader, load.NewSource("../data/extensions/revision.yaml")) + require.NoError(t, err) + + d, _, err := diff.GetWithOperationsSourcesMap(diff.NewConfig().WithExcludeExtensions(), s1, s2) + require.NoError(t, err) + require.Empty(t, d) +} + +func TestDiff_ExtensionsInvalid(t *testing.T) { + s1, err := load.NewSpecInfo(openapi3.NewLoader(), load.NewSource("../data/extensions/base.yaml")) + require.NoError(t, err) + + // Add invalid extension + newPathItem := s1.Spec.Paths.Find("/example/callback") + newPathItem.Post.Extensions["x-amazon-apigateway-integration"] = interface{}(make(chan int)) + s1.Spec.Paths.Set("/example/callback", newPathItem) + + _, _, err = diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s1) + require.EqualError(t, err, "json: unsupported type: chan int") +} + +func TestDiff_ExtensionsInvalidSecuritySchemes(t *testing.T) { + s1, err := load.NewSpecInfo(openapi3.NewLoader(), load.NewSource("../data/security-requirements/spec_1.yaml")) + require.NoError(t, err) + + // Add invalid extension + s1.Spec.Components.SecuritySchemes["petstore_auth"].Value.Extensions = map[string]interface{}{"invalid": interface{}(make(chan int))} + + _, _, err = diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s1) + require.EqualError(t, err, "json: unsupported type: chan int") +} + +func TestDiff_ExtensionsInvalidFlows(t *testing.T) { + s1, err := load.NewSpecInfo(openapi3.NewLoader(), load.NewSource("../data/security-requirements/spec_1.yaml")) + require.NoError(t, err) + + // Add invalid extension + s1.Spec.Components.SecuritySchemes["petstore_auth"].Value.Flows.Extensions = map[string]interface{}{"invalid": interface{}(make(chan int))} + + _, _, err = diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s1) + require.EqualError(t, err, "json: unsupported type: chan int") +} + +func TestDiff_ExtensionsInvalidImplicit(t *testing.T) { + s1, err := load.NewSpecInfo(openapi3.NewLoader(), load.NewSource("../data/security-requirements/spec_1.yaml")) + require.NoError(t, err) + + // Add invalid extension + s1.Spec.Components.SecuritySchemes["petstore_auth"].Value.Flows.Implicit.Extensions = map[string]interface{}{"invalid": interface{}(make(chan int))} + + _, _, err = diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s1) + require.EqualError(t, err, "json: unsupported type: chan int") +} diff --git a/diff/discriminator_diff.go b/diff/discriminator_diff.go index 946acd6f..c0d24b29 100644 --- a/diff/discriminator_diff.go +++ b/diff/discriminator_diff.go @@ -23,37 +23,44 @@ func newDiscriminatorDiff() *DiscriminatorDiff { } -func getDiscriminatorDiff(config *Config, state *state, discriminator1, discriminator2 *openapi3.Discriminator) *DiscriminatorDiff { - diff := getDiscriminatorDiffInternal(config, state, discriminator1, discriminator2) +func getDiscriminatorDiff(config *Config, state *state, discriminator1, discriminator2 *openapi3.Discriminator) (*DiscriminatorDiff, error) { + diff, err := getDiscriminatorDiffInternal(config, state, discriminator1, discriminator2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getDiscriminatorDiffInternal(config *Config, state *state, discriminator1, discriminator2 *openapi3.Discriminator) *DiscriminatorDiff { +func getDiscriminatorDiffInternal(config *Config, state *state, discriminator1, discriminator2 *openapi3.Discriminator) (*DiscriminatorDiff, error) { result := newDiscriminatorDiff() + var err error if discriminator1 == nil && discriminator2 == nil { - return result + return result, nil } if discriminator1 == nil && discriminator2 != nil { result.Added = true - return result + return result, nil } if discriminator1 != nil && discriminator2 == nil { result.Deleted = true - return result + return result, nil } - result.ExtensionsDiff = getExtensionsDiff(config, state, discriminator1.Extensions, discriminator2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, discriminator1.Extensions, discriminator2.Extensions) + if err != nil { + return nil, err + } result.PropertyNameDiff = getValueDiff(discriminator1.PropertyName, discriminator2.PropertyName) result.MappingDiff = getStringMapDiff(discriminator1.Mapping, discriminator2.Mapping) - return result + return result, nil } diff --git a/diff/encoding_diff.go b/diff/encoding_diff.go index ca11939f..c7d43401 100644 --- a/diff/encoding_diff.go +++ b/diff/encoding_diff.go @@ -42,7 +42,10 @@ func getEncodingDiffInternal(config *Config, state *state, value1, value2 *opena return nil, fmt.Errorf("encoding is nil") } - result.ExtensionsDiff = getExtensionsDiff(config, state, value1.Extensions, value2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, value1.Extensions, value2.Extensions) + if err != nil { + return nil, err + } result.ContentTypeDiff = getValueDiff(value1.ContentType, value2.ContentType) result.HeadersDiff, err = getHeadersDiff(config, state, value1.Headers, value2.Headers) if err != nil { diff --git a/diff/example_diff.go b/diff/example_diff.go index 0996b8f8..d89b204e 100644 --- a/diff/example_diff.go +++ b/diff/example_diff.go @@ -18,24 +18,32 @@ func (diff *ExampleDiff) Empty() bool { return diff == nil || *diff == ExampleDiff{} } -func getExampleDiff(config *Config, state *state, value1, value2 *openapi3.Example) *ExampleDiff { - diff := getExampleDiffInternal(config, state, value1, value2) +func getExampleDiff(config *Config, state *state, value1, value2 *openapi3.Example) (*ExampleDiff, error) { + diff, err := getExampleDiffInternal(config, state, value1, value2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getExampleDiffInternal(config *Config, state *state, value1, value2 *openapi3.Example) *ExampleDiff { +func getExampleDiffInternal(config *Config, state *state, value1, value2 *openapi3.Example) (*ExampleDiff, error) { result := ExampleDiff{} + var err error + + result.ExtensionsDiff, err = getExtensionsDiff(config, state, value1.Extensions, value2.Extensions) + if err != nil { + return nil, err + } - result.ExtensionsDiff = getExtensionsDiff(config, state, value1.Extensions, value2.Extensions) result.SummaryDiff = getValueDiffConditional(config.IsExcludeSummary(), value1.Summary, value2.Summary) result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), value1.Description, value2.Description) result.ValueDiff = getValueDiff(value1.Value, value2.Value) result.ExternalValueDiff = getValueDiff(value1.ExternalValue, value2.ExternalValue) - return &result + return &result, nil } diff --git a/diff/example_test.go b/diff/example_test.go index 58f8d496..79640761 100644 --- a/diff/example_test.go +++ b/diff/example_test.go @@ -76,9 +76,7 @@ func ExampleGetPathsDiff() { return } - diffConfig := diff.NewConfig().WithCheckBreaking() - - diffRes, operationsSources, err := diff.GetPathsDiff(diffConfig, + diffRes, operationsSources, err := diff.GetPathsDiff(diff.NewConfig(), []*load.SpecInfo{s1}, []*load.SpecInfo{s2}, ) diff --git a/diff/examples_diff.go b/diff/examples_diff.go index f44e8101..5d63d325 100644 --- a/diff/examples_diff.go +++ b/diff/examples_diff.go @@ -71,7 +71,10 @@ func getExamplesDiffInternal(config *Config, state *state, examples1, examples2 return nil, err } - diff := getExampleDiff(config, state, value1, value2) + diff, err := getExampleDiff(config, state, value1, value2) + if err != nil { + return nil, err + } if !diff.Empty() { result.Modified[name1] = diff diff --git a/diff/extensions_diff.go b/diff/extensions_diff.go index 564d1027..7eda07e5 100644 --- a/diff/extensions_diff.go +++ b/diff/extensions_diff.go @@ -8,16 +8,23 @@ func (diff *ExtensionsDiff) Empty() bool { return (*InterfaceMapDiff)(diff).Empty() } -func getExtensionsDiff(config *Config, state *state, extensions1, extensions2 map[string]interface{}) *ExtensionsDiff { - diff := getExtensionsDiffInternal(config, state, extensions1, extensions2) +func getExtensionsDiff(config *Config, state *state, extensions1, extensions2 map[string]interface{}) (*ExtensionsDiff, error) { + if config.IsExcludeExtensions() { + return nil, nil + } + + diff, err := getExtensionsDiffInternal(state, extensions1, extensions2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return (*ExtensionsDiff)(diff) + return (*ExtensionsDiff)(diff), nil } -func getExtensionsDiffInternal(config *Config, state *state, extensions1, extensions2 map[string]interface{}) *InterfaceMapDiff { - return getInterfaceMapDiff(extensions1, extensions2, config.IncludeExtensions) +func getExtensionsDiffInternal(state *state, extensions1, extensions2 map[string]interface{}) (*InterfaceMapDiff, error) { + return getInterfaceMapDiff(extensions1, extensions2) } diff --git a/diff/external_docs_diff.go b/diff/external_docs_diff.go index da154f8d..5652c448 100644 --- a/diff/external_docs_diff.go +++ b/diff/external_docs_diff.go @@ -22,36 +22,43 @@ func (diff *ExternalDocsDiff) Empty() bool { return diff == nil || *diff == ExternalDocsDiff{} } -func getExternalDocsDiff(config *Config, state *state, docs1, docs2 *openapi3.ExternalDocs) *ExternalDocsDiff { - diff := getExternalDocsDiffInternal(config, state, docs1, docs2) +func getExternalDocsDiff(config *Config, state *state, docs1, docs2 *openapi3.ExternalDocs) (*ExternalDocsDiff, error) { + diff, err := getExternalDocsDiffInternal(config, state, docs1, docs2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getExternalDocsDiffInternal(config *Config, state *state, docs1, docs2 *openapi3.ExternalDocs) *ExternalDocsDiff { +func getExternalDocsDiffInternal(config *Config, state *state, docs1, docs2 *openapi3.ExternalDocs) (*ExternalDocsDiff, error) { result := newExternalDocsDiff() + var err error if docs1 == nil && docs2 == nil { - return result + return result, nil } if docs1 == nil && docs2 != nil { result.Added = true - return result + return result, nil } if docs1 != nil && docs2 == nil { result.Deleted = true - return result + return result, nil } - result.ExtensionsDiff = getExtensionsDiff(config, state, docs1.Extensions, docs2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, docs1.Extensions, docs2.Extensions) + if err != nil { + return nil, err + } result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), docs1.Description, docs2.Description) result.URLDiff = getValueDiff(docs1.URL, docs2.URL) - return result + return result, nil } diff --git a/diff/header_diff.go b/diff/header_diff.go index b6f97ac4..8f2788fd 100644 --- a/diff/header_diff.go +++ b/diff/header_diff.go @@ -38,7 +38,10 @@ func getHeaderDiffInternal(config *Config, state *state, header1, header2 *opena result := HeaderDiff{} var err error - result.ExtensionsDiff = getExtensionsDiff(config, state, header1.Extensions, header2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, header1.Extensions, header2.Extensions) + if err != nil { + return nil, err + } result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), header1.Description, header2.Description) result.DeprecatedDiff = getValueDiff(header1.Deprecated, header2.Deprecated) result.RequiredDiff = getValueDiff(header1.Required, header2.Required) diff --git a/diff/info_diff.go b/diff/info_diff.go index 66f2b9cf..4d6ea95a 100644 --- a/diff/info_diff.go +++ b/diff/info_diff.go @@ -22,41 +22,57 @@ func (diff *InfoDiff) Empty() bool { return diff == nil || *diff == InfoDiff{} } -func getInfoDiff(config *Config, state *state, info1, info2 *openapi3.Info) *InfoDiff { - diff := getInfoDiffInternal(config, state, info1, info2) +func getInfoDiff(config *Config, state *state, info1, info2 *openapi3.Info) (*InfoDiff, error) { + diff, err := getInfoDiffInternal(config, state, info1, info2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getInfoDiffInternal(config *Config, state *state, info1, info2 *openapi3.Info) *InfoDiff { +func getInfoDiffInternal(config *Config, state *state, info1, info2 *openapi3.Info) (*InfoDiff, error) { if info1 == nil && info2 == nil { - return nil + return nil, nil } if info1 == nil && info2 != nil { return &InfoDiff{ Added: true, - } + }, nil } if info1 != nil && info2 == nil { return &InfoDiff{ Deleted: true, - } + }, nil + } + + extensionsDiff, err := getExtensionsDiff(config, state, info1.Extensions, info2.Extensions) + if err != nil { + return nil, err + } + licenseDiff, err := getLicenseDiff(config, state, info1.License, info2.License) + if err != nil { + return nil, err + } + contactDiff, err := getContactDiff(config, state, info1.Contact, info2.Contact) + if err != nil { + return nil, err } return &InfoDiff{ - ExtensionsDiff: getExtensionsDiff(config, state, info1.Extensions, info2.Extensions), + ExtensionsDiff: extensionsDiff, TitleDiff: getValueDiffConditional(config.IsExcludeTitle(), info1.Title, info2.Title), DescriptionDiff: getValueDiffConditional(config.IsExcludeDescription(), info1.Description, info2.Description), TermsOfServiceDiff: getValueDiff(info1.TermsOfService, info2.TermsOfService), - ContactDiff: getContactDiff(config, state, info1.Contact, info2.Contact), - LicenseDiff: getLicenseDiff(config, state, info1.License, info2.License), + ContactDiff: contactDiff, + LicenseDiff: licenseDiff, VersionDiff: getValueDiff(info1.Version, info2.Version), - } + }, nil } diff --git a/diff/interface_map_diff.go b/diff/interface_map_diff.go index 63cf1506..6ce23bcc 100644 --- a/diff/interface_map_diff.go +++ b/diff/interface_map_diff.go @@ -1,6 +1,8 @@ package diff -import "github.com/tufin/oasdiff/utils" +import ( + "github.com/tufin/oasdiff/utils" +) // InterfaceMap is a map of string to interface type InterfaceMap map[string]interface{} @@ -12,14 +14,6 @@ type InterfaceMapDiff struct { Modified ModifiedInterfaces `json:"modified,omitempty" yaml:"modified,omitempty"` } -// ModifiedInterfaces is map of interface names to their respective diffs -type ModifiedInterfaces map[string]*ValueDiff - -// Empty indicates whether a change was found in this element -func (modifiedInterfaces ModifiedInterfaces) Empty() bool { - return len(modifiedInterfaces) == 0 -} - // Empty indicates whether a change was found in this element func (diff *InterfaceMapDiff) Empty() bool { if diff == nil { @@ -39,39 +33,40 @@ func newInterfaceMapDiff() *InterfaceMapDiff { } } -func getInterfaceMapDiff(map1, map2 InterfaceMap, filter utils.StringSet) *InterfaceMapDiff { - diff := getInterfaceMapDiffInternal(map1, map2, filter) +func getInterfaceMapDiff(map1, map2 InterfaceMap) (*InterfaceMapDiff, error) { + diff, err := getInterfaceMapDiffInternal(map1, map2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getInterfaceMapDiffInternal(map1, map2 InterfaceMap, filter utils.StringSet) *InterfaceMapDiff { +func getInterfaceMapDiffInternal(map1, map2 InterfaceMap) (*InterfaceMapDiff, error) { result := newInterfaceMapDiff() for name1, interface1 := range map1 { - if _, ok := filter[name1]; ok { - if interface2, ok := map2[name1]; ok { - if diff := getValueDiff(interface1, interface2); !diff.Empty() { - result.Modified[name1] = diff - } - } else { - result.Deleted = append(result.Deleted, name1) + if interface2, ok := map2[name1]; ok { + patch, err := compareJson(interface1, interface2) + if err != nil { + return nil, err } + result.Modified[name1] = patch + } else { + result.Deleted = append(result.Deleted, name1) } } for name2 := range map2 { - if _, ok := filter[name2]; ok { - if _, ok := map1[name2]; !ok { - result.Added = append(result.Added, name2) - } + if _, ok := map1[name2]; !ok { + result.Added = append(result.Added, name2) } } - return result + return result, nil } diff --git a/diff/json_diff.go b/diff/json_diff.go new file mode 100644 index 00000000..63d1f7d7 --- /dev/null +++ b/diff/json_diff.go @@ -0,0 +1,43 @@ +package diff + +import ( + "github.com/wI2L/jsondiff" +) + +// jsonPatch is a wrapper to jsondiff.jsonPatch with proper serialization for json and yaml +type jsonPatch []*jsonOperation + +// jsonOperation is a wrapper to jsondiff.jsonOperation with proper serialization for json and yaml +type jsonOperation struct { + OldValue interface{} `json:"oldValue" yaml:"oldValue"` + Value interface{} `json:"value" yaml:"value"` + Type string `json:"op" yaml:"op"` + From string `json:"from" yaml:"from"` + Path string `json:"path" yaml:"path"` +} + +func toJsonPatch(patch jsondiff.Patch) jsonPatch { + result := make(jsonPatch, len(patch)) + for i, op := range patch { + result[i] = newJsonOperation(op) + } + return result +} + +func newJsonOperation(op jsondiff.Operation) *jsonOperation { + return &jsonOperation{ + OldValue: op.OldValue, + Value: op.Value, + Type: op.Type, + From: op.From, + Path: op.Path, + } +} + +func compareJson(source, target interface{}, opts ...jsondiff.Option) (jsonPatch, error) { + patch, err := jsondiff.Compare(source, target, opts...) + if err != nil { + return nil, err + } + return toJsonPatch(patch), nil +} diff --git a/diff/license_diff.go b/diff/license_diff.go index 31e4c416..c55a9a92 100644 --- a/diff/license_diff.go +++ b/diff/license_diff.go @@ -18,37 +18,45 @@ func (diff *LicenseDiff) Empty() bool { return diff == nil || *diff == LicenseDiff{} } -func getLicenseDiff(config *Config, state *state, license1, license2 *openapi3.License) *LicenseDiff { - diff := getLicenseDiffInternal(config, state, license1, license2) +func getLicenseDiff(config *Config, state *state, license1, license2 *openapi3.License) (*LicenseDiff, error) { + diff, err := getLicenseDiffInternal(config, state, license1, license2) + + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getLicenseDiffInternal(config *Config, state *state, license1, license2 *openapi3.License) *LicenseDiff { +func getLicenseDiffInternal(config *Config, state *state, license1, license2 *openapi3.License) (*LicenseDiff, error) { result := LicenseDiff{} + var err error if license1 == nil && license2 == nil { - return &result + return &result, nil } if license1 == nil && license2 != nil { result.Added = true - return &result + return &result, nil } if license1 != nil && license2 == nil { result.Deleted = true - return &result + return &result, nil } - result.ExtensionsDiff = getExtensionsDiff(config, state, license1.Extensions, license2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, license1.Extensions, license2.Extensions) + if err != nil { + return nil, err + } result.NameDiff = getValueDiff(license1.Name, license2.Name) result.URLDiff = getValueDiff(license1.URL, license2.URL) - return &result + return &result, nil } diff --git a/diff/link_diff.go b/diff/link_diff.go index cce31203..1e0fe284 100644 --- a/diff/link_diff.go +++ b/diff/link_diff.go @@ -2,7 +2,6 @@ package diff import ( "github.com/getkin/kin-openapi/openapi3" - "github.com/tufin/oasdiff/utils" ) // LinkDiff describes the changes between a pair of link objects: https://swagger.io/specification/#link-object @@ -36,13 +35,24 @@ func getLinkDiff(config *Config, state *state, link1, link2 *openapi3.Link) (*Li func getLinkDiffInternal(config *Config, state *state, link1, link2 *openapi3.Link) (*LinkDiff, error) { result := LinkDiff{} + var err error + + result.ExtensionsDiff, err = getExtensionsDiff(config, state, link1.Extensions, link2.Extensions) + if err != nil { + return nil, err + } - result.ExtensionsDiff = getExtensionsDiff(config, state, link1.Extensions, link2.Extensions) result.OperationIDDiff = getValueDiff(link1.OperationID, link2.OperationID) result.OperationRefDiff = getValueDiff(link1.OperationRef, link2.OperationRef) result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), link1.Description, link2.Description) - result.ParametersDiff = getInterfaceMapDiff(link1.Parameters, link2.Parameters, utils.StringSet{}) - result.ServerDiff = getServerDiff(config, state, link1.Server, link2.Server) + result.ParametersDiff, err = getInterfaceMapDiff(link1.Parameters, link2.Parameters) + if err != nil { + return nil, err + } + result.ServerDiff, err = getServerDiff(config, state, link1.Server, link2.Server) + if err != nil { + return nil, err + } result.RequestBodyDiff = getValueDiff(link1.RequestBody, link2.RequestBody) return &result, nil diff --git a/diff/media_type_diff.go b/diff/media_type_diff.go index 1221d5cd..d5d7b64d 100644 --- a/diff/media_type_diff.go +++ b/diff/media_type_diff.go @@ -41,7 +41,10 @@ func getMediaTypeDiffInternal(config *Config, state *state, mediaType1 *openapi3 return nil, fmt.Errorf("media type is nil") } - result.ExtensionsDiff = getExtensionsDiff(config, state, mediaType1.Extensions, mediaType2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, mediaType1.Extensions, mediaType2.Extensions) + if err != nil { + return nil, err + } result.SchemaDiff, err = getSchemaDiff(config, state, mediaType1.Schema, mediaType2.Schema) if err != nil { return nil, err diff --git a/diff/method_diff.go b/diff/method_diff.go index 1045f3da..4cd88e9d 100644 --- a/diff/method_diff.go +++ b/diff/method_diff.go @@ -56,7 +56,10 @@ func getMethodDiffInternal(config *Config, state *state, operation1, operation2 result := newMethodDiff() var err error - result.ExtensionsDiff = getExtensionsDiff(config, state, operation1.Extensions, operation2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, operation1.Extensions, operation2.Extensions) + if err != nil { + return nil, err + } result.TagsDiff = getStringsDiff(operation1.Tags, operation2.Tags) result.SummaryDiff = getValueDiffConditional(config.IsExcludeSummary(), operation1.Summary, operation2.Summary) result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), operation1.Description, operation2.Description) @@ -83,7 +86,10 @@ func getMethodDiffInternal(config *Config, state *state, operation1, operation2 result.DeprecatedDiff = getValueDiff(operation1.Deprecated, operation2.Deprecated) result.SecurityDiff = getSecurityRequirementsDiff(config, state, operation1.Security, operation2.Security) result.ServersDiff = getServersDiff(config, state, operation1.Servers, operation2.Servers) - result.ExternalDocsDiff = getExternalDocsDiff(config, state, operation1.ExternalDocs, operation2.ExternalDocs) + result.ExternalDocsDiff, err = getExternalDocsDiff(config, state, operation1.ExternalDocs, operation2.ExternalDocs) + if err != nil { + return nil, err + } result.Base = operation1 result.Revision = operation2 diff --git a/diff/modified_interfaces.go b/diff/modified_interfaces.go new file mode 100644 index 00000000..2d8ae683 --- /dev/null +++ b/diff/modified_interfaces.go @@ -0,0 +1,9 @@ +package diff + +// ModifiedInterfaces is map of interface names to their respective diffs +type ModifiedInterfaces map[string]jsonPatch + +// Empty indicates whether a change was found in this element +func (modifiedInterfaces ModifiedInterfaces) Empty() bool { + return len(modifiedInterfaces) == 0 +} diff --git a/diff/oauth_flow.go b/diff/oauth_flow.go index 82dc82b2..4befb6a7 100644 --- a/diff/oauth_flow.go +++ b/diff/oauth_flow.go @@ -20,39 +20,47 @@ func (diff *OAuthFlowDiff) Empty() bool { return diff == nil || *diff == OAuthFlowDiff{} } -func getOAuthFlowDiff(config *Config, state *state, flow1, flow2 *openapi3.OAuthFlow) *OAuthFlowDiff { - diff := getOAuthFlowDiffInternal(config, state, flow1, flow2) +func getOAuthFlowDiff(config *Config, state *state, flow1, flow2 *openapi3.OAuthFlow) (*OAuthFlowDiff, error) { + diff, err := getOAuthFlowDiffInternal(config, state, flow1, flow2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getOAuthFlowDiffInternal(config *Config, state *state, flow1, flow2 *openapi3.OAuthFlow) *OAuthFlowDiff { +func getOAuthFlowDiffInternal(config *Config, state *state, flow1, flow2 *openapi3.OAuthFlow) (*OAuthFlowDiff, error) { if flow1 == nil && flow2 == nil { - return nil + return nil, nil } result := OAuthFlowDiff{} + var err error if flow1 == nil && flow2 != nil { result.Added = true - return &result + return &result, nil } if flow1 != nil && flow2 == nil { result.Deleted = true - return &result + return &result, nil + } + + result.ExtensionsDiff, err = getExtensionsDiff(config, state, flow1.Extensions, flow2.Extensions) + if err != nil { + return nil, err } - result.ExtensionsDiff = getExtensionsDiff(config, state, flow1.Extensions, flow2.Extensions) result.AuthorizationURLDiff = getValueDiff(flow1.AuthorizationURL, flow2.AuthorizationURL) result.TokenURLDiff = getValueDiff(flow1.TokenURL, flow2.TokenURL) result.RefreshURLDiff = getValueDiff(flow1.RefreshURL, flow2.RefreshURL) result.ScopesDiff = getStringMapDiff(flow1.Scopes, flow2.Scopes) - return &result + return &result, nil } diff --git a/diff/oauth_flows.go b/diff/oauth_flows.go index 53aaffae..6702b0b1 100644 --- a/diff/oauth_flows.go +++ b/diff/oauth_flows.go @@ -20,41 +20,64 @@ func (diff *OAuthFlowsDiff) Empty() bool { return diff == nil || *diff == OAuthFlowsDiff{} } -func getOAuthFlowsDiff(config *Config, state *state, flows1, flows2 *openapi3.OAuthFlows) *OAuthFlowsDiff { - diff := getOAuthFlowsDiffInternal(config, state, flows1, flows2) +func getOAuthFlowsDiff(config *Config, state *state, flows1, flows2 *openapi3.OAuthFlows) (*OAuthFlowsDiff, error) { + diff, err := getOAuthFlowsDiffInternal(config, state, flows1, flows2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getOAuthFlowsDiffInternal(config *Config, state *state, flows1, flows2 *openapi3.OAuthFlows) *OAuthFlowsDiff { +func getOAuthFlowsDiffInternal(config *Config, state *state, flows1, flows2 *openapi3.OAuthFlows) (*OAuthFlowsDiff, error) { if flows1 == nil && flows2 == nil { - return nil + return nil, nil } if flows1 == nil && flows2 != nil { return &OAuthFlowsDiff{ Added: true, - } + }, nil } if flows1 != nil && flows2 == nil { return &OAuthFlowsDiff{ Deleted: true, - } + }, nil } result := OAuthFlowsDiff{} + var err error + + result.ExtensionsDiff, err = getExtensionsDiff(config, state, flows1.Extensions, flows2.Extensions) + if err != nil { + return nil, err + } + + result.ImplicitDiff, err = getOAuthFlowDiff(config, state, flows1.Implicit, flows2.Implicit) + if err != nil { + return nil, err + } - result.ExtensionsDiff = getExtensionsDiff(config, state, flows1.Extensions, flows2.Extensions) - result.ImplicitDiff = getOAuthFlowDiff(config, state, flows1.Implicit, flows2.Implicit) - result.PasswordDiff = getOAuthFlowDiff(config, state, flows1.Password, flows2.Password) - result.ClientCredentialsDiff = getOAuthFlowDiff(config, state, flows1.ClientCredentials, flows2.ClientCredentials) - result.AuthorizationCodeDiff = getOAuthFlowDiff(config, state, flows1.AuthorizationCode, flows2.AuthorizationCode) + result.PasswordDiff, err = getOAuthFlowDiff(config, state, flows1.Password, flows2.Password) + if err != nil { + return nil, err + } + + result.ClientCredentialsDiff, err = getOAuthFlowDiff(config, state, flows1.ClientCredentials, flows2.ClientCredentials) + if err != nil { + return nil, err + } + + result.AuthorizationCodeDiff, err = getOAuthFlowDiff(config, state, flows1.AuthorizationCode, flows2.AuthorizationCode) + if err != nil { + return nil, err + } - return &result + return &result, nil } diff --git a/diff/parameter_diff.go b/diff/parameter_diff.go index 039bc978..f928b646 100644 --- a/diff/parameter_diff.go +++ b/diff/parameter_diff.go @@ -49,7 +49,11 @@ func getParameterDiffInternal(config *Config, state *state, param1, param2 *open result.NameDiff = getValueDiff(param1.Name, param2.Name) result.InDiff = getValueDiff(param1.In, param2.In) - result.ExtensionsDiff = getExtensionsDiff(config, state, param1.Extensions, param2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, param1.Extensions, param2.Extensions) + if err != nil { + return nil, err + } + result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), param1.Description, param2.Description) result.StyleDiff = getValueDiff(param1.Style, param2.Style) result.ExplodeDiff = getBoolRefDiff(param1.Explode, param2.Explode) diff --git a/diff/patch_test.go b/diff/patch_test.go index 3d4e4389..bb46f296 100644 --- a/diff/patch_test.go +++ b/diff/patch_test.go @@ -18,7 +18,7 @@ func TestPatch_MethodDescription(t *testing.T) { require.NoError(t, d1.Patch(s1)) - d2, err := diff.Get(diff.NewConfig(), s1, s2) + d2, err := diff.Get(diff.NewConfig().WithExcludeExtensions(), s1, s2) require.NoError(t, err) require.False(t, d2.GetSummary().Diff) } @@ -34,7 +34,7 @@ func TestPatch_ParameterDescription(t *testing.T) { require.NoError(t, d1.Patch(s1)) - d2, err := diff.Get(diff.NewConfig(), s1, s2) + d2, err := diff.Get(diff.NewConfig().WithExcludeExtensions(), s1, s2) require.NoError(t, err) require.False(t, d2.GetSummary().Diff) } @@ -51,7 +51,7 @@ func TestPatch_ParameterSchemaFormat(t *testing.T) { require.NoError(t, d1.Patch(s1)) - d2, err := diff.Get(diff.NewConfig(), s1, s2) + d2, err := diff.Get(diff.NewConfig().WithExcludeExtensions(), s1, s2) require.NoError(t, err) require.False(t, d2.GetSummary().Diff) } @@ -67,7 +67,7 @@ func TestPatch_ParameterSchemaEnum(t *testing.T) { require.NoError(t, d1.Patch(s1)) - d2, err := diff.Get(diff.NewConfig(), s1, s2) + d2, err := diff.Get(diff.NewConfig().WithExcludeExtensions(), s1, s2) require.NoError(t, err) require.False(t, d2.GetSummary().Diff) } @@ -85,7 +85,7 @@ func TestPatch_ParameterSchemaMaxLengthNil(t *testing.T) { require.NoError(t, d1.Patch(s1)) - d2, err := diff.Get(diff.NewConfig(), s1, s2) + d2, err := diff.Get(diff.NewConfig().WithExcludeExtensions(), s1, s2) require.NoError(t, err) require.False(t, d2.GetSummary().Diff) } @@ -102,7 +102,7 @@ func TestPatch_ParameterSchemaMaxLength(t *testing.T) { require.NoError(t, d1.Patch(s1)) - d2, err := diff.Get(diff.NewConfig(), s1, s2) + d2, err := diff.Get(diff.NewConfig().WithExcludeExtensions(), s1, s2) require.NoError(t, err) require.False(t, d2.GetSummary().Diff) } diff --git a/diff/path_diff.go b/diff/path_diff.go index e84a0f37..7dd6d209 100644 --- a/diff/path_diff.go +++ b/diff/path_diff.go @@ -54,7 +54,11 @@ func getPathDiffInternal(config *Config, state *state, pathItemPair *pathItemPai result := newPathDiff() var err error - result.ExtensionsDiff = getExtensionsDiff(config, state, pathItem1.Extensions, pathItem2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, pathItem1.Extensions, pathItem2.Extensions) + if err != nil { + return nil, err + } + result.RefDiff = getValueDiff(pathItem1.Ref, pathItem2.Ref) result.SummaryDiff = getValueDiffConditional(config.IsExcludeSummary(), pathItem1.Summary, pathItem2.Summary) result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), pathItem1.Description, pathItem2.Description) diff --git a/diff/request_body_diff.go b/diff/request_body_diff.go index 5edb8b56..d13d1847 100644 --- a/diff/request_body_diff.go +++ b/diff/request_body_diff.go @@ -68,7 +68,11 @@ func getRequestBodyDiffInternal(config *Config, state *state, requestBodyRef1, r return nil, err } - result.ExtensionsDiff = getExtensionsDiff(config, state, requestBody1.Extensions, requestBody2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, requestBody1.Extensions, requestBody2.Extensions) + if err != nil { + return nil, err + } + result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), requestBody1.Description, requestBody2.Description) result.RequiredDiff = getValueDiff(requestBody1.Required, requestBody2.Required) result.ContentDiff, err = getContentDiff(config, state, requestBody1.Content, requestBody2.Content) diff --git a/diff/response_diff.go b/diff/response_diff.go index 74ffc888..90b4898e 100644 --- a/diff/response_diff.go +++ b/diff/response_diff.go @@ -37,7 +37,11 @@ func diffResponseValuesInternal(config *Config, state *state, response1, respons result := ResponseDiff{} var err error - result.ExtensionsDiff = getExtensionsDiff(config, state, response1.Extensions, response2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, response1.Extensions, response2.Extensions) + if err != nil { + return nil, err + } + result.DescriptionDiff = getStringRefDiffConditional(config.IsExcludeDescription(), response1.Description, response2.Description) result.HeadersDiff, err = getHeadersDiff(config, state, response1.Headers, response2.Headers) if err != nil { diff --git a/diff/schema_diff.go b/diff/schema_diff.go index 133ff59d..b0eb31f9 100644 --- a/diff/schema_diff.go +++ b/diff/schema_diff.go @@ -125,7 +125,10 @@ func getSchemaDiffInternal(config *Config, state *state, schema1, schema2 *opena var err error - result.ExtensionsDiff = getExtensionsDiff(config, state, value1.Extensions, value2.Extensions) + result.ExtensionsDiff, err = getExtensionsDiff(config, state, value1.Extensions, value2.Extensions) + if err != nil { + return nil, err + } result.OneOfDiff, err = getSchemaListsDiff(config, state, value1.OneOf, value2.OneOf) if err != nil { return nil, err @@ -149,7 +152,10 @@ func getSchemaDiffInternal(config *Config, state *state, schema1, schema2 *opena result.EnumDiff = getEnumDiff(config, state, value1.Enum, value2.Enum) result.DefaultDiff = getValueDiff(value1.Default, value2.Default) result.ExampleDiff = getValueDiffConditional(config.IsExcludeExamples(), value1.Example, value2.Example) - result.ExternalDocsDiff = getExternalDocsDiff(config, state, value1.ExternalDocs, value2.ExternalDocs) + result.ExternalDocsDiff, err = getExternalDocsDiff(config, state, value1.ExternalDocs, value2.ExternalDocs) + if err != nil { + return nil, err + } result.AdditionalPropertiesAllowedDiff = getBoolRefDiff(value1.AdditionalProperties.Has, value2.AdditionalProperties.Has) result.UniqueItemsDiff = getValueDiff(value1.UniqueItems, value2.UniqueItems) result.ExclusiveMinDiff = getValueDiff(value1.ExclusiveMin, value2.ExclusiveMin) @@ -188,7 +194,10 @@ func getSchemaDiffInternal(config *Config, state *state, schema1, schema2 *opena return nil, err } - result.DiscriminatorDiff = getDiscriminatorDiff(config, state, value1.Discriminator, value2.Discriminator) + result.DiscriminatorDiff, err = getDiscriminatorDiff(config, state, value1.Discriminator, value2.Discriminator) + if err != nil { + return nil, err + } return &result, nil } diff --git a/diff/security_scheme.go b/diff/security_scheme.go index 47a458a1..a8ab846c 100644 --- a/diff/security_scheme.go +++ b/diff/security_scheme.go @@ -22,28 +22,39 @@ func (diff *SecuritySchemeDiff) Empty() bool { return diff == nil || *diff == SecuritySchemeDiff{} } -func getSecuritySchemeDiff(config *Config, state *state, scheme1, scheme2 *openapi3.SecurityScheme) *SecuritySchemeDiff { - diff := getSecuritySchemeDiffInternal(config, state, scheme1, scheme2) +func getSecuritySchemeDiff(config *Config, state *state, scheme1, scheme2 *openapi3.SecurityScheme) (*SecuritySchemeDiff, error) { + diff, err := getSecuritySchemeDiffInternal(config, state, scheme1, scheme2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getSecuritySchemeDiffInternal(config *Config, state *state, scheme1, scheme2 *openapi3.SecurityScheme) *SecuritySchemeDiff { +func getSecuritySchemeDiffInternal(config *Config, state *state, scheme1, scheme2 *openapi3.SecurityScheme) (*SecuritySchemeDiff, error) { result := SecuritySchemeDiff{} + var err error + + result.ExtensionsDiff, err = getExtensionsDiff(config, state, scheme1.Extensions, scheme2.Extensions) + if err != nil { + return nil, err + } - result.ExtensionsDiff = getExtensionsDiff(config, state, scheme1.Extensions, scheme2.Extensions) result.TypeDiff = getValueDiff(scheme1.Type, scheme2.Type) result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), scheme1.Description, scheme2.Description) result.NameDiff = getValueDiff(scheme1.Name, scheme2.Name) result.InDiff = getValueDiff(scheme1.In, scheme2.In) result.SchemeDiff = getValueDiff(scheme1.Scheme, scheme2.Scheme) result.BearerFormatDiff = getValueDiff(scheme1.BearerFormat, scheme2.BearerFormat) - result.OAuthFlowsDiff = getOAuthFlowsDiff(config, state, scheme1.Flows, scheme2.Flows) + result.OAuthFlowsDiff, err = getOAuthFlowsDiff(config, state, scheme1.Flows, scheme2.Flows) + if err != nil { + return nil, err + } result.OpenIDConnectURLDiff = getValueDiff(scheme1.OpenIdConnectUrl, scheme2.OpenIdConnectUrl) - return &result + return &result, nil } diff --git a/diff/security_schemes.go b/diff/security_schemes.go index 66ba47aa..c3ca5ac1 100644 --- a/diff/security_schemes.go +++ b/diff/security_schemes.go @@ -63,7 +63,11 @@ func getSecuritySchemesDiffInternal(config *Config, state *state, securityScheme if err != nil { return nil, err } - if diff := getSecuritySchemeDiff(config, state, value1, value2); !diff.Empty() { + diff, err := getSecuritySchemeDiff(config, state, value1, value2) + if err != nil { + return nil, err + } + if !diff.Empty() { result.Modified[name1] = diff } } else { diff --git a/diff/server_diff.go b/diff/server_diff.go index e26e7349..eae33552 100644 --- a/diff/server_diff.go +++ b/diff/server_diff.go @@ -19,38 +19,49 @@ func (diff *ServerDiff) Empty() bool { return diff == nil || *diff == ServerDiff{} } -func getServerDiff(config *Config, state *state, value1, value2 *openapi3.Server) *ServerDiff { - diff := getServerDiffInternal(config, state, value1, value2) +func getServerDiff(config *Config, state *state, value1, value2 *openapi3.Server) (*ServerDiff, error) { + diff, err := getServerDiffInternal(config, state, value1, value2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getServerDiffInternal(config *Config, state *state, value1, value2 *openapi3.Server) *ServerDiff { +func getServerDiffInternal(config *Config, state *state, value1, value2 *openapi3.Server) (*ServerDiff, error) { if value1 == nil && value2 == nil { - return nil + return nil, nil } result := ServerDiff{} + var err error if value1 == nil && value2 != nil { result.Added = true - return &result + return &result, nil } if value1 != nil && value2 == nil { result.Deleted = true - return &result + return &result, nil + } + + result.ExtensionsDiff, err = getExtensionsDiff(config, state, value1.Extensions, value2.Extensions) + if err != nil { + return nil, err } - result.ExtensionsDiff = getExtensionsDiff(config, state, value1.Extensions, value2.Extensions) result.URLDiff = getValueDiff(value1.URL, value2.URL) result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), value1.Description, value2.Description) - result.VariablesDiff = getVariablesDiff(config, state, value1.Variables, value2.Variables) + result.VariablesDiff, err = getVariablesDiff(config, state, value1.Variables, value2.Variables) + if err != nil { + return nil, err + } - return &result + return &result, nil } diff --git a/diff/servers_diff.go b/diff/servers_diff.go index 4e67f019..31124733 100644 --- a/diff/servers_diff.go +++ b/diff/servers_diff.go @@ -53,7 +53,11 @@ func getServersDiffInternal(config *Config, state *state, pServers1, pServers2 * for _, server1 := range servers1 { if server2 := findServer(server1, servers2); server2 != nil { - if diff := getServerDiff(config, state, server1, server2); !diff.Empty() { + diff, err := getServerDiff(config, state, server1, server2) + if err != nil { + return nil + } + if !diff.Empty() { result.Modified[server1.URL] = diff } } else { diff --git a/diff/variable_diff.go b/diff/variable_diff.go index b05d0f0e..98bc79a9 100644 --- a/diff/variable_diff.go +++ b/diff/variable_diff.go @@ -17,23 +17,31 @@ func (diff *VariableDiff) Empty() bool { return diff == nil || *diff == VariableDiff{} } -func getVariableDiff(config *Config, state *state, var1, var2 *openapi3.ServerVariable) *VariableDiff { - diff := getVariableDiffInternal(config, state, var1, var2) +func getVariableDiff(config *Config, state *state, var1, var2 *openapi3.ServerVariable) (*VariableDiff, error) { + diff, err := getVariableDiffInternal(config, state, var1, var2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getVariableDiffInternal(config *Config, state *state, var1, var2 *openapi3.ServerVariable) *VariableDiff { +func getVariableDiffInternal(config *Config, state *state, var1, var2 *openapi3.ServerVariable) (*VariableDiff, error) { result := VariableDiff{} + var err error + + result.ExtensionsDiff, err = getExtensionsDiff(config, state, var1.Extensions, var2.Extensions) + if err != nil { + return nil, err + } - result.ExtensionsDiff = getExtensionsDiff(config, state, var1.Extensions, var2.Extensions) result.EnumDiff = getStringsDiff(var1.Enum, var2.Enum) result.DefaultDiff = getValueDiff(var1.Default, var2.Default) result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), var1.Description, var2.Description) - return &result + return &result, nil } diff --git a/diff/variables_diff.go b/diff/variables_diff.go index eaaaca0c..9938d83e 100644 --- a/diff/variables_diff.go +++ b/diff/variables_diff.go @@ -34,17 +34,20 @@ func newVariablesDiff() *VariablesDiff { } } -func getVariablesDiff(config *Config, state *state, variables1, variables2 map[string]*openapi3.ServerVariable) *VariablesDiff { - diff := getVariablesDiffInternal(config, state, variables1, variables2) +func getVariablesDiff(config *Config, state *state, variables1, variables2 map[string]*openapi3.ServerVariable) (*VariablesDiff, error) { + diff, err := getVariablesDiffInternal(config, state, variables1, variables2) + if err != nil { + return nil, err + } if diff.Empty() { - return nil + return nil, nil } - return diff + return diff, nil } -func getVariablesDiffInternal(config *Config, state *state, variables1, variables2 map[string]*openapi3.ServerVariable) *VariablesDiff { +func getVariablesDiffInternal(config *Config, state *state, variables1, variables2 map[string]*openapi3.ServerVariable) (*VariablesDiff, error) { result := newVariablesDiff() for name1, var1 := range variables1 { @@ -54,7 +57,11 @@ func getVariablesDiffInternal(config *Config, state *state, variables1, variable continue } - if diff := getVariableDiff(config, state, var1, var2); !diff.Empty() { + diff, err := getVariableDiff(config, state, var1, var2) + if err != nil { + return nil, err + } + if !diff.Empty() { result.Modified[name1] = diff } } @@ -66,5 +73,5 @@ func getVariablesDiffInternal(config *Config, state *state, variables1, variable } } - return result + return result, nil } diff --git a/go.mod b/go.mod index 93876538..31141acd 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/tufin/oasdiff go 1.21.5 -toolchain go1.22.1 +toolchain go1.22.2 require ( cloud.google.com/go v0.112.2 @@ -23,6 +23,10 @@ require ( github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/spf13/pflag v1.0.5 // indirect + github.com/tidwall/gjson v1.17.0 // indirect + github.com/tidwall/match v1.1.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect + github.com/tidwall/sjson v1.2.5 // indirect golang.org/x/sys v0.18.0 // indirect ) @@ -37,4 +41,5 @@ require ( github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/spf13/cobra v1.8.0 + github.com/wI2L/jsondiff v0.5.1 ) diff --git a/go.sum b/go.sum index 928a89d3..67558d98 100644 --- a/go.sum +++ b/go.sum @@ -55,8 +55,19 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.17.0 h1:/Jocvlh98kcTfpN2+JzGQWQcqrPQwDrVEMApx/M5ZwM= +github.com/tidwall/gjson v1.17.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= +github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= +github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY= +github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/wI2L/jsondiff v0.5.1 h1:xS4zYUspH4U3IB0Lwo9+jv+MSRJSWMF87Y4BpDbFMHo= +github.com/wI2L/jsondiff v0.5.1/go.mod h1:qqG6hnK0Lsrz2BpIVCxWiK9ItsBCpIZQiv0izJjOZ9s= github.com/yargevad/filepathx v1.0.0 h1:SYcT+N3tYGi+NvazubCNlvgIPbzAk7i7y2dwg3I5FYc= github.com/yargevad/filepathx v1.0.0/go.mod h1:BprfX/gpYNJHJfc35GjRRpVcwWXS89gGulUIU5tK3tA= github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA= diff --git a/internal/changelog_flags.go b/internal/changelog_flags.go index ffb3f616..d18e11f5 100644 --- a/internal/changelog_flags.go +++ b/internal/changelog_flags.go @@ -33,7 +33,7 @@ type ChangelogFlags struct { } func (flags *ChangelogFlags) toConfig() *diff.Config { - config := diff.NewConfig().WithCheckBreaking().WithExcludeElements(flags.excludeElements) + config := diff.NewConfig() config.PathFilter = flags.matchPath config.FilterExtension = flags.filterExtension config.PathPrefixBase = flags.prefixBase diff --git a/internal/cmd_flags.go b/internal/cmd_flags.go index 4b45518e..19580424 100644 --- a/internal/cmd_flags.go +++ b/internal/cmd_flags.go @@ -4,12 +4,10 @@ import ( "github.com/spf13/cobra" "github.com/tufin/oasdiff/checker" "github.com/tufin/oasdiff/checker/localizations" - "github.com/tufin/oasdiff/diff" ) func addCommonDiffFlags(cmd *cobra.Command, flags Flags) { cmd.PersistentFlags().BoolVarP(flags.refComposed(), "composed", "c", false, "work in 'composed' mode, compare paths in all specs matching base and revision globs") - enumWithOptions(cmd, newEnumSliceValue(diff.ExcludeDiffOptions, nil, flags.refExcludeElements()), "exclude-elements", "e", "comma-separated list of elements to exclude") cmd.PersistentFlags().StringVarP(flags.refMatchPath(), "match-path", "p", "", "include only paths that match this regular expression") cmd.PersistentFlags().StringVarP(flags.refFilterExtension(), "filter-extension", "", "", "exclude paths and operations with an OpenAPI Extension matching this regular expression") cmd.PersistentFlags().IntVarP(flags.refCircularReferenceCounter(), "max-circular-dep", "", 5, "maximum allowed number of circular dependencies between objects in OpenAPI specs") diff --git a/internal/diff.go b/internal/diff.go index f636cf03..dcc2927a 100644 --- a/internal/diff.go +++ b/internal/diff.go @@ -24,6 +24,7 @@ func getDiffCmd() *cobra.Command { } addCommonDiffFlags(&cmd, &flags) + enumWithOptions(&cmd, newEnumSliceValue(diff.ExcludeDiffOptions, nil, flags.refExcludeElements()), "exclude-elements", "e", "comma-separated list of elements to exclude") enumWithOptions(&cmd, newEnumValue(formatters.SupportedFormatsByContentType(formatters.OutputDiff), string(formatters.FormatYAML), &flags.format), "format", "f", "output format") cmd.PersistentFlags().BoolVarP(&flags.failOnDiff, "fail-on-diff", "o", false, "exit with return code 1 when any change is found") diff --git a/internal/enum_slice.go b/internal/enum_slice.go index c1db7bb7..6cff093b 100644 --- a/internal/enum_slice.go +++ b/internal/enum_slice.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/csv" "fmt" + "slices" "strings" "github.com/tufin/oasdiff/utils" @@ -18,6 +19,7 @@ type enumSliceValue struct { func newEnumSliceValue(allowedValues []string, val []string, p *[]string) *enumSliceValue { result := new(enumSliceValue) + slices.Sort(allowedValues) result.allowedValues = allowedValues result.value = p *result.value = val diff --git a/internal/run_test.go b/internal/run_test.go index 17a90607..6a21905c 100644 --- a/internal/run_test.go +++ b/internal/run_test.go @@ -195,7 +195,7 @@ func Test_BreakingChangesInvalidIgnoreFile(t *testing.T) { func Test_ComposedMode(t *testing.T) { var stdout bytes.Buffer - require.Zero(t, internal.Run(cmdToArgs("oasdiff diff ../data/composed/base/*.yaml ../data/composed/revision/*.yaml --composed --exclude-elements endpoints"), &stdout, io.Discard)) + require.Zero(t, internal.Run(cmdToArgs("oasdiff diff ../data/composed/base/*.yaml ../data/composed/revision/*.yaml --composed --exclude-elements endpoints,extensions"), &stdout, io.Discard)) var bc interface{} require.NoError(t, yaml.Unmarshal(stdout.Bytes(), &bc)) require.Equal(t, map[string]interface{}{"paths": map[string]interface{}{"deleted": []interface{}{"/api/old-test"}}}, bc) diff --git a/internal/summary.go b/internal/summary.go index 60c497b2..0309e128 100644 --- a/internal/summary.go +++ b/internal/summary.go @@ -22,6 +22,7 @@ func getSummaryCmd() *cobra.Command { } addCommonDiffFlags(&cmd, &flags) + enumWithOptions(&cmd, newEnumSliceValue(diff.ExcludeDiffOptions, nil, flags.refExcludeElements()), "exclude-elements", "e", "comma-separated list of elements to exclude") enumWithOptions(&cmd, newEnumValue(formatters.SupportedFormatsByContentType(formatters.OutputSummary), string(formatters.FormatYAML), &flags.format), "format", "f", "output format") cmd.PersistentFlags().BoolVarP(&flags.failOnDiff, "fail-on-diff", "", false, "exit with return code 1 when any change is found") diff --git a/report/text_test.go b/report/text_test.go index e9c777db..4e127d12 100644 --- a/report/text_test.go +++ b/report/text_test.go @@ -28,7 +28,7 @@ func d(t *testing.T, config *diff.Config, v1, v2 int) *diff.Diff { } func Test_NoChanges(t *testing.T) { - require.Equal(t, report.GetTextReportAsString(d(t, &diff.Config{}, 3, 3)), "No changes\n") + require.Equal(t, report.GetTextReportAsString(d(t, diff.NewConfig().WithExcludeExtensions(), 3, 3)), "No changes\n") } func Test_NoEndpointChanges(t *testing.T) {