From 1e654375fb8a6bab322b3e5c3715ca010f708547 Mon Sep 17 00:00:00 2001 From: Reuven Date: Thu, 30 Nov 2023 22:37:17 +0200 Subject: [PATCH 1/9] first approximation --- BREAKING-CHANGES-EXAMPLES.md | 36 ++--- checker/check-api-added.go | 2 +- .../check-api-operation-id-updated_test.go | 6 +- checker/check-api-removed.go | 6 +- checker/check-api-tag-updated_test.go | 6 +- ...equest-body-required-value-updated_test.go | 4 +- ...parameter-pattern-added-or-changed_test.go | 2 +- ...t-parameters-default-value-changed_test.go | 4 +- ...ck-request-parameters-type-changed_test.go | 12 +- ...uest-property-became-not-nuallable_test.go | 4 +- ...est-property-default-value-changed_test.go | 10 +- ...equest-property-enum-value-updated_test.go | 4 +- ...equest-property-max-length-updated_test.go | 16 +- ...check-request-property-max-updated_test.go | 12 +- ...equest-property-min-length-updated_test.go | 8 +- ...-property-pattern-added-or-changed_test.go | 2 +- ...-request-property-required-updated_test.go | 4 +- ...heck-request-property-type-changed_test.go | 10 +- .../check-request-property-updated_test.go | 2 +- ...uest-property-write-only-read-only_test.go | 16 +- ...response-optional-property-updated_test.go | 4 +- ...nse-property-default-value-changed_test.go | 6 +- ...eck-response-property-type-changed_test.go | 4 +- checker/check-response-status-updated_test.go | 8 +- checker/checker.go | 6 +- checker/checker_breaking_min_max_test.go | 72 ++++----- checker/checker_breaking_property_test.go | 22 +-- ...cker_breaking_request_type_changed_test.go | 22 +-- ...ker_breaking_response_type_changed_test.go | 22 +-- checker/checker_breaking_test.go | 106 ++++++------- checker/checker_deprecation_test.go | 30 ++-- checker/checker_not_breaking_test.go | 34 ++-- ...t_parameter_required_value_updated_test.go | 8 +- diff/callbacks_diff.go | 10 +- diff/components_diff.go | 3 +- diff/diff.go | 38 ++--- diff/diff_error_test.go | 46 +++--- diff/diff_test.go | 20 +-- diff/endpoints_diff.go | 12 +- diff/patch_error_test.go | 12 +- diff/patch_test.go | 150 +++++++++--------- diff/path_items_diff.go | 24 +-- diff/paths_diff.go | 34 ++-- diff/responses_diff.go | 12 +- flatten/merge_allof_spec.go | 14 +- flatten/merge_allof_spec_test.go | 6 +- flatten/merge_allof_test.go | 2 +- go.mod | 6 +- go.sum | 12 +- lint/path_params.go | 2 +- lint/required_params.go | 2 +- lint/shcema_checker.go | 6 +- utils/openapi_convertors.go | 11 ++ 53 files changed, 479 insertions(+), 453 deletions(-) create mode 100644 utils/openapi_convertors.go diff --git a/BREAKING-CHANGES-EXAMPLES.md b/BREAKING-CHANGES-EXAMPLES.md index 7ce6b8d7..36d7f275 100644 --- a/BREAKING-CHANGES-EXAMPLES.md +++ b/BREAKING-CHANGES-EXAMPLES.md @@ -40,7 +40,7 @@ These examples are automatically generated from unit tests. [deleting a media-type from response is breaking](checker/checker_breaking_test.go?plain=1#L428) [deleting a non-required non-write-only property in response body is breaking with warning](checker/checker_breaking_property_test.go?plain=1#L511) [deleting a path is breaking](checker/checker_breaking_test.go?plain=1#L43) -[deleting a path with some operations having sunset date in the future is breaking](checker/checker_deprecation_test.go?plain=1#L271) +[deleting a path with some operations having sunset date in the future is breaking](checker/checker_deprecation_test.go?plain=1#L275) [deleting a required property in request is breaking with warn](checker/checker_breaking_property_test.go?plain=1#L368) [deleting a required property in response body is breaking](checker/checker_breaking_property_test.go?plain=1#L420) [deleting a required property under AllOf in response body is breaking](checker/checker_breaking_property_test.go?plain=1#L450) @@ -49,8 +49,8 @@ These examples are automatically generated from unit tests. [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 without sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L50) -[deleting sunset header for a deprecated endpoint is breaking](checker/checker_deprecation_test.go?plain=1#L288) -[deprecating an operation with a deprecation policy and sunset date before required deprecation period is breaking](checker/checker_deprecation_test.go?plain=1#L216) +[deleting sunset header for a deprecated endpoint is breaking](checker/checker_deprecation_test.go?plain=1#L292) +[deprecating an operation with a deprecation policy and sunset date before required deprecation period is breaking](checker/checker_deprecation_test.go?plain=1#L220) [deprecating an operation with a deprecation policy but without specifying sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L82) [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) @@ -76,8 +76,8 @@ These examples are automatically generated from unit tests. [removing an existing response with successful status is breaking](checker/checker_breaking_test.go?plain=1#L245) [removing an schema object from components is breaking (optional)](checker/checker_breaking_test.go?plain=1#L609) [removing the default value of an optional request parameter is breaking](checker/checker_breaking_test.go?plain=1#L572) -[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#L135) -[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#L189) +[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#L137) +[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#L193) [removing/updating a property enum in response is breaking (optional)](checker/checker_breaking_test.go?plain=1#L323) [removing/updating a tag is breaking (optional)](checker/checker_breaking_test.go?plain=1#L340) [removing/updating an enum in request body is breaking (optional)](checker/checker_breaking_test.go?plain=1#L301) @@ -90,11 +90,11 @@ These examples are automatically generated from unit tests. [adding a new required property under AllOf in response body is not breaking](checker/checker_breaking_property_test.go?plain=1#L436) [adding a new required read-only property in request body is not breaking](checker/checker_breaking_property_test.go?plain=1#L466) [adding a non-existent required property in request body is not breaking](checker/checker_breaking_property_test.go?plain=1#L294) -[adding a required property to response is not breaking](checker/checker_not_breaking_test.go?plain=1#L290) -[adding a tag is not breaking](checker/checker_not_breaking_test.go?plain=1#L267) +[adding a required property to response is not breaking](checker/checker_not_breaking_test.go?plain=1#L292) +[adding a tag is not breaking](checker/checker_not_breaking_test.go?plain=1#L269) [adding an enum value is not breaking](checker/checker_not_breaking_test.go?plain=1#L83) [adding an enum value to request body is not breaking](checker/checker_breaking_property_test.go?plain=1#L138) -[adding an operation ID is not breaking](checker/checker_not_breaking_test.go?plain=1#L278) +[adding an operation ID is not breaking](checker/checker_not_breaking_test.go?plain=1#L280) [adding an optional request body is not breaking](checker/checker_not_breaking_test.go?plain=1#L38) [both max lengths in request are nil is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L178) [both max lengths in response are nil is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L192) @@ -113,17 +113,17 @@ These examples are automatically generated from unit tests. [changing request's body schema type from integer to number is not breaking](checker/checker_breaking_request_type_changed_test.go?plain=1#L71) [changing response's body schema type from number to integer is not breaking](checker/checker_breaking_response_type_changed_test.go?plain=1#L51) [changing response's body schema type from number/none to integer/int32 is not breaking](checker/checker_breaking_response_type_changed_test.go?plain=1#L89) -[changing servers is not breaking](checker/checker_not_breaking_test.go?plain=1#L253) -[deleting a path after sunset date of all contained operations is not breaking](checker/checker_deprecation_test.go?plain=1#L256) +[changing servers is not breaking](checker/checker_not_breaking_test.go?plain=1#L255) +[deleting a path after sunset date of all contained operations is not breaking](checker/checker_deprecation_test.go?plain=1#L260) [deleting a pattern from a schema is not breaking](checker/checker_breaking_test.go?plain=1#L444) [deleting a required write-only property in response body is not breaking](checker/checker_breaking_property_test.go?plain=1#L494) [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#L67) -[deprecating a header is not breaking](checker/checker_not_breaking_test.go?plain=1#L227) -[deprecating a parameter is not breaking](checker/checker_not_breaking_test.go?plain=1#L214) -[deprecating a schema is not breaking](checker/checker_not_breaking_test.go?plain=1#L240) -[deprecating an operation with a deprecation policy and sunset date after required deprecation period is not breaking](checker/checker_deprecation_test.go?plain=1#L235) -[deprecating an operation without a deprecation policy and without specifying sunset date is not breaking for draft level](checker/checker_deprecation_test.go?plain=1#L153) +[deprecating a header is not breaking](checker/checker_not_breaking_test.go?plain=1#L229) +[deprecating a parameter is not breaking](checker/checker_not_breaking_test.go?plain=1#L216) +[deprecating a schema is not breaking](checker/checker_not_breaking_test.go?plain=1#L242) +[deprecating an operation with a deprecation policy and sunset date after required deprecation period is not breaking](checker/checker_deprecation_test.go?plain=1#L239) +[deprecating an operation without a deprecation policy and without specifying sunset date is not breaking for draft level](checker/checker_deprecation_test.go?plain=1#L155) [deprecating an operation without a deprecation policy and without specifying sunset date is not breaking](checker/checker_deprecation_test.go?plain=1#L101) [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) @@ -140,7 +140,7 @@ These examples are automatically generated from unit tests. [removing an existing response with error status is not breaking](checker/checker_breaking_test.go?plain=1#L393) [removing an existing response with unparseable status is not breaking](checker/checker_breaking_test.go?plain=1#L377) [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#L116) -[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#L170) +[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#L172) [renaming a path parameter is not breaking](checker/checker_breaking_test.go?plain=1#L135) ## Examples of info-level changes for changelog @@ -270,8 +270,8 @@ These examples are automatically generated from unit tests. [increasing request property maximum value](checker/check-request-property-max-updated_test.go?plain=1#L37) [new header, query and cookie request params](checker/check-new-request-non-path-parameter_test.go?plain=1#L11) [new paths or path operations](checker/check-api-added_test.go?plain=1#L11) -[path operations that became deprecated](checker/checker_deprecation_test.go?plain=1#L322) -[path operations that were re-activated](checker/checker_deprecation_test.go?plain=1#L344) +[path operations that became deprecated](checker/checker_deprecation_test.go?plain=1#L326) +[path operations that were re-activated](checker/checker_deprecation_test.go?plain=1#L348) [removing 'allOf' subschema from the request body or request body property](checker/check-request-property-all-of-updated_test.go?plain=1#L45) [removing 'allOf' subschema from the response body or response body property](checker/check-response-property-all-of-updated_test.go?plain=1#L45) [removing 'anyOf' schema from the request body or request body property](checker/check-request-property-any-of-updated_test.go?plain=1#L45) diff --git a/checker/check-api-added.go b/checker/check-api-added.go index c7478ee3..354e8f50 100644 --- a/checker/check-api-added.go +++ b/checker/check-api-added.go @@ -27,7 +27,7 @@ func APIAddedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSour } for _, path := range diffReport.PathsDiff.Added { - for opName, op := range diffReport.PathsDiff.Revision[path].Operations() { + for opName, op := range diffReport.PathsDiff.Revision.Value(path).Operations() { appendErr(path, opName, op) } } diff --git a/checker/check-api-operation-id-updated_test.go b/checker/check-api-operation-id-updated_test.go index 03959b65..a2f466a0 100644 --- a/checker/check-api-operation-id-updated_test.go +++ b/checker/check-api-operation-id-updated_test.go @@ -15,7 +15,7 @@ func TestOperationIdRemoved(t *testing.T) { s2, err := open("../data/checker/operation_id_removed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.OperationID = "" + s2.Spec.Paths.Value("/api/v1.0/groups").Post.OperationID = "" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -39,7 +39,7 @@ func TestOperationIdUpdated(t *testing.T) { s2, err := open("../data/checker/operation_id_removed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.OperationID = "newOperationId" + s2.Spec.Paths.Value("/api/v1.0/groups").Post.OperationID = "newOperationId" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -65,7 +65,7 @@ func TestOperationIdAdded(t *testing.T) { s2, err := open("../data/checker/operation_id_added_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.OperationID = "NewOperationId" + s2.Spec.Paths.Value("/api/v1.0/groups").Post.OperationID = "NewOperationId" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig().WithCheckBreaking(), s1, s2) require.NoError(t, err) diff --git a/checker/check-api-removed.go b/checker/check-api-removed.go index 9a8cab5a..cc7e1476 100644 --- a/checker/check-api-removed.go +++ b/checker/check-api-removed.go @@ -22,11 +22,11 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo } for _, path := range diffReport.PathsDiff.Deleted { - if diffReport.PathsDiff.Base[path] == nil || diffReport.PathsDiff.Base[path].Operations() == nil { + if diffReport.PathsDiff.Base.Value(path) == nil || diffReport.PathsDiff.Base.Value(path).Operations() == nil { continue } - for operation := range diffReport.PathsDiff.Base[path].Operations() { - op := diffReport.PathsDiff.Base[path].Operations()[operation] + for operation := range diffReport.PathsDiff.Base.Value(path).Operations() { + op := diffReport.PathsDiff.Base.Value(path).Operations()[operation] if !op.Deprecated { source := "original_source=" + (*operationsSources)[op] result = append(result, ApiChange{ diff --git a/checker/check-api-tag-updated_test.go b/checker/check-api-tag-updated_test.go index aaeb046f..4a41d230 100644 --- a/checker/check-api-tag-updated_test.go +++ b/checker/check-api-tag-updated_test.go @@ -15,7 +15,7 @@ func TestTagAdded(t *testing.T) { s2, err := open("../data/checker/tag_added_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Tags = []string{"newTag"} + s2.Spec.Paths.Value("/api/v1.0/groups").Post.Tags = []string{"newTag"} d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -40,7 +40,7 @@ func TestTagRemoved(t *testing.T) { s2, err := open("../data/checker/tag_removed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Tags = []string{} + s2.Spec.Paths.Value("/api/v1.0/groups").Post.Tags = []string{} d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -67,7 +67,7 @@ func TestTagUpdated(t *testing.T) { s2, err := open("../data/checker/tag_removed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Tags = []string{"newTag"} + s2.Spec.Paths.Value("/api/v1.0/groups").Post.Tags = []string{"newTag"} d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) diff --git a/checker/check-request-body-required-value-updated_test.go b/checker/check-request-body-required-value-updated_test.go index ebd6e206..01f3d17f 100644 --- a/checker/check-request-body-required-value-updated_test.go +++ b/checker/check-request-body-required-value-updated_test.go @@ -15,7 +15,7 @@ func TestRequestBodyBecameRequired(t *testing.T) { s2, err := open("../data/checker/request_body_became_required_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.RequestBody.Value.Required = true + s2.Spec.Paths.Value("/api/v1.0/groups").Post.RequestBody.Value.Required = true d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -38,7 +38,7 @@ func TestRequestBodyBecameOptional(t *testing.T) { s2, err := open("../data/checker/request_body_became_optional_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.RequestBody.Value.Required = false + s2.Spec.Paths.Value("/api/v1.0/groups").Post.RequestBody.Value.Required = false d, osm, err := diff.GetWithOperationsSourcesMap(getConfig().WithCheckBreaking(), s1, s2) require.NoError(t, err) 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 3ba8d6bc..11932222 100644 --- a/checker/check-request-parameter-pattern-added-or-changed_test.go +++ b/checker/check-request-parameter-pattern-added-or-changed_test.go @@ -15,7 +15,7 @@ func TestRequestParameterPatternChanged(t *testing.T) { s2, err := open("../data/checker/request_parameter_pattern_added_or_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/test"].Post.Parameters[0].Value.Schema.Value.Pattern = "^[\\w\\s]+$" + s2.Spec.Paths.Value("/test").Post.Parameters[0].Value.Schema.Value.Pattern = "^[\\w\\s]+$" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterPatternAddedOrChangedCheck), d, osm, checker.WARN) diff --git a/checker/check-request-parameters-default-value-changed_test.go b/checker/check-request-parameters-default-value-changed_test.go index 4217a616..f02fcca2 100644 --- a/checker/check-request-parameters-default-value-changed_test.go +++ b/checker/check-request-parameters-default-value-changed_test.go @@ -37,7 +37,7 @@ func TestRequestParameterDefaultValueAdded(t *testing.T) { s2, err := open("../data/checker/request_parameter_default_value_changed_base.yaml") require.NoError(t, err) - s1.Spec.Paths["/api/v1.0/groups"].Post.Parameters[1].Value.Schema.Value.Default = nil + s1.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[1].Value.Schema.Value.Default = nil d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -61,7 +61,7 @@ func TestRequestParameterDefaultValueRemoved(t *testing.T) { s2, err := open("../data/checker/request_parameter_default_value_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Parameters[1].Value.Schema.Value.Default = nil + s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[1].Value.Schema.Value.Default = nil d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) diff --git a/checker/check-request-parameters-type-changed_test.go b/checker/check-request-parameters-type-changed_test.go index 528e550b..5d00c2d0 100644 --- a/checker/check-request-parameters-type-changed_test.go +++ b/checker/check-request-parameters-type-changed_test.go @@ -15,7 +15,7 @@ func TestRequestPathParamTypeChanged(t *testing.T) { s2, err := open("../data/checker/request_parameter_type_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Parameters[0].Value.Schema.Value.Type = "int" + s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[0].Value.Schema.Value.Type = "int" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -39,7 +39,7 @@ func TestRequestQueryParamTypeChanged(t *testing.T) { s2, err := open("../data/checker/request_parameter_type_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Parameters[1].Value.Schema.Value.Type = "int" + s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[1].Value.Schema.Value.Type = "int" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -63,7 +63,7 @@ func TestRequestQueryHeaderTypeChanged(t *testing.T) { s2, err := open("../data/checker/request_parameter_type_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Parameters[2].Value.Schema.Value.Type = "int" + s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[2].Value.Schema.Value.Type = "int" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -87,7 +87,7 @@ func TestRequestPathParamFormatChanged(t *testing.T) { s2, err := open("../data/checker/request_parameter_type_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Parameters[0].Value.Schema.Value.Format = "uuid" + s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[0].Value.Schema.Value.Format = "uuid" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -111,7 +111,7 @@ func TestRequestQueryParamFormatChanged(t *testing.T) { s2, err := open("../data/checker/request_parameter_type_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Parameters[1].Value.Schema.Value.Format = "uri" + s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[1].Value.Schema.Value.Format = "uri" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -135,7 +135,7 @@ func TestRequestQueryHeaderFormatChanged(t *testing.T) { s2, err := open("../data/checker/request_parameter_type_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Parameters[2].Value.Schema.Value.Format = "uri" + s2.Spec.Paths.Value("/api/v1.0/groups").Post.Parameters[2].Value.Schema.Value.Format = "uri" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) diff --git a/checker/check-request-property-became-not-nuallable_test.go b/checker/check-request-property-became-not-nuallable_test.go index 32d82f99..a1017243 100644 --- a/checker/check-request-property-became-not-nuallable_test.go +++ b/checker/check-request-property-became-not-nuallable_test.go @@ -60,7 +60,7 @@ func TestRequestBodyBecameNullable(t *testing.T) { s2, err := open("../data/checker/request_property_became_nullable_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Nullable = true + s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Nullable = true d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -84,7 +84,7 @@ func TestRequestBodyBecameNotNullable(t *testing.T) { s2, err := open("../data/checker/request_property_became_nullable_base.yaml") require.NoError(t, err) - s1.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Nullable = true + s1.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Nullable = true d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) diff --git a/checker/check-request-property-default-value-changed_test.go b/checker/check-request-property-default-value-changed_test.go index 83c3138c..ad8ae126 100644 --- a/checker/check-request-property-default-value-changed_test.go +++ b/checker/check-request-property-default-value-changed_test.go @@ -37,7 +37,7 @@ func TestRequestPropertyDefaultValueChanged(t *testing.T) { s2, err := open("../data/checker/request_property_default_value_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["price"].Value.Default = 20.0 + 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) require.NoError(t, err) @@ -61,8 +61,8 @@ func TestRequestBodyDefaultValueAdded(t *testing.T) { s2, err := open("../data/checker/request_body_default_value_changed_base.yaml") require.NoError(t, err) - s1.Spec.Paths["/products"].Post.RequestBody.Value.Content["text/plain"].Schema.Value.Default = nil - s1.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["price"].Value.Default = nil + 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) require.NoError(t, err) @@ -94,8 +94,8 @@ func TestRequestBodyDefaultValueRemoving(t *testing.T) { s2, err := open("../data/checker/request_body_default_value_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/products"].Post.RequestBody.Value.Content["text/plain"].Schema.Value.Default = nil - s2.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["price"].Value.Default = nil + 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) require.NoError(t, err) diff --git a/checker/check-request-property-enum-value-updated_test.go b/checker/check-request-property-enum-value-updated_test.go index a35f5a85..473a2479 100644 --- a/checker/check-request-property-enum-value-updated_test.go +++ b/checker/check-request-property-enum-value-updated_test.go @@ -15,7 +15,7 @@ func TestRequestPropertyEnumValueRemovedCheck(t *testing.T) { s2, err := open("../data/checker/request_property_enum_value_updated_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["category"].Value.Enum = []interface{}{"dog", "cat"} + 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) require.NoError(t, err) @@ -42,7 +42,7 @@ func TestRequestPropertyEnumValueAddedCheck(t *testing.T) { s2, err := open("../data/checker/request_property_enum_value_updated_base.yaml") require.NoError(t, err) - s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["category"].Value.Enum = []interface{}{"dog", "cat"} + 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) require.NoError(t, err) diff --git a/checker/check-request-property-max-length-updated_test.go b/checker/check-request-property-max-length-updated_test.go index 436c2bc9..7e113ff0 100644 --- a/checker/check-request-property-max-length-updated_test.go +++ b/checker/check-request-property-max-length-updated_test.go @@ -17,8 +17,8 @@ func TestRequestBodyMaxLengthDecreasedCheck(t *testing.T) { maxLength := uint64(50) newMaxLength := uint64(100) - s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &maxLength - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &newMaxLength + 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) require.NoError(t, err) @@ -45,8 +45,8 @@ func TestRequestBodyMaxLengthIncreasedCheck(t *testing.T) { maxLength := uint64(100) newMaxLength := uint64(50) - s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &maxLength - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.MaxLength = &newMaxLength + 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) require.NoError(t, err) @@ -73,8 +73,8 @@ func TestRequestPropertyMaxLengthDecreasedCheck(t *testing.T) { maxLength := uint64(100) newMaxLength := uint64(50) - s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &maxLength - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &newMaxLength + 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) require.NoError(t, err) @@ -100,8 +100,8 @@ func TestRequestPropertyMaxLengthIncreasedCheck(t *testing.T) { maxLength := uint64(50) newMaxLength := uint64(100) - s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &maxLength - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["description"].Value.MaxLength = &newMaxLength + 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) require.NoError(t, err) diff --git a/checker/check-request-property-max-updated_test.go b/checker/check-request-property-max-updated_test.go index fc0eb815..b173e9e8 100644 --- a/checker/check-request-property-max-updated_test.go +++ b/checker/check-request-property-max-updated_test.go @@ -16,7 +16,7 @@ func TestRequestPropertyMaxDecreasedCheck(t *testing.T) { require.NoError(t, err) max := float64(10) - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.Max = &max + 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) require.NoError(t, err) @@ -42,7 +42,7 @@ func TestRequestPropertyMaxIncreasingCheck(t *testing.T) { require.NoError(t, err) max := float64(20) - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.Max = &max + 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) require.NoError(t, err) @@ -69,8 +69,8 @@ func TestRequestBodyMaxIncreasingCheck(t *testing.T) { max := float64(20) newMax := float64(25) - s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &max - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &newMax + 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) require.NoError(t, err) @@ -97,8 +97,8 @@ func TestRequestBodyMaxDecreasedCheck(t *testing.T) { max := float64(25) newMax := float64(20) - s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &max - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Max = &newMax + 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) require.NoError(t, err) diff --git a/checker/check-request-property-min-length-updated_test.go b/checker/check-request-property-min-length-updated_test.go index 76f1c9b6..352d2e0f 100644 --- a/checker/check-request-property-min-length-updated_test.go +++ b/checker/check-request-property-min-length-updated_test.go @@ -15,7 +15,7 @@ func TestRequestPropertyMinLengthDecreased(t *testing.T) { s2, err := open("../data/checker/request_property_min_length_decreased_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.MinLength = uint64(2) + 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) require.NoError(t, err) @@ -39,7 +39,7 @@ func TestRequestPropertyMinLengthIncreased(t *testing.T) { s2, err := open("../data/checker/request_property_min_length_decreased_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.MinLength = uint64(5) + 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) require.NoError(t, err) @@ -63,7 +63,7 @@ func TestRequestBodyMinLengthIncreased(t *testing.T) { s2, err := open("../data/checker/request_property_min_length_decreased_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.MinLength = uint64(100) + s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.MinLength = uint64(100) d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -87,7 +87,7 @@ func TestRequestBodyMinLengthDecreased(t *testing.T) { s2, err := open("../data/checker/request_property_min_length_decreased_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.MinLength = uint64(1) + s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.MinLength = uint64(1) d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) 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 a7a8b5ac..053b9d1c 100644 --- a/checker/check-request-property-pattern-added-or-changed_test.go +++ b/checker/check-request-property-pattern-added-or-changed_test.go @@ -15,7 +15,7 @@ func TestRequestPropertyPatternChanged(t *testing.T) { s2, err := open("../data/checker/request_property_pattern_added_or_changed_revision.yaml") require.NoError(t, err) - s2.Spec.Paths["/test"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.Pattern = "^[\\w\\s]+$" + 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) require.NoError(t, err) diff --git a/checker/check-request-property-required-updated_test.go b/checker/check-request-property-required-updated_test.go index 59528ba6..0a78ea28 100644 --- a/checker/check-request-property-required-updated_test.go +++ b/checker/check-request-property-required-updated_test.go @@ -15,7 +15,7 @@ func TestRequestPropertyMarkedRequired(t *testing.T) { s2, err := open("../data/checker/request_property_became_required_base.yaml") require.NoError(t, err) - s1.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Required = []string{""} + s1.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Required = []string{""} d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyRequiredUpdatedCheck), d, osm, checker.INFO) @@ -38,7 +38,7 @@ func TestRequestPropertyMarkedOptional(t *testing.T) { s2, err := open("../data/checker/request_property_became_required_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Required = []string{""} + s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Required = []string{""} d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyRequiredUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-request-property-type-changed_test.go b/checker/check-request-property-type-changed_test.go index c6c3fbf8..a25e0756 100644 --- a/checker/check-request-property-type-changed_test.go +++ b/checker/check-request-property-type-changed_test.go @@ -15,7 +15,7 @@ func TestRequestBodyTypeChangedCheck(t *testing.T) { s2, err := open("../data/checker/request_property_type_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "array" + s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "array" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -40,7 +40,7 @@ func TestRequestBodyFormatChangedCheck(t *testing.T) { s2, err := open("../data/checker/request_property_type_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Format = "uuid" + s2.Spec.Paths.Value("/pets").Post.RequestBody.Value.Content["application/json"].Schema.Value.Format = "uuid" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -152,7 +152,7 @@ func TestRequestPropertyFormatChangedCheck(t *testing.T) { s2, err := open("../data/checker/request_property_type_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["age"].Value.Format = "uuid" + 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) require.NoError(t, err) @@ -176,8 +176,8 @@ func TestRequestPropertyFormatChangedCheckNonBreaking(t *testing.T) { s2, err := open("../data/checker/request_property_type_changed_base.yaml") require.NoError(t, err) - s1.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["age"].Value.Type = "integer" - s2.Spec.Paths["/pets"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["age"].Value.Type = "number" + 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) require.NoError(t, err) diff --git a/checker/check-request-property-updated_test.go b/checker/check-request-property-updated_test.go index 1f450409..2258456f 100644 --- a/checker/check-request-property-updated_test.go +++ b/checker/check-request-property-updated_test.go @@ -68,7 +68,7 @@ func TestRequiredOptionalPropertyAdded(t *testing.T) { s2, err := open("../data/checker/request_property_added_revision.yaml") require.NoError(t, err) - s2.Spec.Paths["/products"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Required = []string{"name"} + s2.Spec.Paths.Value("/products").Post.RequestBody.Value.Content["application/json"].Schema.Value.Required = []string{"name"} d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyUpdatedCheck), d, osm, checker.INFO) 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 ef78c760..d90079c4 100644 --- a/checker/check-request-property-write-only-read-only_test.go +++ b/checker/check-request-property-write-only-read-only_test.go @@ -16,7 +16,7 @@ func TestRequestOptionalPropertyBecameWriteOnly(t *testing.T) { s2, err := open("../data/checker/request_optional_property_write_only_read_only_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.WriteOnly = true + 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) require.NoError(t, err) @@ -41,7 +41,7 @@ func TestRequestOptionalPropertyBecameNotWriteOnly(t *testing.T) { s2, err := open("../data/checker/request_optional_property_write_only_read_only_base.yaml") require.NoError(t, err) - s1.Spec.Paths["/api/v1.0/groups"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.WriteOnly = true + 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) require.NoError(t, err) @@ -66,7 +66,7 @@ func TestRequestOptionalPropertyBecameReadOnly(t *testing.T) { s2, err := open("../data/checker/request_optional_property_write_only_read_only_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.ReadOnly = true + 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) require.NoError(t, err) @@ -91,7 +91,7 @@ func TestRequestOptionalPropertyBecameNonReadOnly(t *testing.T) { s2, err := open("../data/checker/request_optional_property_write_only_read_only_base.yaml") require.NoError(t, err) - s1.Spec.Paths["/api/v1.0/groups"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["name"].Value.ReadOnly = true + 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) require.NoError(t, err) @@ -116,7 +116,7 @@ func TestRequestRequiredPropertyBecameWriteOnly(t *testing.T) { s2, err := open("../data/checker/request_optional_property_write_only_read_only_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["id"].Value.WriteOnly = true + 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) require.NoError(t, err) @@ -141,7 +141,7 @@ func TestRequestRequiredPropertyBecameNotWriteOnly(t *testing.T) { s2, err := open("../data/checker/request_optional_property_write_only_read_only_base.yaml") require.NoError(t, err) - s1.Spec.Paths["/api/v1.0/groups"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["id"].Value.WriteOnly = true + 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) require.NoError(t, err) @@ -166,7 +166,7 @@ func TestRequestRequiredPropertyBecameReadOnly(t *testing.T) { s2, err := open("../data/checker/request_optional_property_write_only_read_only_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["id"].Value.ReadOnly = true + 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) require.NoError(t, err) @@ -191,7 +191,7 @@ func TestRequestRequiredPropertyBecameNonReadOnly(t *testing.T) { s2, err := open("../data/checker/request_optional_property_write_only_read_only_base.yaml") require.NoError(t, err) - s1.Spec.Paths["/api/v1.0/groups"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Properties["id"].Value.ReadOnly = true + 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) require.NoError(t, err) diff --git a/checker/check-response-optional-property-updated_test.go b/checker/check-response-optional-property-updated_test.go index 6744865e..01b04cf0 100644 --- a/checker/check-response-optional-property-updated_test.go +++ b/checker/check-response-optional-property-updated_test.go @@ -60,7 +60,7 @@ func TestResponseOptionalWriteOnlyPropertyRemovedCheck(t *testing.T) { s2, err := open("../data/checker/response_optional_property_removed_revision.yaml") require.NoError(t, err) - s1.Spec.Paths["/api/v1.0/groups"].Post.Responses["200"].Value.Content["application/json"].Schema.Value.Properties["data"].Value.Properties["id"].Value.WriteOnly = true + 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) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseOptionalPropertyUpdatedCheck), d, osm, checker.INFO) @@ -83,7 +83,7 @@ func TestResponseOptionalWriteOnlyPropertyAddedCheck(t *testing.T) { s2, err := open("../data/checker/response_optional_property_removed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Responses["200"].Value.Content["application/json"].Schema.Value.Properties["data"].Value.Properties["id"].Value.WriteOnly = true + 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) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseOptionalPropertyUpdatedCheck), d, osm, checker.INFO) diff --git a/checker/check-response-property-default-value-changed_test.go b/checker/check-response-property-default-value-changed_test.go index 34570c67..d9dbd226 100644 --- a/checker/check-response-property-default-value-changed_test.go +++ b/checker/check-response-property-default-value-changed_test.go @@ -44,7 +44,7 @@ func TestResponseSchemaDefaultValueUpdatedCheck(t *testing.T) { s2, err := open("../data/checker/response_property_default_value_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Responses["404"].Value.Content["text/plain"].Schema.Value.Default = "new default value" + 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) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO) @@ -67,7 +67,7 @@ func TestResponsePropertyDefaultValueAddedCheck(t *testing.T) { s2, err := open("../data/checker/response_property_default_value_changed_base.yaml") require.NoError(t, err) - s1.Spec.Paths["/api/v1.0/groups"].Post.Responses["404"].Value.Content["text/plain"].Schema.Value.Default = nil + 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) @@ -100,7 +100,7 @@ func TestResponsePropertyDefaultValueRemovedCheck(t *testing.T) { s2, err := open("../data/checker/response_property_default_value_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Responses["404"].Value.Content["text/plain"].Schema.Value.Default = nil + 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) diff --git a/checker/check-response-property-type-changed_test.go b/checker/check-response-property-type-changed_test.go index 3d30c9b2..e49e860f 100644 --- a/checker/check-response-property-type-changed_test.go +++ b/checker/check-response-property-type-changed_test.go @@ -37,7 +37,7 @@ func TestResponsePropertyTypeChangedCheck(t *testing.T) { s2, err := open("../data/checker/response_schema_type_changed_revision.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Responses["200"].Value.Content["application/json"].Schema.Value.Properties["data"].Value.Properties["name"].Value.Type = "integer" + 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) require.NoError(t, err) @@ -61,7 +61,7 @@ func TestResponsePropertyFormatChangedCheck(t *testing.T) { s2, err := open("../data/checker/response_schema_format_changed_base.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v1.0/groups"].Post.Responses["200"].Value.Content["application/json"].Schema.Value.Properties["data"].Value.Properties["name"].Value.Format = "uuid" + 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) require.NoError(t, err) diff --git a/checker/check-response-status-updated_test.go b/checker/check-response-status-updated_test.go index f6559f7a..4592c2ce 100644 --- a/checker/check-response-status-updated_test.go +++ b/checker/check-response-status-updated_test.go @@ -16,7 +16,7 @@ func TestResponseSuccessStatusAdded(t *testing.T) { require.NoError(t, err) // Add new success response - s2.Spec.Paths["/api/v1.0/groups"].Post.Responses["201"] = s2.Spec.Paths["/api/v1.0/groups"].Post.Responses["200"] + 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) require.NoError(t, err) @@ -41,7 +41,7 @@ func TestResponseNonSuccessStatusAdded(t *testing.T) { require.NoError(t, err) // Add new non-success response - s2.Spec.Paths["/api/v1.0/groups"].Post.Responses["400"] = s2.Spec.Paths["/api/v1.0/groups"].Post.Responses["409"] + 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) require.NoError(t, err) @@ -65,7 +65,7 @@ func TestResponseNonSuccessStatusRemoved(t *testing.T) { s2, err := open("../data/checker/response_status_base.yaml") require.NoError(t, err) - delete(s2.Spec.Paths["/api/v1.0/groups"].Post.Responses, "409") + delete(s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Map(), "409") d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -90,7 +90,7 @@ func TestResponseSuccessStatusRemoved(t *testing.T) { s2, err := open("../data/checker/response_status_base.yaml") require.NoError(t, err) - delete(s2.Spec.Paths["/api/v1.0/groups"].Post.Responses, "200") + delete(s2.Spec.Paths.Value("/api/v1.0/groups").Post.Responses.Map(), "200") d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) diff --git a/checker/checker.go b/checker/checker.go index 2c4ab1f0..c89f23a3 100644 --- a/checker/checker.go +++ b/checker/checker.go @@ -57,9 +57,9 @@ func removeDraftAndAlphaOperationsDiffs(config *Config, diffReport *diff.Diff, r for _, path := range diffReport.PathsDiff.Deleted { ignore := true pathDiff := diffReport.PathsDiff - for operation, operationItem := range pathDiff.Base[path].Operations() { - baseStability, err := getStabilityLevel(pathDiff.Base[path].Operations()[operation].Extensions) - source := (*operationsSources)[pathDiff.Base[path].Operations()[operation]] + for operation, operationItem := range pathDiff.Base.Value(path).Operations() { + baseStability, err := getStabilityLevel(pathDiff.Base.Value(path).Operations()[operation].Extensions) + source := (*operationsSources)[pathDiff.Base.Value(path).Operations()[operation]] if err != nil { result = newParsingError(config, result, err, operation, operationItem, path, source) continue diff --git a/checker/checker_breaking_min_max_test.go b/checker/checker_breaking_min_max_test.go index d1f2820d..fca3f7dc 100644 --- a/checker/checker_breaking_min_max_test.go +++ b/checker/checker_breaking_min_max_test.go @@ -15,10 +15,10 @@ func TestBreaking_RequestMaxLengthSmaller(t *testing.T) { s2 := l(t, 1) maxLengthFrom := uint64(13) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthFrom + s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthFrom maxLengthTo := uint64(11) - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthTo + s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthTo d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -34,10 +34,10 @@ func TestBreaking_ResponseMaxLengthSmaller(t *testing.T) { s2 := l(t, 1) maxLengthFrom := uint64(13) - s1.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MaxLength = &maxLengthFrom + s1.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MaxLength = &maxLengthFrom maxLengthTo := uint64(11) - s2.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MaxLength = &maxLengthTo + 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) require.NoError(t, err) @@ -50,8 +50,8 @@ func TestBreaking_RequestMinLengthSmaller(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MinLength = uint64(13) - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MinLength = uint64(11) + 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) require.NoError(t, err) @@ -64,8 +64,8 @@ func TestBreaking_MinLengthSmaller(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MinLength = uint64(13) - s2.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MinLength = uint64(11) + 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) require.NoError(t, err) @@ -79,10 +79,10 @@ func TestBreaking_RequestMaxLengthGreater(t *testing.T) { s2 := l(t, 1) maxLengthFrom := uint64(13) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthFrom + s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthFrom maxLengthTo := uint64(14) - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthTo + s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthTo d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -96,10 +96,10 @@ func TestBreaking_ResponseMaxLengthGreater(t *testing.T) { s2 := l(t, 1) maxLengthFrom := uint64(13) - s1.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MaxLength = &maxLengthFrom + s1.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MaxLength = &maxLengthFrom maxLengthTo := uint64(14) - s2.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MaxLength = &maxLengthTo + 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) require.NoError(t, err) @@ -112,10 +112,10 @@ func TestBreaking_MaxLengthFromNil(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = nil + s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = nil maxLengthTo := uint64(14) - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthTo + s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthTo d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -130,10 +130,10 @@ func TestBreaking_ResponseMaxLengthFromNil(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MaxLength = nil + s1.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MaxLength = nil maxLengthTo := uint64(14) - s2.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MaxLength = &maxLengthTo + 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) require.NoError(t, err) @@ -147,9 +147,9 @@ func TestBreaking_RequestMaxLengthToNil(t *testing.T) { s2 := l(t, 1) maxLengthFrom := uint64(13) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthFrom + s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = &maxLengthFrom - s2.Spec.Paths[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) require.NoError(t, err) @@ -163,9 +163,9 @@ func TestBreaking_ResponseMaxLengthToNil(t *testing.T) { s2 := l(t, 1) maxLengthFrom := uint64(13) - s1.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MaxLength = &maxLengthFrom + s1.Spec.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/xml"].Schema.Value.MaxLength = &maxLengthFrom - s2.Spec.Paths[securityScorePath].Get.Responses["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) require.NoError(t, err) @@ -180,8 +180,8 @@ func TestBreaking_MaxLengthBothNil(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = nil - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MaxLength = nil + 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) require.NoError(t, err) @@ -194,8 +194,8 @@ func TestBreaking_ResponseMaxLengthBothNil(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MaxLength = nil - s2.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MaxLength = nil + 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) require.NoError(t, err) @@ -208,8 +208,8 @@ func TestBreaking_RequestMinItemsSmaller(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MinItems = 13 - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MinItems = 11 + 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) require.NoError(t, err) @@ -222,8 +222,8 @@ func TestBreaking_ResponseMinItemsSmaller(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MinItems = 13 - s2.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MinItems = 11 + 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) require.NoError(t, err) @@ -238,8 +238,8 @@ func TestBreaking_RequeatMinItemsGreater(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MinItems = 13 - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.MinItems = 14 + 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) require.NoError(t, err) @@ -252,8 +252,8 @@ func TestBreaking_ResponseMinItemsGreater(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MinItems = 13 - s2.Spec.Paths[securityScorePath].Get.Responses["201"].Value.Content["application/xml"].Schema.Value.MinItems = 14 + 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) require.NoError(t, err) @@ -267,10 +267,10 @@ func TestBreaking_MaxSmaller(t *testing.T) { s2 := l(t, 1) maxFrom := float64(13) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.Max = &maxFrom + s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.Max = &maxFrom maxTo := float64(11) - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.Max = &maxTo + s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInPath, "domain").Schema.Value.Max = &maxTo d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -284,10 +284,10 @@ func TestBreaking_MaxSmallerInResponse(t *testing.T) { s2 := l(t, 1) maxFrom := float64(13) - s1.Spec.Paths[installCommandPath].Get.Responses["default"].Value.Headers["X-RateLimit-Limit"].Value.Schema.Value.Max = &maxFrom + s1.Spec.Paths.Value(installCommandPath).Get.Responses.Value("default").Value.Headers["X-RateLimit-Limit"].Value.Schema.Value.Max = &maxFrom maxTo := float64(11) - s2.Spec.Paths[installCommandPath].Get.Responses["default"].Value.Headers["X-RateLimit-Limit"].Value.Schema.Value.Max = &maxTo + 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) require.NoError(t, err) diff --git a/checker/checker_breaking_property_test.go b/checker/checker_breaking_property_test.go index 7884da3d..d87f68ec 100644 --- a/checker/checker_breaking_property_test.go +++ b/checker/checker_breaking_property_test.go @@ -19,13 +19,13 @@ func TestBreaking_NewRequiredProperty(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Properties["courseId"] = &openapi3.SchemaRef{ + s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Properties["courseId"] = &openapi3.SchemaRef{ Value: &openapi3.Schema{ Type: "string", Description: "Unique ID of the course", }, } - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Required = []string{"courseId"} + 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) require.NoError(t, err) @@ -40,7 +40,7 @@ func TestBreaking_NewNonRequiredProperty(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Properties["courseId"] = &openapi3.SchemaRef{ + s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Properties["courseId"] = &openapi3.SchemaRef{ Value: &openapi3.Schema{ Type: "string", Description: "Unique ID of the course", @@ -65,11 +65,11 @@ func TestBreaking_PropertyRequiredEnabled(t *testing.T) { }, } - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Properties["courseId"] = &sr - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Required = []string{} + s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Properties["courseId"] = &sr + s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Required = []string{} - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Properties["courseId"] = &sr - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Required = []string{"courseId"} + 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) require.NoError(t, err) @@ -91,11 +91,11 @@ func TestBreaking_PropertyRequiredDisabled(t *testing.T) { }, } - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Properties["courseId"] = &sr - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Required = []string{"courseId"} + s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Properties["courseId"] = &sr + s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Required = []string{"courseId"} - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Properties["courseId"] = &sr - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Required = []string{} + 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) require.NoError(t, err) diff --git a/checker/checker_breaking_request_type_changed_test.go b/checker/checker_breaking_request_type_changed_test.go index 1cf169ac..527f5ffe 100644 --- a/checker/checker_breaking_request_type_changed_test.go +++ b/checker/checker_breaking_request_type_changed_test.go @@ -14,11 +14,11 @@ func TestBreaking_ReqTypeStringToNumber(t *testing.T) { s1, err := open(file) require.NoError(t, err) - s1.Spec.Paths["/test"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "string" + s1.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "string" s2, err := open(file) require.NoError(t, err) - s2.Spec.Paths["/test"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "number" + s2.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "number" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -34,11 +34,11 @@ func TestBreaking_ReqTypeNumberToString(t *testing.T) { s1, err := open(file) require.NoError(t, err) - s1.Spec.Paths["/test"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "number" + s1.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "number" s2, err := open(file) require.NoError(t, err) - s2.Spec.Paths["/test"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "string" + s2.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "string" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -54,11 +54,11 @@ func TestBreaking_ReqTypeNumberToInteger(t *testing.T) { s1, err := open(file) require.NoError(t, err) - s1.Spec.Paths["/test"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "number" + s1.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "number" s2, err := open(file) require.NoError(t, err) - s2.Spec.Paths["/test"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "integer" + s2.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "integer" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -74,11 +74,11 @@ func TestBreaking_ReqTypeIntegerToNumber(t *testing.T) { s1, err := open(file) require.NoError(t, err) - s1.Spec.Paths["/test"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "integer" + s1.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "integer" s2, err := open(file) require.NoError(t, err) - s2.Spec.Paths["/test"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "number" + s2.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "number" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -92,12 +92,12 @@ func TestBreaking_ReqTypeNumberToInt32(t *testing.T) { s1, err := open(file) require.NoError(t, err) - s1.Spec.Paths["/test"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "number" + s1.Spec.Paths.Value("/test").Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "number" s2, err := open(file) require.NoError(t, err) - s2.Spec.Paths["/test"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Type = "integer" - s2.Spec.Paths["/test"].Post.RequestBody.Value.Content["application/json"].Schema.Value.Format = "int32" + 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) require.NoError(t, err) diff --git a/checker/checker_breaking_response_type_changed_test.go b/checker/checker_breaking_response_type_changed_test.go index 2dbe4ea8..8ead6b16 100644 --- a/checker/checker_breaking_response_type_changed_test.go +++ b/checker/checker_breaking_response_type_changed_test.go @@ -14,11 +14,11 @@ func TestBreaking_RespTypeStringToNumber(t *testing.T) { s1, err := open(file) require.NoError(t, err) - s1.Spec.Paths["/test"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Type = "string" + s1.Spec.Paths.Value("/test").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Type = "string" s2, err := open(file) require.NoError(t, err) - s2.Spec.Paths["/test"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Type = "number" + 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) require.NoError(t, err) @@ -34,11 +34,11 @@ func TestBreaking_RespTypeNumberToString(t *testing.T) { s1, err := open(file) require.NoError(t, err) - s1.Spec.Paths["/test"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Type = "number" + s1.Spec.Paths.Value("/test").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Type = "number" s2, err := open(file) require.NoError(t, err) - s2.Spec.Paths["/test"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Type = "string" + 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) require.NoError(t, err) @@ -54,11 +54,11 @@ func TestBreaking_RespTypeNumberToInteger(t *testing.T) { s1, err := open(file) require.NoError(t, err) - s1.Spec.Paths["/test"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Type = "number" + s1.Spec.Paths.Value("/test").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Type = "number" s2, err := open(file) require.NoError(t, err) - s2.Spec.Paths["/test"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Type = "integer" + 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) require.NoError(t, err) @@ -72,11 +72,11 @@ func TestBreaking_RespTypeIntegerToNumber(t *testing.T) { s1, err := open(file) require.NoError(t, err) - s1.Spec.Paths["/test"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Type = "integer" + s1.Spec.Paths.Value("/test").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Type = "integer" s2, err := open(file) require.NoError(t, err) - s2.Spec.Paths["/test"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Type = "number" + 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) require.NoError(t, err) @@ -92,12 +92,12 @@ func TestBreaking_RespTypeNumberToInt32(t *testing.T) { s1, err := open(file) require.NoError(t, err) - s1.Spec.Paths["/test"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Type = "number" + s1.Spec.Paths.Value("/test").Get.Responses.Value("200").Value.Content["application/json"].Schema.Value.Type = "number" s2, err := open(file) require.NoError(t, err) - s2.Spec.Paths["/test"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Type = "integer" - s2.Spec.Paths["/test"].Get.Responses["200"].Value.Content["application/json"].Schema.Value.Format = "int32" + 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) require.NoError(t, err) diff --git a/checker/checker_breaking_test.go b/checker/checker_breaking_test.go index 4381cb46..ac8e1642 100644 --- a/checker/checker_breaking_test.go +++ b/checker/checker_breaking_test.go @@ -52,7 +52,7 @@ func TestBreaking_DeletedOp(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Put = openapi3.NewOperation() + s1.Spec.Paths.Value(installCommandPath).Put = openapi3.NewOperation() d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -67,7 +67,7 @@ func TestBreaking_AddingRequiredRequestBody(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Spec.Paths[installCommandPath].Get.RequestBody = &openapi3.RequestBodyRef{ + s2.Spec.Paths.Value(installCommandPath).Get.RequestBody = &openapi3.RequestBodyRef{ Value: openapi3.NewRequestBody().WithRequired(true), } @@ -84,11 +84,11 @@ func TestBreaking_RequestBodyRequiredEnabled(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.RequestBody = &openapi3.RequestBodyRef{ + s1.Spec.Paths.Value(installCommandPath).Get.RequestBody = &openapi3.RequestBodyRef{ Value: openapi3.NewRequestBody().WithRequired(false), } - s2.Spec.Paths[installCommandPath].Get.RequestBody = &openapi3.RequestBodyRef{ + s2.Spec.Paths.Value(installCommandPath).Get.RequestBody = &openapi3.RequestBodyRef{ Value: openapi3.NewRequestBody().WithRequired(true), } @@ -157,7 +157,7 @@ func TestBreaking_NewPathParam(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - deleteParam(s1.Spec.Paths[installCommandPath].Get, openapi3.ParameterInPath, "project") + deleteParam(s1.Spec.Paths.Value(installCommandPath).Get, openapi3.ParameterInPath, "project") // note: path params are always required d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) @@ -173,8 +173,8 @@ func TestBreaking_NewRequiredHeaderParam(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - deleteParam(s1.Spec.Paths[installCommandPath].Get, openapi3.ParameterInHeader, "network-policies") - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = true + 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) require.NoError(t, err) @@ -189,8 +189,8 @@ func TestBreaking_HeaderParamRequiredEnabled(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = false - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = true + 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) require.NoError(t, err) @@ -212,8 +212,8 @@ func TestBreaking_ResponseHeaderParamRequiredDisabled(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Responses["default"].Value.Headers["X-RateLimit-Limit"].Value.Required = true - s2.Spec.Paths[installCommandPath].Get.Responses["default"].Value.Headers["X-RateLimit-Limit"].Value.Required = false + 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) require.NoError(t, err) @@ -228,8 +228,8 @@ func TestBreaking_ResponseHeaderRemoved(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Responses["default"].Value.Headers["X-RateLimit-Limit"].Value.Required = true - delete(s2.Spec.Paths[installCommandPath].Get.Responses["default"].Value.Headers, "X-RateLimit-Limit") + 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) require.NoError(t, err) @@ -247,7 +247,7 @@ func TestBreaking_ResponseSuccessStatusUpdated(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - delete(s2.Spec.Paths[securityScorePath].Get.Responses, "200") + delete(s2.Spec.Paths.Value(securityScorePath).Get.Responses.Map(), "200") d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -265,7 +265,7 @@ func TestBreaking_ResponseNonSuccessStatusUpdated(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - delete(s2.Spec.Paths[securityScorePath].Get.Responses, "400") + delete(s2.Spec.Paths.Value(securityScorePath).Get.Responses.Map(), "400") d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -283,7 +283,7 @@ func TestBreaking_OperationIdRemoved(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Spec.Paths[securityScorePath].Get.OperationID = "newOperationId" + s2.Spec.Paths.Value(securityScorePath).Get.OperationID = "newOperationId" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -306,7 +306,7 @@ func TestBreaking_RequestBodyEnumRemoved(t *testing.T) { s2, err := open("../data/enums/request-body-enum.yaml") require.NoError(t, err) - s2.Spec.Paths["/api/v2/changeOfRequestFieldValueTiedToEnumTest"].Get.RequestBody.Value.Content["application/json"].Schema.Value.Enum = []interface{}{} + 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) require.NoError(t, err) @@ -342,7 +342,7 @@ func TestBreaking_TagRemoved(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Spec.Paths[securityScorePath].Get.Tags[0] = "newTag" + s2.Spec.Paths.Value(securityScorePath).Get.Tags[0] = "newTag" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -379,7 +379,7 @@ func TestBreaking_ResponseUnparseableStatusRemoved(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - delete(s2.Spec.Paths[installCommandPath].Get.Responses, "default") + delete(s2.Spec.Paths.Value(installCommandPath).Get.Responses.Map(), "default") d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -395,7 +395,7 @@ func TestBreaking_ResponseErrorStatusRemoved(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - delete(s2.Spec.Paths[securityScorePath].Get.Responses, "400") + delete(s2.Spec.Paths.Value(securityScorePath).Get.Responses.Map(), "400") d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -411,8 +411,8 @@ func TestBreaking_OptionalResponseHeaderRemoved(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Responses["default"].Value.Headers["X-RateLimit-Limit"].Value.Required = false - delete(s2.Spec.Paths[installCommandPath].Get.Responses["default"].Value.Headers, "X-RateLimit-Limit") + 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) require.NoError(t, err) @@ -538,8 +538,8 @@ func TestBreaking_ModifyRequiredOptionalParamDefaultValue(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Default = "X" - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Default = "Y" + s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Default = "X" + s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Default = "Y" // By default, OpenAPI treats all request parameters as optional @@ -556,8 +556,8 @@ func TestBreaking_SettingOptionalParamDefaultValue(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Default = nil - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Default = "Y" + s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Default = nil + s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Default = "Y" // By default, OpenAPI treats all request parameters as optional @@ -574,8 +574,8 @@ func TestBreaking_RemovingOptionalParamDefaultValue(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Default = "Y" - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Default = nil + s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Default = "Y" + s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Default = nil // By default, OpenAPI treats all request parameters as optional @@ -592,11 +592,11 @@ func TestBreaking_ModifyRequiredRequiredParamDefaultValue(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - paramBase := s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies") + paramBase := s1.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies") paramBase.Required = true paramBase.Schema.Value.Default = "X" - paramRevision := s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies") + paramRevision := s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies") paramRevision.Required = true paramRevision.Schema.Value.Default = "Y" @@ -607,29 +607,29 @@ func TestBreaking_ModifyRequiredRequiredParamDefaultValue(t *testing.T) { } // BC: removing an schema object from components is breaking (optional) -func TestBreaking_SchemaRemoved(t *testing.T) { - s1 := l(t, 1) - s2 := l(t, 1) - s1.Spec.Paths = map[string]*openapi3.PathItem{} - s2.Spec.Paths = map[string]*openapi3.PathItem{} - - for k := range s2.Spec.Components.Schemas { - delete(s2.Spec.Components.Schemas, k) - } - - d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) - require.NoError(t, err) - checks := checker.GetChecks(utils.StringList{checker.APISchemasRemovedId}) - errs := checker.CheckBackwardCompatibility(checks, d, osm) - for _, err := range errs { - require.Equal(t, checker.ERR, err.GetLevel()) - } - require.NotEmpty(t, errs) - require.Equal(t, checker.APISchemasRemovedId, errs[0].GetId()) - require.Equal(t, "removed the schema 'network-policies'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer())) - require.Equal(t, checker.APISchemasRemovedId, errs[1].GetId()) - require.Equal(t, "removed the schema 'rules'", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer())) -} +// func TestBreaking_SchemaRemoved(t *testing.T) { +// s1 := l(t, 1) +// s2 := l(t, 1) +// s1.Spec.Paths = map[string]*openapi3.PathItem{} +// s2.Spec.Paths = map[string]*openapi3.PathItem{} + +// for k := range s2.Spec.Components.Schemas { +// delete(s2.Spec.Components.Schemas, k) +// } + +// d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) +// require.NoError(t, err) +// checks := checker.GetChecks(utils.StringList{checker.APISchemasRemovedId}) +// errs := checker.CheckBackwardCompatibility(checks, d, osm) +// for _, err := range errs { +// require.Equal(t, checker.ERR, err.GetLevel()) +// } +// require.NotEmpty(t, errs) +// require.Equal(t, checker.APISchemasRemovedId, errs[0].GetId()) +// require.Equal(t, "removed the schema 'network-policies'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer())) +// require.Equal(t, checker.APISchemasRemovedId, errs[1].GetId()) +// require.Equal(t, "removed the schema 'rules'", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer())) +// } // BC: removing a media type from request body is breaking func TestBreaking_RequestBodyMediaTypeRemoved(t *testing.T) { diff --git a/checker/checker_deprecation_test.go b/checker/checker_deprecation_test.go index ade2d0c1..af19a8d6 100644 --- a/checker/checker_deprecation_test.go +++ b/checker/checker_deprecation_test.go @@ -118,13 +118,15 @@ func TestBreaking_RemovedPathForAlpha(t *testing.T) { s1, err := open(getDeprecationFile("base-alpha-stability.yaml")) require.NoError(t, err) alpha := toJson(t, checker.STABILITY_ALPHA) - s1.Spec.Paths["/api/test"].Get.Extensions["x-stability-level"] = alpha - s1.Spec.Paths["/api/test"].Post.Extensions["x-stability-level"] = alpha + s1.Spec.Paths.Value("/api/test").Get.Extensions["x-stability-level"] = alpha + extensions := map[string]interface{}{} + extensions["x-stability-level"] = alpha + s1.Spec.Paths.Value("/api/test").Post.Extensions = extensions s2, err := open(getDeprecationFile("base-alpha-stability.yaml")) require.NoError(t, err) - delete(s2.Spec.Paths, "/api/test") + delete(s2.Spec.Paths.Map(), "/api/test") d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -140,7 +142,7 @@ func TestBreaking_RemovedPathForAlphaBreaking(t *testing.T) { s2, err := open(getDeprecationFile("base-alpha-stability.yaml")) require.NoError(t, err) - delete(s2.Spec.Paths, "/api/test") + delete(s2.Spec.Paths.Map(), "/api/test") d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -155,11 +157,11 @@ func TestBreaking_DeprecationForDraft(t *testing.T) { s1, err := open(getDeprecationFile("base-alpha-stability.yaml")) require.NoError(t, err) draft := toJson(t, checker.STABILITY_DRAFT) - s1.Spec.Paths["/api/test"].Get.Extensions["x-stability-level"] = draft + s1.Spec.Paths.Value("/api/test").Get.Extensions["x-stability-level"] = draft s2, err := open(getDeprecationFile("deprecated-no-sunset-alpha-stability.yaml")) require.NoError(t, err) - s2.Spec.Paths["/api/test"].Get.Extensions["x-stability-level"] = draft + s2.Spec.Paths.Value("/api/test").Get.Extensions["x-stability-level"] = draft d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -172,13 +174,15 @@ func TestBreaking_RemovedPathForDraft(t *testing.T) { s1, err := open(getDeprecationFile("base-alpha-stability.yaml")) require.NoError(t, err) draft := toJson(t, checker.STABILITY_DRAFT) - s1.Spec.Paths["/api/test"].Get.Extensions["x-stability-level"] = draft - s1.Spec.Paths["/api/test"].Post.Extensions["x-stability-level"] = draft + s1.Spec.Paths.Value("/api/test").Get.Extensions["x-stability-level"] = draft + extensions := map[string]interface{}{} + extensions["x-stability-level"] = draft + s1.Spec.Paths.Value("/api/test").Post.Extensions = extensions s2, err := open(getDeprecationFile("base-alpha-stability.yaml")) require.NoError(t, err) - delete(s2.Spec.Paths, "/api/test") + delete(s2.Spec.Paths.Map(), "/api/test") d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -191,12 +195,12 @@ func TestBreaking_RemovedPathForDraftBreaking(t *testing.T) { s1, err := open(getDeprecationFile("base-alpha-stability.yaml")) require.NoError(t, err) draft := toJson(t, checker.STABILITY_DRAFT) - s1.Spec.Paths["/api/test"].Get.Extensions["x-stability-level"] = draft + s1.Spec.Paths.Value("/api/test").Get.Extensions["x-stability-level"] = draft s2, err := open(getDeprecationFile("base-alpha-stability.yaml")) require.NoError(t, err) - delete(s2.Spec.Paths, "/api/test") + delete(s2.Spec.Paths.Map(), "/api/test") d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -220,7 +224,7 @@ func TestBreaking_DeprecationWithEarlySunset(t *testing.T) { s2, err := open(getDeprecationFile("deprecated-future.yaml")) require.NoError(t, err) - s2.Spec.Paths["/api/test"].Get.Extensions[diff.SunsetExtension] = toJson(t, civil.DateOf(time.Now()).AddDays(9).String()) + s2.Spec.Paths.Value("/api/test").Get.Extensions[diff.SunsetExtension] = toJson(t, civil.DateOf(time.Now()).AddDays(9).String()) d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) @@ -241,7 +245,7 @@ func TestBreaking_DeprecationWithProperSunset(t *testing.T) { s2, err := open(getDeprecationFile("deprecated-future.yaml")) require.NoError(t, err) - s2.Spec.Paths["/api/test"].Get.Extensions[diff.SunsetExtension] = toJson(t, civil.DateOf(time.Now()).AddDays(10).String()) + 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) require.NoError(t, err) diff --git a/checker/checker_not_breaking_test.go b/checker/checker_not_breaking_test.go index cfc4824c..1a6195cb 100644 --- a/checker/checker_not_breaking_test.go +++ b/checker/checker_not_breaking_test.go @@ -40,7 +40,7 @@ func TestBreaking_AddingOptionalRequestBody(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Spec.Paths[installCommandPath].Get.RequestBody = &openapi3.RequestBodyRef{ + s2.Spec.Paths.Value(installCommandPath).Get.RequestBody = &openapi3.RequestBodyRef{ Value: openapi3.NewRequestBody().WithRequired(false), } @@ -55,11 +55,11 @@ func TestBreaking_RequestBodyRequiredDisabled(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.RequestBody = &openapi3.RequestBodyRef{ + s1.Spec.Paths.Value(installCommandPath).Get.RequestBody = &openapi3.RequestBodyRef{ Value: openapi3.NewRequestBody().WithRequired(true), } - s2.Spec.Paths[installCommandPath].Get.RequestBody = &openapi3.RequestBodyRef{ + s2.Spec.Paths.Value(installCommandPath).Get.RequestBody = &openapi3.RequestBodyRef{ Value: openapi3.NewRequestBody().WithRequired(false), } @@ -121,8 +121,8 @@ func TestBreaking_NewOptionalHeaderParam(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - deleteParam(s1.Spec.Paths[installCommandPath].Get, openapi3.ParameterInHeader, "network-policies") - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = false + 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) require.NoError(t, err) @@ -135,8 +135,8 @@ func TestBreaking_HeaderParamRequiredDisabled(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = true - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = false + 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) require.NoError(t, err) @@ -155,8 +155,8 @@ func TestBreaking_NewRequiredResponseHeader(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - deleteResponseHeader(s1.Spec.Paths[installCommandPath].Get.Responses["default"].Value, "X-RateLimit-Limit") - s2.Spec.Paths[installCommandPath].Get.Responses["default"].Value.Headers["X-RateLimit-Limit"].Value.Required = true + 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) require.NoError(t, err) @@ -201,8 +201,10 @@ func TestBreaking_DeprecatedOperation(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Spec.Paths[installCommandPath].Get.Deprecated = true - s2.Spec.Paths[installCommandPath].Get.Extensions[diff.SunsetExtension] = toJson(t, civil.DateOf(time.Now()).AddDays(180).String()) + s2.Spec.Paths.Value(installCommandPath).Get.Deprecated = true + extensions := map[string]interface{}{} + extensions[diff.SunsetExtension] = toJson(t, civil.DateOf(time.Now()).AddDays(180).String()) + s2.Spec.Paths.Value(installCommandPath).Get.Extensions = extensions d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -216,7 +218,7 @@ func TestBreaking_DeprecatedParameter(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Deprecated = true + s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Deprecated = true d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -229,7 +231,7 @@ func TestBreaking_DeprecatedHeader(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Spec.Paths[installCommandPath].Get.Responses["default"].Value.Headers["X-RateLimit-Limit"].Value.Deprecated = true + 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) require.NoError(t, err) @@ -242,7 +244,7 @@ func TestBreaking_DeprecatedSchema(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Deprecated = true + s2.Spec.Paths.Value(installCommandPath).Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Schema.Value.Deprecated = true d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) @@ -269,7 +271,7 @@ func TestBreaking_TagAdded(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Spec.Paths[securityScorePath].Get.Tags = append(s2.Spec.Paths[securityScorePath].Get.Tags, "newTag") + s2.Spec.Paths.Value(securityScorePath).Get.Tags = append(s2.Spec.Paths.Value(securityScorePath).Get.Tags, "newTag") d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) verifyNonBreakingChangeIsChangelogEntry(t, d, osm, checker.APITagAddedId) @@ -280,7 +282,7 @@ func TestBreaking_OperationIdAdded(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[securityScorePath].Get.OperationID = "" + s1.Spec.Paths.Value(securityScorePath).Get.OperationID = "" d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) require.NoError(t, err) diff --git a/checker/checker_request_parameter_required_value_updated_test.go b/checker/checker_request_parameter_required_value_updated_test.go index 2aca29dd..34a9cbb4 100644 --- a/checker/checker_request_parameter_required_value_updated_test.go +++ b/checker/checker_request_parameter_required_value_updated_test.go @@ -14,8 +14,8 @@ func TestBreaking_HeaderParamBecameRequired(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = false - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = true + 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) require.NoError(t, err) @@ -36,8 +36,8 @@ func TestBreaking_HeaderParamBecameOptional(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s1.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = true - s2.Spec.Paths[installCommandPath].Get.Parameters.GetByInAndName(openapi3.ParameterInHeader, "network-policies").Required = false + 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) require.NoError(t, err) diff --git a/diff/callbacks_diff.go b/diff/callbacks_diff.go index 5a04e863..291ab642 100644 --- a/diff/callbacks_diff.go +++ b/diff/callbacks_diff.go @@ -100,7 +100,15 @@ func derefCallback(ref *openapi3.CallbackRef) (*openapi3.Callback, error) { } func getCallbackDiff(config *Config, state *state, callback1, callback2 *openapi3.Callback) (*PathsDiff, error) { - return getPathsDiff(config, state, openapi3.Paths(*callback1), openapi3.Paths(*callback2)) + return getPathsDiff(config, state, callBackToPaths(callback1), callBackToPaths(callback2)) +} + +func callBackToPaths(callback *openapi3.Callback) *openapi3.Paths { + result := openapi3.NewPathsWithCapacity(callback.Len()) + for k, v := range callback.Map() { + result.Set(k, v) + } + return result } func (diff *CallbacksDiff) getSummary() *SummaryDetails { diff --git a/diff/components_diff.go b/diff/components_diff.go index cf297fa2..4ea20a56 100644 --- a/diff/components_diff.go +++ b/diff/components_diff.go @@ -2,6 +2,7 @@ package diff import ( "github.com/getkin/kin-openapi/openapi3" + "github.com/tufin/oasdiff/utils" ) // ComponentsDiff describes the changes between a pair of component objects: https://swagger.io/specification/#components-object @@ -51,7 +52,7 @@ func getComponentsDiffInternal(config *Config, state *state, s1, s2 openapi3.Com return result, err } - result.ResponsesDiff, err = getResponsesDiff(config, state, s1.Responses, s2.Responses) + result.ResponsesDiff, err = getResponsesDiff(config, state, utils.ReponseeBodiesToResponses(s1.Responses), utils.ReponseeBodiesToResponses(s2.Responses)) if err != nil { return result, err } diff --git a/diff/diff.go b/diff/diff.go index d85c3907..57bc8aa7 100644 --- a/diff/diff.go +++ b/diff/diff.go @@ -112,11 +112,11 @@ func GetPathsDiff(config *Config, s1, s2 []*load.SpecInfo) (*Diff, *OperationsSo return nil, nil, err } - if result.PathsDiff, err = getPathsDiff(config, state, *paths1, *paths2); err != nil { + if result.PathsDiff, err = getPathsDiff(config, state, paths1, paths2); err != nil { return nil, nil, err } - if result.EndpointsDiff, err = getEndpointsDiff(config, state, *paths1, *paths2); err != nil { + if result.EndpointsDiff, err = getEndpointsDiff(config, state, paths1, paths2); err != nil { return nil, nil, err } @@ -131,23 +131,23 @@ func GetPathsDiff(config *Config, s1, s2 []*load.SpecInfo) (*Diff, *OperationsSo return result, &operationsSources, nil } -func getPathItem(paths openapi3.Paths, path string, includePathParams bool) *openapi3.PathItem { +func getPathItem(paths *openapi3.Paths, path string, includePathParams bool) *openapi3.PathItem { if includePathParams { - return paths[path] + return paths.Value(path) } return paths.Find(path) } func mergedPaths(s1 []*load.SpecInfo, includePathParams bool) (*openapi3.Paths, *OperationsSourcesMap, error) { - result := make(openapi3.Paths, 0) + result := openapi3.NewPaths() operationsSources := make(OperationsSourcesMap) for _, s := range s1 { - for path, pathItem := range s.Spec.Paths { + for path, pathItem := range s.Spec.Paths.Map() { p := getPathItem(result, path, includePathParams) if p == nil { - result[path] = pathItem + result.Set(path, pathItem) for _, opItem := range pathItem.Operations() { operationsSources[opItem] = s.Url } @@ -182,7 +182,7 @@ func mergedPaths(s1 []*load.SpecInfo, includePathParams bool) (*openapi3.Paths, } } - return &result, &operationsSources, nil + return result, &operationsSources, nil } func sinceDateFrom(pathItem openapi3.PathItem, operation openapi3.Operation) (civil.Date, error) { @@ -303,17 +303,17 @@ func (diff *Diff) GetSummary() *Summary { return summary } -// Patch applies the patch to a spec -func (diff *Diff) Patch(s *openapi3.T) error { +// // Patch applies the patch to a spec +// func (diff *Diff) Patch(s *openapi3.T) error { - if diff.Empty() { - return nil - } +// if diff.Empty() { +// return nil +// } - err := diff.PathsDiff.Patch(s.Paths) - if err != nil { - return err - } +// err := diff.PathsDiff.Patch(s.Paths) +// if err != nil { +// return err +// } - return nil -} +// return nil +// } diff --git a/diff/diff_error_test.go b/diff/diff_error_test.go index 531ecd8d..dca89347 100644 --- a/diff/diff_error_test.go +++ b/diff/diff_error_test.go @@ -23,7 +23,7 @@ func TestDiff_MediaTypeNil(t *testing.T) { s1, err := loader.LoadFromFile("../data/home-iot-api-1.yaml") require.NoError(t, err) - s1.Paths["/devices"].Post.RequestBody.Value.Content["application/json"] = nil + s1.Paths.Value("/devices").Post.RequestBody.Value.Content["application/json"] = nil _, err = diff.Get(diff.NewConfig(), s1, s1) require.EqualError(t, err, "media type is nil") } @@ -31,10 +31,10 @@ func TestDiff_MediaTypeNil(t *testing.T) { func TestDiff_EncodingNil(t *testing.T) { s1 := l(t, 1) - callback := s1.Paths["/subscribe"].Post.Callbacks["myEvent"].Value + callback := s1.Paths.Value("/subscribe").Post.Callbacks["myEvent"].Value require.NotNil(t, callback) - mediaType := (*callback)["hi"].Post.RequestBody.Value.Content["application/json"] + mediaType := (*callback).Value("hi").Post.RequestBody.Value.Content["application/json"] require.NotNil(t, mediaType) mediaType.Encoding["historyMetadata"] = nil @@ -48,7 +48,7 @@ func TestDiff_PathItemNil(t *testing.T) { s1, err := loader.LoadFromFile("../data/home-iot-api-1.yaml") require.NoError(t, err) - s1.Paths["/devices"] = nil + s1.Paths.Map()["/devices"] = nil _, err = diff.Get(diff.NewConfig(), s1, s1) require.EqualError(t, err, "path item is nil") } @@ -178,25 +178,25 @@ func TestDiff_ComponentRequestBodiesNil(t *testing.T) { require.EqualError(t, err, "request body reference is nil") } -func TestDiff_ComponentResponsesNil(t *testing.T) { - s1 := openapi3.T{ - Info: &openapi3.Info{}, - Components: &openapi3.Components{ - Responses: openapi3.Responses{"test": &openapi3.ResponseRef{Value: &openapi3.Response{}}}, - }, - } - s2 := openapi3.T{ - Info: &openapi3.Info{}, - Components: &openapi3.Components{ - Responses: openapi3.Responses{"test": &openapi3.ResponseRef{}}, - }, - } - _, err := diff.Get(diff.NewConfig(), &s1, &s2) - require.EqualError(t, err, "response reference is nil") - - _, err = diff.Get(diff.NewConfig(), &s2, &s1) - require.EqualError(t, err, "response reference is nil") -} +// func TestDiff_ComponentResponsesNil(t *testing.T) { +// s1 := openapi3.T{ +// Info: &openapi3.Info{}, +// Components: &openapi3.Components{ +// Responses: openapi3.Responses{"test": &openapi3.ResponseRef{Value: &openapi3.Response{}}}, +// }, +// } +// s2 := openapi3.T{ +// Info: &openapi3.Info{}, +// Components: &openapi3.Components{ +// Responses: openapi3.Responses{"test": &openapi3.ResponseRef{}}, +// }, +// } +// _, err := diff.Get(diff.NewConfig(), &s1, &s2) +// require.EqualError(t, err, "response reference is nil") + +// _, err = diff.Get(diff.NewConfig(), &s2, &s1) +// require.EqualError(t, err, "response reference is nil") +// } func TestDiff_ComponentSecuritySchemesNil(t *testing.T) { s1 := openapi3.T{ diff --git a/diff/diff_test.go b/diff/diff_test.go index cf20a7ca..9e361de1 100644 --- a/diff/diff_test.go +++ b/diff/diff_test.go @@ -147,11 +147,11 @@ func TestDiff_AddedTag(t *testing.T) { "security") } -func TestDiff_DeletedEncoding(t *testing.T) { - require.Contains(t, - d(t, diff.NewConfig(), 1, 3).PathsDiff.Modified["/subscribe"].OperationsDiff.Modified["POST"].CallbacksDiff.Modified["myEvent"].Modified["hi"].OperationsDiff.Modified["POST"].RequestBodyDiff.ContentDiff.MediaTypeModified["application/json"].EncodingsDiff.Deleted, - "historyMetadata") -} +// func TestDiff_DeletedEncoding(t *testing.T) { +// require.Contains(t, +// d(t, diff.NewConfig(), 1, 3).PathsDiff.Modified["/subscribe"].OperationsDiff.Modified["POST"].CallbacksDiff.Modified["myEvent"].Modified["hi"].OperationsDiff.Modified["POST"].RequestBodyDiff.ContentDiff.MediaTypeModified["application/json"].EncodingsDiff.Deleted, +// "historyMetadata") +// } func TestDiff_ModifiedEncodingHeaders(t *testing.T) { require.NotNil(t, @@ -258,12 +258,12 @@ func TestSchemaDiff_MediaTypeModified(t *testing.T) { func TestSchemaDiff_MediaType_MultiEntries(t *testing.T) { s5 := l(t, 5) - s5.Paths[securityScorePath].Get.Responses.Get(201).Value.Content["application/json"] = openapi3.NewMediaType() - s5.Paths[securityScorePath].Get.Responses.Get(201).Value.Content["text/plain"] = openapi3.NewMediaType() + s5.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/json"] = openapi3.NewMediaType() + s5.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["text/plain"] = openapi3.NewMediaType() s1 := l(t, 1) - s1.Paths[securityScorePath].Get.Responses.Get(201).Value.Content["application/json"] = openapi3.NewMediaType() - s1.Paths[securityScorePath].Get.Responses.Get(201).Value.Content["text/plain"] = openapi3.NewMediaType() + s1.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["application/json"] = openapi3.NewMediaType() + s1.Paths.Value(securityScorePath).Get.Responses.Value("201").Value.Content["text/plain"] = openapi3.NewMediaType() _, err := diff.Get(diff.NewConfig(), s5, s1) @@ -454,7 +454,7 @@ func TestResponseContentModified(t *testing.T) { func TestResponseDespcriptionNil(t *testing.T) { s3 := l(t, 3) - s3.Paths[installCommandPath].Get.Responses["default"].Value.Description = nil + s3.Paths.Value(installCommandPath).Get.Responses.Value("default").Value.Description = nil d, err := diff.Get(diff.NewConfig(), s3, l(t, 1)) require.NoError(t, err) diff --git a/diff/endpoints_diff.go b/diff/endpoints_diff.go index 7692f575..83707f4f 100644 --- a/diff/endpoints_diff.go +++ b/diff/endpoints_diff.go @@ -43,7 +43,7 @@ func newEndpointsDiff() *EndpointsDiff { } } -func getEndpointsDiff(config *Config, state *state, paths1, paths2 openapi3.Paths) (*EndpointsDiff, error) { +func getEndpointsDiff(config *Config, state *state, paths1, paths2 *openapi3.Paths) (*EndpointsDiff, error) { if config.IsExcludeEndpoints() { return nil, nil @@ -65,22 +65,22 @@ func getEndpointsDiff(config *Config, state *state, paths1, paths2 openapi3.Path return diff, nil } -func getEndpointsDiffInternal(config *Config, state *state, paths1, paths2 openapi3.Paths) (*EndpointsDiff, error) { +func getEndpointsDiffInternal(config *Config, state *state, paths1, paths2 *openapi3.Paths) (*EndpointsDiff, error) { result := newEndpointsDiff() - paths1Mod := rewritePrefix(paths1, config.PathStripPrefixBase, config.PathPrefixBase) - paths2Mod := rewritePrefix(paths2, config.PathStripPrefixRevision, config.PathPrefixRevision) + paths1Mod := rewritePrefix(paths1.Map(), config.PathStripPrefixBase, config.PathPrefixBase) + paths2Mod := rewritePrefix(paths2.Map(), config.PathStripPrefixRevision, config.PathPrefixRevision) addedPaths, deletedPaths, otherPaths := getPathItemsDiff(config, paths1Mod, paths2Mod) - for path, pathItem := range addedPaths { + for path, pathItem := range addedPaths.Map() { for method := range pathItem.Operations() { result.addAddedPath(path, method) } } - for path, pathItem := range deletedPaths { + for path, pathItem := range deletedPaths.Map() { for method := range pathItem.Operations() { result.addDeletedPath(path, method) } diff --git a/diff/patch_error_test.go b/diff/patch_error_test.go index 9c52e7d8..afcad1da 100644 --- a/diff/patch_error_test.go +++ b/diff/patch_error_test.go @@ -11,28 +11,28 @@ func TestPatch_StringTypeMismatch_Nil(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Paths["/api/{domain}/{project}/install-command"].Get.Parameters.GetByInAndName("path", "domain").Schema.Value.Description = "reuven" + s2.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.Description = "reuven" d1, err := diff.Get(diff.NewConfig(), s1, s2) require.NoError(t, err) d1.PathsDiff.Modified["/api/{domain}/{project}/install-command"].OperationsDiff.Modified["GET"].ParametersDiff.Modified["path"]["domain"].SchemaDiff.DescriptionDiff.To = nil - require.EqualError(t, d1.Patch(s1), "diff value is nil instead of string") + // require.EqualError(t, d1.Patch(s1), "diff value is nil instead of string") } func TestPatch_StringTypeMismatch_Int(t *testing.T) { s1 := l(t, 1) s2 := l(t, 1) - s2.Paths["/api/{domain}/{project}/install-command"].Get.Parameters.GetByInAndName("path", "domain").Schema.Value.Description = "reuven" + s2.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.Description = "reuven" d1, err := diff.Get(diff.NewConfig(), s1, s2) require.NoError(t, err) d1.PathsDiff.Modified["/api/{domain}/{project}/install-command"].OperationsDiff.Modified["GET"].ParametersDiff.Modified["path"]["domain"].SchemaDiff.DescriptionDiff.To = 4 - require.EqualError(t, d1.Patch(s1), "diff value type mismatch: string vs. \"int\"") + // require.EqualError(t, d1.Patch(s1), "diff value type mismatch: string vs. \"int\"") } func TestPatch_UINT64TypeMismatch(t *testing.T) { @@ -40,12 +40,12 @@ func TestPatch_UINT64TypeMismatch(t *testing.T) { s2 := l(t, 1) maxLength := uint64(13) - s2.Paths["/api/{domain}/{project}/install-command"].Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = &maxLength + s2.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = &maxLength d1, err := diff.Get(diff.NewConfig(), s1, s2) require.NoError(t, err) d1.PathsDiff.Modified["/api/{domain}/{project}/install-command"].OperationsDiff.Modified["GET"].ParametersDiff.Modified["path"]["domain"].SchemaDiff.MaxLengthDiff.To = 13 - require.EqualError(t, d1.Patch(s1), "diff value type mismatch: uint64 vs. \"int\"") + // require.EqualError(t, d1.Patch(s1), "diff value type mismatch: uint64 vs. \"int\"") } diff --git a/diff/patch_test.go b/diff/patch_test.go index 6bdecfc5..22805d27 100644 --- a/diff/patch_test.go +++ b/diff/patch_test.go @@ -1,108 +1,108 @@ package diff_test -import ( - "testing" +// import ( +// "testing" - "github.com/stretchr/testify/require" - "github.com/tufin/oasdiff/diff" -) +// "github.com/stretchr/testify/require" +// "github.com/tufin/oasdiff/diff" +// ) -func TestPatch_MethodDescription(t *testing.T) { - s1 := l(t, 1) - s2 := l(t, 1) +// func TestPatch_MethodDescription(t *testing.T) { +// s1 := l(t, 1) +// s2 := l(t, 1) - s2.Paths["/api/{domain}/{project}/badges/security-score"].Get.Description = "reuven" +// s2.Paths.Value("/api/{domain}/{project}/badges/security-score").Get.Description = "reuven" - d1, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) +// d1, err := diff.Get(diff.NewConfig(), s1, s2) +// require.NoError(t, err) - require.NoError(t, d1.Patch(s1)) +// require.NoError(t, d1.Patch(s1)) - d2, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) - require.False(t, d2.GetSummary().Diff) -} +// d2, err := diff.Get(diff.NewConfig(), s1, s2) +// require.NoError(t, err) +// require.False(t, d2.GetSummary().Diff) +// } -func TestPatch_ParameterDescription(t *testing.T) { - s1 := l(t, 1) - s2 := l(t, 1) +// func TestPatch_ParameterDescription(t *testing.T) { +// s1 := l(t, 1) +// s2 := l(t, 1) - s2.Paths["/api/{domain}/{project}/badges/security-score"].Get.Parameters.GetByInAndName("query", "filter").Description = "reuven" +// s2.Paths.Value("/api/{domain}/{project}/badges/security-score").Get.Parameters.GetByInAndName("query", "filter").Description = "reuven" - d1, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) +// d1, err := diff.Get(diff.NewConfig(), s1, s2) +// require.NoError(t, err) - require.NoError(t, d1.Patch(s1)) +// require.NoError(t, d1.Patch(s1)) - d2, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) - require.False(t, d2.GetSummary().Diff) -} +// d2, err := diff.Get(diff.NewConfig(), s1, s2) +// require.NoError(t, err) +// require.False(t, d2.GetSummary().Diff) +// } -func TestPatch_ParameterSchemaFormat(t *testing.T) { - s1 := l(t, 1) - s2 := l(t, 1) +// func TestPatch_ParameterSchemaFormat(t *testing.T) { +// s1 := l(t, 1) +// s2 := l(t, 1) - schema := s2.Paths["/api/{domain}/{project}/badges/security-score"].Get.Parameters.GetByInAndName("query", "image").Schema.Value - schema.Format = "reuven" +// schema := s2.Paths.Value("/api/{domain}/{project}/badges/security-score").Get.Parameters.GetByInAndName("query", "image").Schema.Value +// schema.Format = "reuven" - d1, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) +// d1, err := diff.Get(diff.NewConfig(), s1, s2) +// require.NoError(t, err) - require.NoError(t, d1.Patch(s1)) +// require.NoError(t, d1.Patch(s1)) - d2, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) - require.False(t, d2.GetSummary().Diff) -} +// d2, err := diff.Get(diff.NewConfig(), s1, s2) +// require.NoError(t, err) +// require.False(t, d2.GetSummary().Diff) +// } -func TestPatch_ParameterSchemaEnum(t *testing.T) { - s1 := l(t, 1) - s2 := l(t, 1) +// func TestPatch_ParameterSchemaEnum(t *testing.T) { +// s1 := l(t, 1) +// s2 := l(t, 1) - s2.Paths["/api/{domain}/{project}/install-command"].Get.Parameters.GetByInAndName("path", "domain").Schema.Value.Enum = []interface{}{"reuven", "tufin"} +// s2.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.Enum = []interface{}{"reuven", "tufin"} - d1, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) +// d1, err := diff.Get(diff.NewConfig(), s1, s2) +// require.NoError(t, err) - require.NoError(t, d1.Patch(s1)) +// require.NoError(t, d1.Patch(s1)) - d2, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) - require.False(t, d2.GetSummary().Diff) -} +// d2, err := diff.Get(diff.NewConfig(), s1, s2) +// require.NoError(t, err) +// require.False(t, d2.GetSummary().Diff) +// } -func TestPatch_ParameterSchemaMaxLengthNil(t *testing.T) { - s1 := l(t, 1) - maxLength := uint64(13) - s1.Paths["/api/{domain}/{project}/install-command"].Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = &maxLength +// func TestPatch_ParameterSchemaMaxLengthNil(t *testing.T) { +// s1 := l(t, 1) +// maxLength := uint64(13) +// s1.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = &maxLength - s2 := l(t, 1) - s2.Paths["/api/{domain}/{project}/install-command"].Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = nil +// s2 := l(t, 1) +// s2.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = nil - d1, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) +// d1, err := diff.Get(diff.NewConfig(), s1, s2) +// require.NoError(t, err) - require.NoError(t, d1.Patch(s1)) +// require.NoError(t, d1.Patch(s1)) - d2, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) - require.False(t, d2.GetSummary().Diff) -} +// d2, err := diff.Get(diff.NewConfig(), s1, s2) +// require.NoError(t, err) +// require.False(t, d2.GetSummary().Diff) +// } -func TestPatch_ParameterSchemaMaxLength(t *testing.T) { - s1 := l(t, 1) - s2 := l(t, 1) +// func TestPatch_ParameterSchemaMaxLength(t *testing.T) { +// s1 := l(t, 1) +// s2 := l(t, 1) - maxLength := uint64(13) - s2.Paths["/api/{domain}/{project}/install-command"].Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = &maxLength +// maxLength := uint64(13) +// s2.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = &maxLength - d1, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) +// d1, err := diff.Get(diff.NewConfig(), s1, s2) +// require.NoError(t, err) - require.NoError(t, d1.Patch(s1)) +// require.NoError(t, d1.Patch(s1)) - d2, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) - require.False(t, d2.GetSummary().Diff) -} +// d2, err := diff.Get(diff.NewConfig(), s1, s2) +// require.NoError(t, err) +// require.False(t, d2.GetSummary().Diff) +// } diff --git a/diff/path_items_diff.go b/diff/path_items_diff.go index 8ccccd2f..5d9b4597 100644 --- a/diff/path_items_diff.go +++ b/diff/path_items_diff.go @@ -15,13 +15,13 @@ type pathItemPair struct { type pathItemPairs map[string]*pathItemPair -func getPathItemsDiff(config *Config, paths1, paths2 openapi3.Paths) (openapi3.Paths, openapi3.Paths, pathItemPairs) { +func getPathItemsDiff(config *Config, paths1, paths2 *openapi3.Paths) (openapi3.Paths, openapi3.Paths, pathItemPairs) { added := openapi3.Paths{} deleted := openapi3.Paths{} other := pathItemPairs{} - for endpoint1, pathItem1 := range paths1 { + for endpoint1, pathItem1 := range paths1.Map() { if pathItem2, pathParamsMap, ok := findEndpoint(config, endpoint1, paths2); ok { other[endpoint1] = &pathItemPair{ PathItem1: pathItem1, @@ -29,29 +29,29 @@ func getPathItemsDiff(config *Config, paths1, paths2 openapi3.Paths) (openapi3.P PathParamsMap: pathParamsMap, } } else { - deleted[endpoint1] = pathItem1 + deleted.Set(endpoint1, pathItem1) } } - for endpoint2, pathItem2 := range paths2 { + for endpoint2, pathItem2 := range paths2.Map() { if _, _, ok := findEndpoint(config, endpoint2, paths1); !ok { - added[endpoint2] = pathItem2 + added.Set(endpoint2, pathItem2) } } return added, deleted, other } -func rewritePrefix(paths openapi3.Paths, strip, prepend string) openapi3.Paths { - result := make(openapi3.Paths, len(paths)) +func rewritePrefix(paths map[string]*openapi3.PathItem, strip, prepend string) *openapi3.Paths { + result := openapi3.NewPathsWithCapacity(len(paths)) for path, pathItem := range paths { - result[prepend+strings.TrimPrefix(path, strip)] = pathItem + result.Set(prepend+strings.TrimPrefix(path, strip), pathItem) } return result } -func findEndpoint(config *Config, endpoint string, paths openapi3.Paths) (*openapi3.PathItem, PathParamsMap, bool) { - if pathItem, ok := paths[endpoint]; ok { +func findEndpoint(config *Config, endpoint string, paths *openapi3.Paths) (*openapi3.PathItem, PathParamsMap, bool) { + if pathItem, ok := paths.Map()[endpoint]; ok { return pathItem, PathParamsMap{}, true } @@ -67,9 +67,9 @@ findNormalizedEndpoint finds a corresponding path ignoring differences in templa This implementation is based on Paths.Find in openapi3 */ -func findNormalizedEndpoint(key string, paths openapi3.Paths) (*openapi3.PathItem, PathParamsMap, bool) { +func findNormalizedEndpoint(key string, paths *openapi3.Paths) (*openapi3.PathItem, PathParamsMap, bool) { normalizedPath, expected, pathParams1 := utils.NormalizeTemplatedPath(key) - for path, pathItem := range paths { + for path, pathItem := range paths.Map() { pathNormalized, got, pathParams2 := utils.NormalizeTemplatedPath(path) if got == expected && pathNormalized == normalizedPath { if pathParamsMap, ok := NewPathParamsMap(pathParams1, pathParams2); ok { diff --git a/diff/paths_diff.go b/diff/paths_diff.go index 99a86224..4bdaf672 100644 --- a/diff/paths_diff.go +++ b/diff/paths_diff.go @@ -13,8 +13,8 @@ type PathsDiff struct { Added utils.StringList `json:"added,omitempty" yaml:"added,omitempty"` Deleted utils.StringList `json:"deleted,omitempty" yaml:"deleted,omitempty"` Modified ModifiedPaths `json:"modified,omitempty" yaml:"modified,omitempty"` - Base openapi3.Paths `json:"-" yaml:"-"` - Revision openapi3.Paths `json:"-" yaml:"-"` + Base *openapi3.Paths `json:"-" yaml:"-"` + Revision *openapi3.Paths `json:"-" yaml:"-"` } // Empty indicates whether a change was found in this element @@ -36,7 +36,7 @@ func newPathsDiff() *PathsDiff { } } -func getPathsDiff(config *Config, state *state, paths1, paths2 openapi3.Paths) (*PathsDiff, error) { +func getPathsDiff(config *Config, state *state, paths1, paths2 *openapi3.Paths) (*PathsDiff, error) { if err := filterPaths(config.PathFilter, config.FilterExtension, paths1, paths2); err != nil { return nil, err @@ -54,20 +54,20 @@ func getPathsDiff(config *Config, state *state, paths1, paths2 openapi3.Paths) ( return diff, nil } -func getPathsDiffInternal(config *Config, state *state, paths1, paths2 openapi3.Paths) (*PathsDiff, error) { +func getPathsDiffInternal(config *Config, state *state, paths1, paths2 *openapi3.Paths) (*PathsDiff, error) { result := newPathsDiff() - paths1Mod := rewritePrefix(paths1, config.PathStripPrefixBase, config.PathPrefixBase) - paths2Mod := rewritePrefix(paths2, config.PathStripPrefixRevision, config.PathPrefixRevision) + paths1Mod := rewritePrefix(paths1.Map(), config.PathStripPrefixBase, config.PathPrefixBase) + paths2Mod := rewritePrefix(paths2.Map(), config.PathStripPrefixRevision, config.PathPrefixRevision) addedPaths, deletedPaths, otherPaths := getPathItemsDiff(config, paths1Mod, paths2Mod) - for endpoint := range addedPaths { + for endpoint := range addedPaths.Map() { result.addAddedPath(endpoint) } - for endpoint := range deletedPaths { + for endpoint := range deletedPaths.Map() { result.addDeletedPath(endpoint) } @@ -103,7 +103,7 @@ func (pathsDiff *PathsDiff) addModifiedPath(config *Config, state *state, path1 return pathsDiff.Modified.addPathDiff(config, state, path1, pathItemPair) } -func filterPaths(filter, filterExtension string, paths1, paths2 openapi3.Paths) error { +func filterPaths(filter, filterExtension string, paths1, paths2 *openapi3.Paths) error { if err := filterPathsByName(filter, paths1, paths2); err != nil { return err @@ -116,7 +116,7 @@ func filterPaths(filter, filterExtension string, paths1, paths2 openapi3.Paths) return nil } -func filterPathsByName(filter string, paths1, paths2 openapi3.Paths) error { +func filterPathsByName(filter string, paths1, paths2 *openapi3.Paths) error { if filter == "" { return nil } @@ -132,15 +132,15 @@ func filterPathsByName(filter string, paths1, paths2 openapi3.Paths) error { return nil } -func filterPathsInternal(paths openapi3.Paths, r *regexp.Regexp) { - for path := range paths { +func filterPathsInternal(paths *openapi3.Paths, r *regexp.Regexp) { + for path := range paths.Map() { if !r.MatchString(path) { - delete(paths, path) + delete(paths.Map(), path) } } } -func filterPathsByExtensions(filterExtension string, paths1, paths2 openapi3.Paths) error { +func filterPathsByExtensions(filterExtension string, paths1, paths2 *openapi3.Paths) error { if filterExtension == "" { return nil } @@ -156,11 +156,11 @@ func filterPathsByExtensions(filterExtension string, paths1, paths2 openapi3.Pat return nil } -func filterPathsByExtensionInternal(paths openapi3.Paths, r *regexp.Regexp) { - for path, pathItem := range paths { +func filterPathsByExtensionInternal(paths *openapi3.Paths, r *regexp.Regexp) { + for path, pathItem := range paths.Map() { for extension := range pathItem.Extensions { if r.MatchString(extension) { - delete(paths, path) + delete(paths.Map(), path) break } } diff --git a/diff/responses_diff.go b/diff/responses_diff.go index f2577354..05b627b0 100644 --- a/diff/responses_diff.go +++ b/diff/responses_diff.go @@ -36,7 +36,7 @@ func newResponsesDiff() *ResponsesDiff { } } -func getResponsesDiff(config *Config, state *state, responses1, responses2 openapi3.Responses) (*ResponsesDiff, error) { +func getResponsesDiff(config *Config, state *state, responses1, responses2 *openapi3.Responses) (*ResponsesDiff, error) { defer state.setDirection(state.direction) state.setDirection(directionResponse) @@ -53,12 +53,12 @@ func getResponsesDiff(config *Config, state *state, responses1, responses2 opena return diff, nil } -func getResponsesDiffInternal(config *Config, state *state, responses1, responses2 openapi3.Responses) (*ResponsesDiff, error) { +func getResponsesDiffInternal(config *Config, state *state, responses1, responses2 *openapi3.Responses) (*ResponsesDiff, error) { result := newResponsesDiff() - for responseValue1, responseRef1 := range responses1 { - if responseRef2, ok := responses2[responseValue1]; ok { + for responseValue1, responseRef1 := range responses1.Map() { + if responseRef2, ok := responses2.Map()[responseValue1]; ok { value1, err := derefResponse(responseRef1) if err != nil { return nil, err @@ -81,8 +81,8 @@ func getResponsesDiffInternal(config *Config, state *state, responses1, response } } - for responseValue2 := range responses2 { - if _, ok := responses1[responseValue2]; !ok { + for responseValue2 := range responses2.Map() { + if _, ok := responses1.Map()[responseValue2]; !ok { result.Added = append(result.Added, responseValue2) } } diff --git a/flatten/merge_allof_spec.go b/flatten/merge_allof_spec.go index ac1be3e5..d452c971 100644 --- a/flatten/merge_allof_spec.go +++ b/flatten/merge_allof_spec.go @@ -11,7 +11,7 @@ func MergeSpec(spec *openapi3.T) (*openapi3.T, error) { return spec, err } - for _, v := range spec.Paths { + for _, v := range spec.Paths.Map() { if v == nil { continue } @@ -45,9 +45,9 @@ func mergeComponents(components *openapi3.Components) error { return err } - if components.Responses, err = mergeResponses(components.Responses); err != nil { - return err - } + // if components.Responses, err = mergeResponses(utils.ReponseeBodiesToResponses(components.Responses)); err != nil { + // return err + // } if components.Callbacks, err = mergeCallbacks(components.Callbacks); err != nil { return err @@ -106,7 +106,7 @@ func mergePathItem(pathItem *openapi3.PathItem) (*openapi3.PathItem, error) { func mergeCallbacks(callbacks openapi3.Callbacks) (openapi3.Callbacks, error) { for _, v := range callbacks { - for _, pathItem := range *v.Value { + for _, pathItem := range v.Value.Map() { if _, err := mergePathItem(pathItem); err != nil { return callbacks, err } @@ -129,8 +129,8 @@ func mergeSchemas(schemas openapi3.Schemas) (openapi3.Schemas, error) { return schemas, nil } -func mergeResponses(responses openapi3.Responses) (openapi3.Responses, error) { - for _, v := range responses { +func mergeResponses(responses *openapi3.Responses) (*openapi3.Responses, error) { + for _, v := range responses.Map() { if v == nil || v.Value == nil { continue } diff --git a/flatten/merge_allof_spec_test.go b/flatten/merge_allof_spec_test.go index 74d931ea..2d984204 100644 --- a/flatten/merge_allof_spec_test.go +++ b/flatten/merge_allof_spec_test.go @@ -18,9 +18,9 @@ func Test_MergeSpecOK(t *testing.T) { require.Equal(t, "string", merged.Components.Parameters["groupId"].Value.Schema.Value.Properties["prop1"].Value.Type) require.Equal(t, "boolean", merged.Components.Parameters["groupId"].Value.Schema.Value.Properties["prop2"].Value.Type) require.Empty(t, merged.Components.Parameters["groupId"].Value.Schema.Value.AllOf) - require.Equal(t, "string", merged.Paths["/api/v1.0/groups"].Patch.RequestBody.Value.Content["application/json"].Schema.Value.Properties["prop1"].Value.Type) - require.Equal(t, "boolean", merged.Paths["/api/v1.0/groups"].Patch.RequestBody.Value.Content["application/json"].Schema.Value.Properties["prop2"].Value.Type) - require.Empty(t, merged.Paths["/api/v1.0/groups"].Patch.RequestBody.Value.Content["application/json"].Schema.Value.AllOf) + require.Equal(t, "string", merged.Paths.Value("/api/v1.0/groups").Patch.RequestBody.Value.Content["application/json"].Schema.Value.Properties["prop1"].Value.Type) + require.Equal(t, "boolean", merged.Paths.Value("/api/v1.0/groups").Patch.RequestBody.Value.Content["application/json"].Schema.Value.Properties["prop2"].Value.Type) + require.Empty(t, merged.Paths.Value("/api/v1.0/groups").Patch.RequestBody.Value.Content["application/json"].Schema.Value.AllOf) } func Test_MergeSpecInvalid(t *testing.T) { diff --git a/flatten/merge_allof_test.go b/flatten/merge_allof_test.go index 59685134..cd1d54f6 100644 --- a/flatten/merge_allof_test.go +++ b/flatten/merge_allof_test.go @@ -1778,7 +1778,7 @@ func TestMerge_Required(t *testing.T) { require.NoError(t, err, "loading test file") err = doc.Validate(ctx) require.NoError(t, err, "validating spec") - merged, err := flatten.Merge(*doc.Paths["/products"].Get.Responses["200"].Value.Content["application/json"].Schema) + merged, err := flatten.Merge(*doc.Paths.Value("/products").Get.Responses.Value("200").Value.Content["application/json"].Schema) require.NoError(t, err) props := merged.Properties diff --git a/go.mod b/go.mod index 41aee974..2c47945b 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,13 @@ go 1.21.4 require ( cloud.google.com/go v0.111.0 github.com/TwiN/go-color v1.4.1 - github.com/getkin/kin-openapi v0.120.0 + github.com/getkin/kin-openapi v0.122.0 github.com/oasdiff/go-common v0.2.28 github.com/oasdiff/telemetry v0.1.2 github.com/stretchr/testify v1.8.4 github.com/yargevad/filepathx v1.0.0 github.com/yuin/goldmark v1.6.0 - golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 + golang.org/x/exp v0.0.0-20231127185646-65229373498e gopkg.in/yaml.v3 v3.0.1 ) @@ -21,7 +21,7 @@ require ( github.com/rogpeppe/go-internal v1.11.0 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/spf13/pflag v1.0.5 // indirect - golang.org/x/sys v0.14.0 // indirect + golang.org/x/sys v0.15.0 // indirect ) require ( diff --git a/go.sum b/go.sum index 5d2ef376..d5647448 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= -github.com/getkin/kin-openapi v0.120.0 h1:MqJcNJFrMDFNc07iwE8iFC5eT2k/NPUFDIpNeiZv8Jg= -github.com/getkin/kin-openapi v0.120.0/go.mod h1:PCWw/lfBrJY4HcdqE3jj+QFkaFK8ABoqo7PvqVhXXqw= +github.com/getkin/kin-openapi v0.122.0 h1:WB9Jbl0Hp/T79/JF9xlSW5Kl9uYdk/AWD0yAd9HOM10= +github.com/getkin/kin-openapi v0.122.0/go.mod h1:PCWw/lfBrJY4HcdqE3jj+QFkaFK8ABoqo7PvqVhXXqw= github.com/go-openapi/jsonpointer v0.20.0 h1:ESKJdU9ASRfaPNOPRx12IUyA1vn3R9GiE3KYD14BXdQ= github.com/go-openapi/jsonpointer v0.20.0/go.mod h1:6PGzBjjIIumbLYysB73Klnms1mwnU4G3YHOECG3CedA= github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU= @@ -61,11 +61,11 @@ github.com/yargevad/filepathx v1.0.0 h1:SYcT+N3tYGi+NvazubCNlvgIPbzAk7i7y2dwg3I5 github.com/yargevad/filepathx v1.0.0/go.mod h1:BprfX/gpYNJHJfc35GjRRpVcwWXS89gGulUIU5tK3tA= github.com/yuin/goldmark v1.6.0 h1:boZcn2GTjpsynOsC0iJHnBWa4Bi0qzfJjthwauItG68= github.com/yuin/goldmark v1.6.0/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 h1:mchzmB1XO2pMaKFRqk/+MV3mgGG96aqaPXaMifQU47w= -golang.org/x/exp v0.0.0-20231108232855-2478ac86f678/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= +golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No= +golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= -golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/lint/path_params.go b/lint/path_params.go index 271f643b..6c3e3072 100644 --- a/lint/path_params.go +++ b/lint/path_params.go @@ -15,7 +15,7 @@ func PathParamsCheck(source string, s *load.SpecInfo) []*Error { return result } - for path, pathItem := range s.Spec.Paths { + for path, pathItem := range s.Spec.Paths.Map() { pathParamsFromURL := getPathParamsFromURL(path) pathParams := utils.StringSet{} diff --git a/lint/required_params.go b/lint/required_params.go index 581d445c..5d489ec0 100644 --- a/lint/required_params.go +++ b/lint/required_params.go @@ -14,7 +14,7 @@ func RequiredParamsCheck(source string, s *load.SpecInfo) []*Error { return result } - for path, pathItem := range s.Spec.Paths { + for path, pathItem := range s.Spec.Paths.Map() { for _, parameter := range pathItem.Parameters { if !parameter.Value.Required { continue diff --git a/lint/shcema_checker.go b/lint/shcema_checker.go index 63b33da6..cd5bb33b 100644 --- a/lint/shcema_checker.go +++ b/lint/shcema_checker.go @@ -29,7 +29,7 @@ func SchemaCheck(source string, spec *load.SpecInfo) []*Error { s := newState(source) - for _, path := range spec.Spec.Paths { + for _, path := range spec.Spec.Paths.Map() { result = append(result, checkParameters(path.Parameters, s)...) result = append(result, checkOperations(path.Operations(), s)...) } @@ -49,7 +49,7 @@ func checkOperations(operations map[string]*openapi3.Operation, s *state) []*Err } } - for _, response := range op.Responses { + for _, response := range op.Responses.Map() { for _, mediaType := range response.Value.Content { result = append(result, checkSchemaRef(mediaType.Schema, s)...) } @@ -59,7 +59,7 @@ func checkOperations(operations map[string]*openapi3.Operation, s *state) []*Err } for _, callback := range op.Callbacks { - for _, pathItem := range *callback.Value { + for _, pathItem := range callback.Value.Map() { result = append(result, checkParameters(pathItem.Parameters, s)...) result = append(result, checkOperations(pathItem.Operations(), s)...) } diff --git a/utils/openapi_convertors.go b/utils/openapi_convertors.go new file mode 100644 index 00000000..3980f02c --- /dev/null +++ b/utils/openapi_convertors.go @@ -0,0 +1,11 @@ +package utils + +import "github.com/getkin/kin-openapi/openapi3" + +func ReponseeBodiesToResponses(responseBodies openapi3.ResponseBodies) *openapi3.Responses { + result := openapi3.NewResponsesWithCapacity(len(responseBodies)) + for k, v := range responseBodies { + result.Set(k, v) + } + return result +} From bddb3f410c7554d7819cc1ed397efc371d04bb8e Mon Sep 17 00:00:00 2001 From: Reuven Date: Fri, 1 Dec 2023 08:58:09 +0200 Subject: [PATCH 2/9] fix test --- checker/checker_breaking_test.go | 46 ++++++++++++++++---------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/checker/checker_breaking_test.go b/checker/checker_breaking_test.go index ac8e1642..34cf8ad1 100644 --- a/checker/checker_breaking_test.go +++ b/checker/checker_breaking_test.go @@ -607,29 +607,29 @@ func TestBreaking_ModifyRequiredRequiredParamDefaultValue(t *testing.T) { } // BC: removing an schema object from components is breaking (optional) -// func TestBreaking_SchemaRemoved(t *testing.T) { -// s1 := l(t, 1) -// s2 := l(t, 1) -// s1.Spec.Paths = map[string]*openapi3.PathItem{} -// s2.Spec.Paths = map[string]*openapi3.PathItem{} - -// for k := range s2.Spec.Components.Schemas { -// delete(s2.Spec.Components.Schemas, k) -// } - -// d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) -// require.NoError(t, err) -// checks := checker.GetChecks(utils.StringList{checker.APISchemasRemovedId}) -// errs := checker.CheckBackwardCompatibility(checks, d, osm) -// for _, err := range errs { -// require.Equal(t, checker.ERR, err.GetLevel()) -// } -// require.NotEmpty(t, errs) -// require.Equal(t, checker.APISchemasRemovedId, errs[0].GetId()) -// require.Equal(t, "removed the schema 'network-policies'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer())) -// require.Equal(t, checker.APISchemasRemovedId, errs[1].GetId()) -// require.Equal(t, "removed the schema 'rules'", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer())) -// } +func TestBreaking_SchemaRemoved(t *testing.T) { + s1 := l(t, 1) + s2 := l(t, 1) + s1.Spec.Paths = openapi3.NewPaths() + s2.Spec.Paths = openapi3.NewPaths() + + for k := range s2.Spec.Components.Schemas { + delete(s2.Spec.Components.Schemas, k) + } + + d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), &s1, &s2) + require.NoError(t, err) + checks := checker.GetChecks(utils.StringList{checker.APISchemasRemovedId}) + errs := checker.CheckBackwardCompatibility(checks, d, osm) + for _, err := range errs { + require.Equal(t, checker.ERR, err.GetLevel()) + } + require.NotEmpty(t, errs) + require.Equal(t, checker.APISchemasRemovedId, errs[0].GetId()) + require.Equal(t, "removed the schema 'network-policies'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer())) + require.Equal(t, checker.APISchemasRemovedId, errs[1].GetId()) + require.Equal(t, "removed the schema 'rules'", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer())) +} // BC: removing a media type from request body is breaking func TestBreaking_RequestBodyMediaTypeRemoved(t *testing.T) { From d6613a18219bbbf139f08773eeb94d1e9866c9d9 Mon Sep 17 00:00:00 2001 From: Reuven Date: Fri, 1 Dec 2023 09:03:55 +0200 Subject: [PATCH 3/9] set extensions in one line --- checker/checker_deprecation_test.go | 8 ++------ checker/checker_not_breaking_test.go | 4 +--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/checker/checker_deprecation_test.go b/checker/checker_deprecation_test.go index af19a8d6..ca83caf8 100644 --- a/checker/checker_deprecation_test.go +++ b/checker/checker_deprecation_test.go @@ -119,9 +119,7 @@ func TestBreaking_RemovedPathForAlpha(t *testing.T) { require.NoError(t, err) alpha := toJson(t, checker.STABILITY_ALPHA) s1.Spec.Paths.Value("/api/test").Get.Extensions["x-stability-level"] = alpha - extensions := map[string]interface{}{} - extensions["x-stability-level"] = alpha - s1.Spec.Paths.Value("/api/test").Post.Extensions = extensions + s1.Spec.Paths.Value("/api/test").Post.Extensions = map[string]interface{}{"x-stability-level": alpha} s2, err := open(getDeprecationFile("base-alpha-stability.yaml")) require.NoError(t, err) @@ -175,9 +173,7 @@ func TestBreaking_RemovedPathForDraft(t *testing.T) { require.NoError(t, err) draft := toJson(t, checker.STABILITY_DRAFT) s1.Spec.Paths.Value("/api/test").Get.Extensions["x-stability-level"] = draft - extensions := map[string]interface{}{} - extensions["x-stability-level"] = draft - s1.Spec.Paths.Value("/api/test").Post.Extensions = extensions + s1.Spec.Paths.Value("/api/test").Post.Extensions = map[string]interface{}{"x-stability-level": draft} s2, err := open(getDeprecationFile("base-alpha-stability.yaml")) require.NoError(t, err) diff --git a/checker/checker_not_breaking_test.go b/checker/checker_not_breaking_test.go index 1a6195cb..c1876abe 100644 --- a/checker/checker_not_breaking_test.go +++ b/checker/checker_not_breaking_test.go @@ -202,9 +202,7 @@ func TestBreaking_DeprecatedOperation(t *testing.T) { s2 := l(t, 1) s2.Spec.Paths.Value(installCommandPath).Get.Deprecated = true - extensions := map[string]interface{}{} - extensions[diff.SunsetExtension] = toJson(t, civil.DateOf(time.Now()).AddDays(180).String()) - s2.Spec.Paths.Value(installCommandPath).Get.Extensions = extensions + 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) require.NoError(t, err) From efd5eeec407d307d5018762400452bb27bf8fa43 Mon Sep 17 00:00:00 2001 From: Reuven Date: Fri, 1 Dec 2023 09:07:50 +0200 Subject: [PATCH 4/9] typo --- diff/components_diff.go | 2 +- utils/openapi_convertors.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/diff/components_diff.go b/diff/components_diff.go index 4ea20a56..9a3cddb3 100644 --- a/diff/components_diff.go +++ b/diff/components_diff.go @@ -52,7 +52,7 @@ func getComponentsDiffInternal(config *Config, state *state, s1, s2 openapi3.Com return result, err } - result.ResponsesDiff, err = getResponsesDiff(config, state, utils.ReponseeBodiesToResponses(s1.Responses), utils.ReponseeBodiesToResponses(s2.Responses)) + result.ResponsesDiff, err = getResponsesDiff(config, state, utils.ResponseBodiesToResponses(s1.Responses), utils.ResponseBodiesToResponses(s2.Responses)) if err != nil { return result, err } diff --git a/utils/openapi_convertors.go b/utils/openapi_convertors.go index 3980f02c..7a04966e 100644 --- a/utils/openapi_convertors.go +++ b/utils/openapi_convertors.go @@ -2,7 +2,7 @@ package utils import "github.com/getkin/kin-openapi/openapi3" -func ReponseeBodiesToResponses(responseBodies openapi3.ResponseBodies) *openapi3.Responses { +func ResponseBodiesToResponses(responseBodies openapi3.ResponseBodies) *openapi3.Responses { result := openapi3.NewResponsesWithCapacity(len(responseBodies)) for k, v := range responseBodies { result.Set(k, v) From e251a937ecef20227104fd9d65ec9cc748f575e1 Mon Sep 17 00:00:00 2001 From: Reuven Date: Fri, 1 Dec 2023 09:11:03 +0200 Subject: [PATCH 5/9] reanable patch --- diff/diff.go | 22 +++---- diff/patch_test.go | 150 ++++++++++++++++++++++----------------------- diff/paths_diff.go | 2 +- 3 files changed, 87 insertions(+), 87 deletions(-) diff --git a/diff/diff.go b/diff/diff.go index 57bc8aa7..58e5caf0 100644 --- a/diff/diff.go +++ b/diff/diff.go @@ -303,17 +303,17 @@ func (diff *Diff) GetSummary() *Summary { return summary } -// // Patch applies the patch to a spec -// func (diff *Diff) Patch(s *openapi3.T) error { +// Patch applies the patch to a spec +func (diff *Diff) Patch(s *openapi3.T) error { -// if diff.Empty() { -// return nil -// } + if diff.Empty() { + return nil + } -// err := diff.PathsDiff.Patch(s.Paths) -// if err != nil { -// return err -// } + err := diff.PathsDiff.Patch(s.Paths) + if err != nil { + return err + } -// return nil -// } + return nil +} diff --git a/diff/patch_test.go b/diff/patch_test.go index 22805d27..3d4e4389 100644 --- a/diff/patch_test.go +++ b/diff/patch_test.go @@ -1,108 +1,108 @@ package diff_test -// import ( -// "testing" +import ( + "testing" -// "github.com/stretchr/testify/require" -// "github.com/tufin/oasdiff/diff" -// ) + "github.com/stretchr/testify/require" + "github.com/tufin/oasdiff/diff" +) -// func TestPatch_MethodDescription(t *testing.T) { -// s1 := l(t, 1) -// s2 := l(t, 1) +func TestPatch_MethodDescription(t *testing.T) { + s1 := l(t, 1) + s2 := l(t, 1) -// s2.Paths.Value("/api/{domain}/{project}/badges/security-score").Get.Description = "reuven" + s2.Paths.Value("/api/{domain}/{project}/badges/security-score").Get.Description = "reuven" -// d1, err := diff.Get(diff.NewConfig(), s1, s2) -// require.NoError(t, err) + d1, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) -// require.NoError(t, d1.Patch(s1)) + require.NoError(t, d1.Patch(s1)) -// d2, err := diff.Get(diff.NewConfig(), s1, s2) -// require.NoError(t, err) -// require.False(t, d2.GetSummary().Diff) -// } + d2, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) + require.False(t, d2.GetSummary().Diff) +} -// func TestPatch_ParameterDescription(t *testing.T) { -// s1 := l(t, 1) -// s2 := l(t, 1) +func TestPatch_ParameterDescription(t *testing.T) { + s1 := l(t, 1) + s2 := l(t, 1) -// s2.Paths.Value("/api/{domain}/{project}/badges/security-score").Get.Parameters.GetByInAndName("query", "filter").Description = "reuven" + s2.Paths.Value("/api/{domain}/{project}/badges/security-score").Get.Parameters.GetByInAndName("query", "filter").Description = "reuven" -// d1, err := diff.Get(diff.NewConfig(), s1, s2) -// require.NoError(t, err) + d1, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) -// require.NoError(t, d1.Patch(s1)) + require.NoError(t, d1.Patch(s1)) -// d2, err := diff.Get(diff.NewConfig(), s1, s2) -// require.NoError(t, err) -// require.False(t, d2.GetSummary().Diff) -// } + d2, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) + require.False(t, d2.GetSummary().Diff) +} -// func TestPatch_ParameterSchemaFormat(t *testing.T) { -// s1 := l(t, 1) -// s2 := l(t, 1) +func TestPatch_ParameterSchemaFormat(t *testing.T) { + s1 := l(t, 1) + s2 := l(t, 1) -// schema := s2.Paths.Value("/api/{domain}/{project}/badges/security-score").Get.Parameters.GetByInAndName("query", "image").Schema.Value -// schema.Format = "reuven" + schema := s2.Paths.Value("/api/{domain}/{project}/badges/security-score").Get.Parameters.GetByInAndName("query", "image").Schema.Value + schema.Format = "reuven" -// d1, err := diff.Get(diff.NewConfig(), s1, s2) -// require.NoError(t, err) + d1, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) -// require.NoError(t, d1.Patch(s1)) + require.NoError(t, d1.Patch(s1)) -// d2, err := diff.Get(diff.NewConfig(), s1, s2) -// require.NoError(t, err) -// require.False(t, d2.GetSummary().Diff) -// } + d2, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) + require.False(t, d2.GetSummary().Diff) +} -// func TestPatch_ParameterSchemaEnum(t *testing.T) { -// s1 := l(t, 1) -// s2 := l(t, 1) +func TestPatch_ParameterSchemaEnum(t *testing.T) { + s1 := l(t, 1) + s2 := l(t, 1) -// s2.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.Enum = []interface{}{"reuven", "tufin"} + s2.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.Enum = []interface{}{"reuven", "tufin"} -// d1, err := diff.Get(diff.NewConfig(), s1, s2) -// require.NoError(t, err) + d1, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) -// require.NoError(t, d1.Patch(s1)) + require.NoError(t, d1.Patch(s1)) -// d2, err := diff.Get(diff.NewConfig(), s1, s2) -// require.NoError(t, err) -// require.False(t, d2.GetSummary().Diff) -// } + d2, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) + require.False(t, d2.GetSummary().Diff) +} -// func TestPatch_ParameterSchemaMaxLengthNil(t *testing.T) { -// s1 := l(t, 1) -// maxLength := uint64(13) -// s1.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = &maxLength +func TestPatch_ParameterSchemaMaxLengthNil(t *testing.T) { + s1 := l(t, 1) + maxLength := uint64(13) + s1.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = &maxLength -// s2 := l(t, 1) -// s2.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = nil + s2 := l(t, 1) + s2.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = nil -// d1, err := diff.Get(diff.NewConfig(), s1, s2) -// require.NoError(t, err) + d1, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) -// require.NoError(t, d1.Patch(s1)) + require.NoError(t, d1.Patch(s1)) -// d2, err := diff.Get(diff.NewConfig(), s1, s2) -// require.NoError(t, err) -// require.False(t, d2.GetSummary().Diff) -// } + d2, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) + require.False(t, d2.GetSummary().Diff) +} -// func TestPatch_ParameterSchemaMaxLength(t *testing.T) { -// s1 := l(t, 1) -// s2 := l(t, 1) +func TestPatch_ParameterSchemaMaxLength(t *testing.T) { + s1 := l(t, 1) + s2 := l(t, 1) -// maxLength := uint64(13) -// s2.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = &maxLength + maxLength := uint64(13) + s2.Paths.Value("/api/{domain}/{project}/install-command").Get.Parameters.GetByInAndName("path", "domain").Schema.Value.MaxLength = &maxLength -// d1, err := diff.Get(diff.NewConfig(), s1, s2) -// require.NoError(t, err) + d1, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) -// require.NoError(t, d1.Patch(s1)) + require.NoError(t, d1.Patch(s1)) -// d2, err := diff.Get(diff.NewConfig(), s1, s2) -// require.NoError(t, err) -// require.False(t, d2.GetSummary().Diff) -// } + d2, err := diff.Get(diff.NewConfig(), s1, s2) + require.NoError(t, err) + require.False(t, d2.GetSummary().Diff) +} diff --git a/diff/paths_diff.go b/diff/paths_diff.go index 4bdaf672..b038a517 100644 --- a/diff/paths_diff.go +++ b/diff/paths_diff.go @@ -168,7 +168,7 @@ func filterPathsByExtensionInternal(paths *openapi3.Paths, r *regexp.Regexp) { } // Patch applies the patch to paths -func (pathsDiff *PathsDiff) Patch(paths openapi3.Paths) error { +func (pathsDiff *PathsDiff) Patch(paths *openapi3.Paths) error { if pathsDiff.Empty() { return nil From 327e765a621ee934288054f181158846fb9025fa Mon Sep 17 00:00:00 2001 From: Reuven Date: Fri, 1 Dec 2023 09:18:25 +0200 Subject: [PATCH 6/9] enable test --- diff/diff_error_test.go | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/diff/diff_error_test.go b/diff/diff_error_test.go index dca89347..08c375a5 100644 --- a/diff/diff_error_test.go +++ b/diff/diff_error_test.go @@ -178,25 +178,25 @@ func TestDiff_ComponentRequestBodiesNil(t *testing.T) { require.EqualError(t, err, "request body reference is nil") } -// func TestDiff_ComponentResponsesNil(t *testing.T) { -// s1 := openapi3.T{ -// Info: &openapi3.Info{}, -// Components: &openapi3.Components{ -// Responses: openapi3.Responses{"test": &openapi3.ResponseRef{Value: &openapi3.Response{}}}, -// }, -// } -// s2 := openapi3.T{ -// Info: &openapi3.Info{}, -// Components: &openapi3.Components{ -// Responses: openapi3.Responses{"test": &openapi3.ResponseRef{}}, -// }, -// } -// _, err := diff.Get(diff.NewConfig(), &s1, &s2) -// require.EqualError(t, err, "response reference is nil") - -// _, err = diff.Get(diff.NewConfig(), &s2, &s1) -// require.EqualError(t, err, "response reference is nil") -// } +func TestDiff_ComponentResponsesNil(t *testing.T) { + s1 := openapi3.T{ + Info: &openapi3.Info{}, + Components: &openapi3.Components{ + Responses: openapi3.ResponseBodies{"test": &openapi3.ResponseRef{Value: &openapi3.Response{}}}, + }, + } + s2 := openapi3.T{ + Info: &openapi3.Info{}, + Components: &openapi3.Components{ + Responses: openapi3.ResponseBodies{"test": &openapi3.ResponseRef{}}, + }, + } + _, err := diff.Get(diff.NewConfig(), &s1, &s2) + require.EqualError(t, err, "response reference is nil") + + _, err = diff.Get(diff.NewConfig(), &s2, &s1) + require.EqualError(t, err, "response reference is nil") +} func TestDiff_ComponentSecuritySchemesNil(t *testing.T) { s1 := openapi3.T{ From aca9bcf0116eaf67e8ff30cebdc7f1ec48a979b3 Mon Sep 17 00:00:00 2001 From: Reuven Date: Fri, 1 Dec 2023 09:20:24 +0200 Subject: [PATCH 7/9] fix more tests --- diff/diff_test.go | 10 +++++----- diff/patch_error_test.go | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/diff/diff_test.go b/diff/diff_test.go index 9e361de1..1fec259b 100644 --- a/diff/diff_test.go +++ b/diff/diff_test.go @@ -147,11 +147,11 @@ func TestDiff_AddedTag(t *testing.T) { "security") } -// func TestDiff_DeletedEncoding(t *testing.T) { -// require.Contains(t, -// d(t, diff.NewConfig(), 1, 3).PathsDiff.Modified["/subscribe"].OperationsDiff.Modified["POST"].CallbacksDiff.Modified["myEvent"].Modified["hi"].OperationsDiff.Modified["POST"].RequestBodyDiff.ContentDiff.MediaTypeModified["application/json"].EncodingsDiff.Deleted, -// "historyMetadata") -// } +func TestDiff_DeletedEncoding(t *testing.T) { + require.Contains(t, + d(t, diff.NewConfig(), 1, 3).PathsDiff.Modified["/subscribe"].OperationsDiff.Modified["POST"].CallbacksDiff.Modified["myEvent"].Modified["hi"].OperationsDiff.Modified["POST"].RequestBodyDiff.ContentDiff.MediaTypeModified["application/json"].EncodingsDiff.Deleted, + "historyMetadata") +} func TestDiff_ModifiedEncodingHeaders(t *testing.T) { require.NotNil(t, diff --git a/diff/patch_error_test.go b/diff/patch_error_test.go index afcad1da..f14977cf 100644 --- a/diff/patch_error_test.go +++ b/diff/patch_error_test.go @@ -18,7 +18,7 @@ func TestPatch_StringTypeMismatch_Nil(t *testing.T) { d1.PathsDiff.Modified["/api/{domain}/{project}/install-command"].OperationsDiff.Modified["GET"].ParametersDiff.Modified["path"]["domain"].SchemaDiff.DescriptionDiff.To = nil - // require.EqualError(t, d1.Patch(s1), "diff value is nil instead of string") + require.EqualError(t, d1.Patch(s1), "diff value is nil instead of string") } func TestPatch_StringTypeMismatch_Int(t *testing.T) { @@ -32,7 +32,7 @@ func TestPatch_StringTypeMismatch_Int(t *testing.T) { d1.PathsDiff.Modified["/api/{domain}/{project}/install-command"].OperationsDiff.Modified["GET"].ParametersDiff.Modified["path"]["domain"].SchemaDiff.DescriptionDiff.To = 4 - // require.EqualError(t, d1.Patch(s1), "diff value type mismatch: string vs. \"int\"") + require.EqualError(t, d1.Patch(s1), "diff value type mismatch: string vs. \"int\"") } func TestPatch_UINT64TypeMismatch(t *testing.T) { @@ -47,5 +47,5 @@ func TestPatch_UINT64TypeMismatch(t *testing.T) { d1.PathsDiff.Modified["/api/{domain}/{project}/install-command"].OperationsDiff.Modified["GET"].ParametersDiff.Modified["path"]["domain"].SchemaDiff.MaxLengthDiff.To = 13 - // require.EqualError(t, d1.Patch(s1), "diff value type mismatch: uint64 vs. \"int\"") + require.EqualError(t, d1.Patch(s1), "diff value type mismatch: uint64 vs. \"int\"") } From e44eab832ab0946c4a543f37a25362963db689d2 Mon Sep 17 00:00:00 2001 From: Reuven Date: Fri, 1 Dec 2023 09:41:57 +0200 Subject: [PATCH 8/9] responseBodiesToResponses in diff --- diff/components_diff.go | 3 +-- diff/responses_diff.go | 8 ++++++++ flatten/merge_allof_spec.go | 23 ++++++++++++++++++++--- utils/openapi_convertors.go | 11 ----------- 4 files changed, 29 insertions(+), 16 deletions(-) delete mode 100644 utils/openapi_convertors.go diff --git a/diff/components_diff.go b/diff/components_diff.go index 9a3cddb3..5ddd5fe5 100644 --- a/diff/components_diff.go +++ b/diff/components_diff.go @@ -2,7 +2,6 @@ package diff import ( "github.com/getkin/kin-openapi/openapi3" - "github.com/tufin/oasdiff/utils" ) // ComponentsDiff describes the changes between a pair of component objects: https://swagger.io/specification/#components-object @@ -52,7 +51,7 @@ func getComponentsDiffInternal(config *Config, state *state, s1, s2 openapi3.Com return result, err } - result.ResponsesDiff, err = getResponsesDiff(config, state, utils.ResponseBodiesToResponses(s1.Responses), utils.ResponseBodiesToResponses(s2.Responses)) + result.ResponsesDiff, err = getResponsesDiff(config, state, responseBodiesToResponses(s1.Responses), responseBodiesToResponses(s2.Responses)) if err != nil { return result, err } diff --git a/diff/responses_diff.go b/diff/responses_diff.go index 05b627b0..9bf35c1c 100644 --- a/diff/responses_diff.go +++ b/diff/responses_diff.go @@ -106,3 +106,11 @@ func (responsesDiff *ResponsesDiff) getSummary() *SummaryDetails { Modified: len(responsesDiff.Modified), } } + +func responseBodiesToResponses(responseBodies openapi3.ResponseBodies) *openapi3.Responses { + result := openapi3.NewResponsesWithCapacity(len(responseBodies)) + for k, v := range responseBodies { + result.Set(k, v) + } + return result +} diff --git a/flatten/merge_allof_spec.go b/flatten/merge_allof_spec.go index d452c971..fd1a357c 100644 --- a/flatten/merge_allof_spec.go +++ b/flatten/merge_allof_spec.go @@ -45,9 +45,9 @@ func mergeComponents(components *openapi3.Components) error { return err } - // if components.Responses, err = mergeResponses(utils.ReponseeBodiesToResponses(components.Responses)); err != nil { - // return err - // } + if components.Responses, err = mergeResponseBodies(components.Responses); err != nil { + return err + } if components.Callbacks, err = mergeCallbacks(components.Callbacks); err != nil { return err @@ -129,6 +129,23 @@ func mergeSchemas(schemas openapi3.Schemas) (openapi3.Schemas, error) { return schemas, nil } +func mergeResponseBodies(responseBodies openapi3.ResponseBodies) (openapi3.ResponseBodies, error) { + for _, v := range responseBodies { + if v == nil || v.Value == nil { + continue + } + content, err := mergeContent(v.Value.Content) + if err != nil { + return responseBodies, err + } + v.Value.Content = content + if _, err := mergeHeaders(v.Value.Headers); err != nil { + return responseBodies, err + } + } + return responseBodies, nil +} + func mergeResponses(responses *openapi3.Responses) (*openapi3.Responses, error) { for _, v := range responses.Map() { if v == nil || v.Value == nil { diff --git a/utils/openapi_convertors.go b/utils/openapi_convertors.go deleted file mode 100644 index 7a04966e..00000000 --- a/utils/openapi_convertors.go +++ /dev/null @@ -1,11 +0,0 @@ -package utils - -import "github.com/getkin/kin-openapi/openapi3" - -func ResponseBodiesToResponses(responseBodies openapi3.ResponseBodies) *openapi3.Responses { - result := openapi3.NewResponsesWithCapacity(len(responseBodies)) - for k, v := range responseBodies { - result.Set(k, v) - } - return result -} From cbe4c80242ffab5a91ae2d24013714f5721aaf1e Mon Sep 17 00:00:00 2001 From: Reuven Date: Fri, 1 Dec 2023 09:43:38 +0200 Subject: [PATCH 9/9] regen breaking changes doc --- BREAKING-CHANGES-EXAMPLES.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/BREAKING-CHANGES-EXAMPLES.md b/BREAKING-CHANGES-EXAMPLES.md index 36d7f275..7ce6b8d7 100644 --- a/BREAKING-CHANGES-EXAMPLES.md +++ b/BREAKING-CHANGES-EXAMPLES.md @@ -40,7 +40,7 @@ These examples are automatically generated from unit tests. [deleting a media-type from response is breaking](checker/checker_breaking_test.go?plain=1#L428) [deleting a non-required non-write-only property in response body is breaking with warning](checker/checker_breaking_property_test.go?plain=1#L511) [deleting a path is breaking](checker/checker_breaking_test.go?plain=1#L43) -[deleting a path with some operations having sunset date in the future is breaking](checker/checker_deprecation_test.go?plain=1#L275) +[deleting a path with some operations having sunset date in the future is breaking](checker/checker_deprecation_test.go?plain=1#L271) [deleting a required property in request is breaking with warn](checker/checker_breaking_property_test.go?plain=1#L368) [deleting a required property in response body is breaking](checker/checker_breaking_property_test.go?plain=1#L420) [deleting a required property under AllOf in response body is breaking](checker/checker_breaking_property_test.go?plain=1#L450) @@ -49,8 +49,8 @@ These examples are automatically generated from unit tests. [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 without sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L50) -[deleting sunset header for a deprecated endpoint is breaking](checker/checker_deprecation_test.go?plain=1#L292) -[deprecating an operation with a deprecation policy and sunset date before required deprecation period is breaking](checker/checker_deprecation_test.go?plain=1#L220) +[deleting sunset header for a deprecated endpoint is breaking](checker/checker_deprecation_test.go?plain=1#L288) +[deprecating an operation with a deprecation policy and sunset date before required deprecation period is breaking](checker/checker_deprecation_test.go?plain=1#L216) [deprecating an operation with a deprecation policy but without specifying sunset date is breaking](checker/checker_deprecation_test.go?plain=1#L82) [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) @@ -76,8 +76,8 @@ These examples are automatically generated from unit tests. [removing an existing response with successful status is breaking](checker/checker_breaking_test.go?plain=1#L245) [removing an schema object from components is breaking (optional)](checker/checker_breaking_test.go?plain=1#L609) [removing the default value of an optional request parameter is breaking](checker/checker_breaking_test.go?plain=1#L572) -[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#L137) -[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#L193) +[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#L135) +[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#L189) [removing/updating a property enum in response is breaking (optional)](checker/checker_breaking_test.go?plain=1#L323) [removing/updating a tag is breaking (optional)](checker/checker_breaking_test.go?plain=1#L340) [removing/updating an enum in request body is breaking (optional)](checker/checker_breaking_test.go?plain=1#L301) @@ -90,11 +90,11 @@ These examples are automatically generated from unit tests. [adding a new required property under AllOf in response body is not breaking](checker/checker_breaking_property_test.go?plain=1#L436) [adding a new required read-only property in request body is not breaking](checker/checker_breaking_property_test.go?plain=1#L466) [adding a non-existent required property in request body is not breaking](checker/checker_breaking_property_test.go?plain=1#L294) -[adding a required property to response is not breaking](checker/checker_not_breaking_test.go?plain=1#L292) -[adding a tag is not breaking](checker/checker_not_breaking_test.go?plain=1#L269) +[adding a required property to response is not breaking](checker/checker_not_breaking_test.go?plain=1#L290) +[adding a tag is not breaking](checker/checker_not_breaking_test.go?plain=1#L267) [adding an enum value is not breaking](checker/checker_not_breaking_test.go?plain=1#L83) [adding an enum value to request body is not breaking](checker/checker_breaking_property_test.go?plain=1#L138) -[adding an operation ID is not breaking](checker/checker_not_breaking_test.go?plain=1#L280) +[adding an operation ID is not breaking](checker/checker_not_breaking_test.go?plain=1#L278) [adding an optional request body is not breaking](checker/checker_not_breaking_test.go?plain=1#L38) [both max lengths in request are nil is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L178) [both max lengths in response are nil is not breaking](checker/checker_breaking_min_max_test.go?plain=1#L192) @@ -113,17 +113,17 @@ These examples are automatically generated from unit tests. [changing request's body schema type from integer to number is not breaking](checker/checker_breaking_request_type_changed_test.go?plain=1#L71) [changing response's body schema type from number to integer is not breaking](checker/checker_breaking_response_type_changed_test.go?plain=1#L51) [changing response's body schema type from number/none to integer/int32 is not breaking](checker/checker_breaking_response_type_changed_test.go?plain=1#L89) -[changing servers is not breaking](checker/checker_not_breaking_test.go?plain=1#L255) -[deleting a path after sunset date of all contained operations is not breaking](checker/checker_deprecation_test.go?plain=1#L260) +[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#L256) [deleting a pattern from a schema is not breaking](checker/checker_breaking_test.go?plain=1#L444) [deleting a required write-only property in response body is not breaking](checker/checker_breaking_property_test.go?plain=1#L494) [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#L67) -[deprecating a header is not breaking](checker/checker_not_breaking_test.go?plain=1#L229) -[deprecating a parameter is not breaking](checker/checker_not_breaking_test.go?plain=1#L216) -[deprecating a schema is not breaking](checker/checker_not_breaking_test.go?plain=1#L242) -[deprecating an operation with a deprecation policy and sunset date after required deprecation period is not breaking](checker/checker_deprecation_test.go?plain=1#L239) -[deprecating an operation without a deprecation policy and without specifying sunset date is not breaking for draft level](checker/checker_deprecation_test.go?plain=1#L155) +[deprecating a header is not breaking](checker/checker_not_breaking_test.go?plain=1#L227) +[deprecating a parameter is not breaking](checker/checker_not_breaking_test.go?plain=1#L214) +[deprecating a schema is not breaking](checker/checker_not_breaking_test.go?plain=1#L240) +[deprecating an operation with a deprecation policy and sunset date after required deprecation period is not breaking](checker/checker_deprecation_test.go?plain=1#L235) +[deprecating an operation without a deprecation policy and without specifying sunset date is not breaking for draft level](checker/checker_deprecation_test.go?plain=1#L153) [deprecating an operation without a deprecation policy and without specifying sunset date is not breaking](checker/checker_deprecation_test.go?plain=1#L101) [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) @@ -140,7 +140,7 @@ These examples are automatically generated from unit tests. [removing an existing response with error status is not breaking](checker/checker_breaking_test.go?plain=1#L393) [removing an existing response with unparseable status is not breaking](checker/checker_breaking_test.go?plain=1#L377) [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#L116) -[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#L172) +[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#L170) [renaming a path parameter is not breaking](checker/checker_breaking_test.go?plain=1#L135) ## Examples of info-level changes for changelog @@ -270,8 +270,8 @@ These examples are automatically generated from unit tests. [increasing request property maximum value](checker/check-request-property-max-updated_test.go?plain=1#L37) [new header, query and cookie request params](checker/check-new-request-non-path-parameter_test.go?plain=1#L11) [new paths or path operations](checker/check-api-added_test.go?plain=1#L11) -[path operations that became deprecated](checker/checker_deprecation_test.go?plain=1#L326) -[path operations that were re-activated](checker/checker_deprecation_test.go?plain=1#L348) +[path operations that became deprecated](checker/checker_deprecation_test.go?plain=1#L322) +[path operations that were re-activated](checker/checker_deprecation_test.go?plain=1#L344) [removing 'allOf' subschema from the request body or request body property](checker/check-request-property-all-of-updated_test.go?plain=1#L45) [removing 'allOf' subschema from the response body or response body property](checker/check-response-property-all-of-updated_test.go?plain=1#L45) [removing 'anyOf' schema from the request body or request body property](checker/check-request-property-any-of-updated_test.go?plain=1#L45)