From bfcb84708ead9a29093dce4d9634f2e14dd2dfa3 Mon Sep 17 00:00:00 2001 From: Reuven Harrison Date: Sun, 13 Oct 2024 17:26:47 +0300 Subject: [PATCH] avoid errors on draft/alpha endpoints --- checker/check_api_removed.go | 5 +++++ checker/check_api_removed_test.go | 24 +++++++--------------- data/deprecation/base-draft-stability.yaml | 15 ++++++++++++++ docs/BREAKING-CHANGES-EXAMPLES.md | 9 ++++---- 4 files changed, 31 insertions(+), 22 deletions(-) create mode 100644 data/deprecation/base-draft-stability.yaml diff --git a/checker/check_api_removed.go b/checker/check_api_removed.go index 3b6dadb2..8bdfd3ee 100644 --- a/checker/check_api_removed.go +++ b/checker/check_api_removed.go @@ -39,6 +39,11 @@ func checkRemovedPaths(pathsDiff *diff.PathsDiff, operationsSources *diff.Operat for operation := range pathsDiff.Base.Value(path).Operations() { op := pathsDiff.Base.Value(path).GetOperation(operation) + stability, err := getStabilityLevel(op.Extensions) + if err != nil || stability == STABILITY_ALPHA || stability == STABILITY_DRAFT { + continue + } + if change := checkAPIRemoval(config, true, op, operationsSources, operation, path); change != nil { result = append(result, change) } diff --git a/checker/check_api_removed_test.go b/checker/check_api_removed_test.go index a019999d..f30fd461 100644 --- a/checker/check_api_removed_test.go +++ b/checker/check_api_removed_test.go @@ -44,46 +44,36 @@ func TestBreaking_DeprecationNoSunset(t *testing.T) { require.Equal(t, checker.INFO, errs[0].GetLevel()) } -// BC: removing the path without a deprecation policy and without specifying sunset date is breaking if some APIs are not alpha stability level +// BC: removing the path without a deprecation policy and without specifying sunset date is breaking for endpoints with non draft/alpha stability level func TestBreaking_RemovedPathForAlphaBreaking(t *testing.T) { s1, err := open(getDeprecationFile("base-alpha-stability.yaml")) require.NoError(t, err) - s2, err := open(getDeprecationFile("base-alpha-stability.yaml")) + s2, err := open(getDeprecationFile("sunset-path.yaml")) require.NoError(t, err) - s2.Spec.Paths.Delete("/api/test") - d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIRemovedCheck), d, osm) - require.Len(t, errs, 2) + require.Len(t, errs, 1) require.Equal(t, checker.APIPathRemovedWithoutDeprecationId, errs[0].GetId()) require.Equal(t, "api path removed without deprecation", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer())) - require.Equal(t, checker.APIPathRemovedWithoutDeprecationId, errs[1].GetId()) - require.Equal(t, "api path removed without deprecation", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer())) } -// BC: removing the path without a deprecation policy and without specifying sunset date is breaking if some APIs are not draft stability level +// BC: removing the path without a deprecation policy and without specifying sunset date is breaking for endpoints with non draft/alpha stability level func TestBreaking_RemovedPathForDraftBreaking(t *testing.T) { - s1, err := open(getDeprecationFile("base-alpha-stability.yaml")) + s1, err := open(getDeprecationFile("base-draft-stability.yaml")) require.NoError(t, err) - draft := toJson(t, checker.STABILITY_DRAFT) - s1.Spec.Paths.Value("/api/test").Get.Extensions["x-stability-level"] = draft - s2, err := open(getDeprecationFile("base-alpha-stability.yaml")) + s2, err := open(getDeprecationFile("sunset-path.yaml")) require.NoError(t, err) - s2.Spec.Paths.Delete("/api/test") - d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.APIRemovedCheck), d, osm) - require.Len(t, errs, 2) + require.Len(t, errs, 1) require.Equal(t, checker.APIPathRemovedWithoutDeprecationId, errs[0].GetId()) require.Equal(t, "api path removed without deprecation", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer())) - require.Equal(t, checker.APIPathRemovedWithoutDeprecationId, errs[1].GetId()) - require.Equal(t, "api path removed without deprecation", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer())) } // BC: deleting a path with some operations having sunset date in the future is breaking diff --git a/data/deprecation/base-draft-stability.yaml b/data/deprecation/base-draft-stability.yaml new file mode 100644 index 00000000..be10d55a --- /dev/null +++ b/data/deprecation/base-draft-stability.yaml @@ -0,0 +1,15 @@ +info: + title: Tufin + version: 1.0.0 +openapi: 3.0.3 +paths: + /api/test: + post: + responses: + 201: + description: OK + get: + x-stability-level: draft + responses: + 200: + description: OK diff --git a/docs/BREAKING-CHANGES-EXAMPLES.md b/docs/BREAKING-CHANGES-EXAMPLES.md index 228ee97a..67bdd39a 100644 --- a/docs/BREAKING-CHANGES-EXAMPLES.md +++ b/docs/BREAKING-CHANGES-EXAMPLES.md @@ -50,7 +50,7 @@ These examples are automatically generated from unit tests. [deleting a media-type from response is breaking](../checker/check_breaking_test.go?plain=1#L442) [deleting a non-required non-write-only property in response body is breaking with warning](../checker/check_breaking_property_test.go?plain=1#L512) [deleting a path is breaking](../checker/check_breaking_test.go?plain=1#L37) -[deleting a path with some operations having sunset date in the future is breaking](../checker/check_api_removed_test.go?plain=1#L89) +[deleting a path with some operations having sunset date in the future is breaking](../checker/check_api_removed_test.go?plain=1#L79) [deleting a required property in request is breaking with warn](../checker/check_breaking_property_test.go?plain=1#L369) [deleting a required property in response body is breaking](../checker/check_breaking_property_test.go?plain=1#L421) [deleting a required property under AllOf in response body is breaking](../checker/check_breaking_property_test.go?plain=1#L451) @@ -80,7 +80,7 @@ These examples are automatically generated from unit tests. [removing 'allOf' subschema from the request body or request body property is breaking with warn](../checker/check_breaking_test.go?plain=1#L749) [removing 'anyOf' schema from the request body or request body property is breaking](../checker/check_breaking_test.go?plain=1#L684) [removing 'oneOf' schema from the request body or request body property is breaking](../checker/check_breaking_test.go?plain=1#L706) -[removing a deprecated enpoint with an invalid date is breaking](../checker/check_api_removed_test.go?plain=1#L130) +[removing a deprecated enpoint with an invalid date is breaking](../checker/check_api_removed_test.go?plain=1#L120) [removing a media type from request body is breaking](../checker/check_breaking_test.go?plain=1#L668) [removing a success status is breaking](../checker/check_response_status_updated_test.go?plain=1#L87) [removing an existing optional response header is breaking as warn](../checker/check_breaking_test.go?plain=1#L422) @@ -89,8 +89,7 @@ These examples are automatically generated from unit tests. [removing an existing response with successful status is breaking](../checker/check_breaking_test.go?plain=1#L251) [removing an schema object from components is breaking (optional)](../checker/check_breaking_test.go?plain=1#L643) [removing the default value of an optional request parameter is breaking](../checker/check_breaking_test.go?plain=1#L606) -[removing the path without a deprecation policy and without specifying sunset date is breaking if some APIs are not alpha stability level](../checker/check_api_removed_test.go?plain=1#L47) -[removing the path without a deprecation policy and without specifying sunset date is breaking if some APIs are not draft stability level](../checker/check_api_removed_test.go?plain=1#L67) +[removing the path without a deprecation policy and without specifying sunset date is breaking for endpoints with non draft/alpha stability level](../checker/check_api_removed_test.go?plain=1#L47) [removing/updating a property enum in response is breaking (optional)](../checker/check_breaking_test.go?plain=1#L333) [removing/updating a tag is breaking (optional)](../checker/check_breaking_test.go?plain=1#L351) [removing/updating an enum in request body is breaking (optional)](../checker/check_breaking_test.go?plain=1#L310) @@ -134,7 +133,7 @@ These examples are automatically generated from unit tests. [changing servers is not breaking](../checker/check_not_breaking_test.go?plain=1#L252) [deleting a deprecated operation without sunset date is not breaking](../checker/check_api_removed_test.go?plain=1#L29) [deleting a path after sunset date of all contained operations is not breaking](../checker/check_api_deprecation_test.go?plain=1#L255) -[deleting a path with deprecated operations without sunset date is not breaking](../checker/check_api_removed_test.go?plain=1#L107) +[deleting a path with deprecated operations without sunset date is not breaking](../checker/check_api_removed_test.go?plain=1#L97) [deleting a pattern from a schema is not breaking](../checker/check_breaking_test.go?plain=1#L459) [deleting a required write-only property in response body is not breaking](../checker/check_breaking_property_test.go?plain=1#L495) [deleting a tag is not breaking](../checker/check_not_breaking_test.go?plain=1#L71)