From 2a50ce016d23694be8703a49e5dab0a108859ac0 Mon Sep 17 00:00:00 2001 From: Reuven Harrison Date: Thu, 4 Jul 2024 12:39:39 +0300 Subject: [PATCH] change constructors (#569) --- checker/api_change.go | 15 ++++ checker/check_added_required_request_body.go | 20 ++--- checker/check_api_added.go | 21 ++--- checker/check_api_deprecation.go | 76 ++++++++--------- checker/check_api_operation_id_updated.go | 22 +++-- checker/check_api_security_updated.go | 81 ++++++++++--------- checker/check_api_sunset_changed.go | 37 +++++---- checker/check_api_tag_updated.go | 41 +++++----- ..._new_request_non_path_default_parameter.go | 20 ++--- .../check_new_request_non_path_parameter.go | 22 +++-- ...ck_new_requried_request_header_property.go | 21 +++-- checker/check_request_body_became_enum.go | 21 +++-- checker/check_request_body_enum_deleted.go | 21 +++-- .../check_request_body_mediatype_updated.go | 40 ++++----- ...eck_request_body_required_value_updated.go | 21 +++-- .../check_request_discriminator_updated.go | 21 +++-- ...eck_request_header_property_became_enum.go | 40 ++++----- ...request_header_property_became_required.go | 40 ++++----- .../check_request_parameter_became_enum.go | 21 +++-- ...ck_request_parameter_enum_value_updated.go | 40 ++++----- ...uest_parameter_pattern_added_or_changed.go | 61 +++++++------- checker/check_request_parameter_removed.go | 21 +++-- ...equest_parameter_required_value_updated.go | 21 +++-- ...rameter_x_extensible_enum_value_removed.go | 61 +++++--------- ...er_x_extensible_enum_value_removed_test.go | 24 ++++++ ...equest_parameters_default_value_changed.go | 21 +++-- ...ck_request_parameters_max_items_updated.go | 22 +++-- ...check_request_parameters_max_length_set.go | 23 +++--- ..._request_parameters_max_length_set_test.go | 32 ++++++++ ...k_request_parameters_max_length_updated.go | 22 +++-- checker/check_request_parameters_max_set.go | 23 +++--- .../check_request_parameters_max_updated.go | 22 +++-- .../check_request_parameters_min_items_set.go | 22 +++-- ...ck_request_parameters_min_items_updated.go | 22 +++-- ...k_request_parameters_min_length_updated.go | 22 +++-- checker/check_request_parameters_min_set.go | 23 +++--- .../check_request_parameters_min_updated.go | 22 +++-- .../check_request_parameters_type_changed.go | 41 +++++----- checker/check_request_path_parameter_added.go | 21 +++-- .../check_request_property_all_of_updated.go | 79 +++++++++--------- .../check_request_property_any_of_updated.go | 78 +++++++++--------- checker/check_request_property_became_enum.go | 21 +++-- ...k_request_property_became_not_nuallable.go | 80 +++++++++--------- ..._request_property_default_value_changed.go | 21 +++-- ...eck_request_property_enum_value_updated.go | 40 ++++----- .../check_request_property_max_length_set.go | 42 +++++----- ...ck_request_property_max_length_set_test.go | 56 +++++++++++++ ...eck_request_property_max_length_updated.go | 78 +++++++++--------- checker/check_request_property_max_set.go | 42 +++++----- .../check_request_property_max_set_test.go | 56 +++++++++++++ checker/check_request_property_max_updated.go | 78 +++++++++--------- ...ck_request_property_min_items_increased.go | 40 ++++----- .../check_request_property_min_items_set.go | 42 +++++----- ...eck_request_property_min_length_updated.go | 78 +++++++++--------- checker/check_request_property_min_set.go | 42 +++++----- checker/check_request_property_min_updated.go | 78 +++++++++--------- .../check_request_property_one_of_updated.go | 78 +++++++++--------- ...quest_property_pattern_added_or_changed.go | 61 +++++++------- ...check_request_property_required_updated.go | 59 +++++++------- .../check_request_property_type_changed.go | 40 ++++----- checker/check_request_property_updated.go | 80 +++++++++--------- ...k_request_property_write_only_read_only.go | 78 +++++++++--------- ...roperty_x_extensible_enum_value_removed.go | 61 +++++--------- ...ty_x_extensible_enum_value_removed_test.go | 24 ++++++ .../check_response_discriminator_updated.go | 21 +++-- .../check_response_header_became_optional.go | 21 +++-- checker/check_response_header_removed.go | 40 ++++----- ...k_response_mediatype_enum_value_removed.go | 21 +++-- checker/check_response_mediatype_updated.go | 40 ++++----- ...heck_response_optional_property_updated.go | 40 ++++----- ..._optional_property_write_only_read_only.go | 40 ++++----- ...check_response_pattern_added_or_changed.go | 21 +++-- .../check_response_property_all_of_updated.go | 78 +++++++++--------- .../check_response_property_any_of_updated.go | 79 +++++++++--------- ...heck_response_property_became_nuallable.go | 39 ++++----- ...check_response_property_became_optional.go | 40 ++++----- ...check_response_property_became_required.go | 40 ++++----- ...response_property_default_value_changed.go | 21 +++-- ...heck_response_property_enum_value_added.go | 22 +++-- ...ck_response_property_enum_value_removed.go | 21 +++-- .../check_response_property_max_increased.go | 40 ++++----- ..._response_property_max_length_increased.go | 40 ++++----- ...heck_response_property_max_length_unset.go | 40 ++++----- .../check_response_property_min_decreased.go | 40 ++++----- ...k_response_property_min_items_decreased.go | 40 ++++----- ...check_response_property_min_items_unset.go | 40 ++++----- ..._response_property_min_length_decreased.go | 40 ++++----- .../check_response_property_one_of_updated.go | 78 +++++++++--------- .../check_response_property_type_changed.go | 40 ++++----- ...heck_response_required_property_updated.go | 40 ++++----- ..._required_property_write_only_read_only.go | 41 +++++----- checker/check_response_status_updated.go | 40 ++++----- checker/checker.go | 21 ++--- checker/localizations/localizations.go | 6 +- checker/localizations_src/en/messages.yaml | 4 - checker/rules.go | 4 - .../request_body_max_length_set_base.yaml | 16 ++++ .../request_body_max_length_set_revision.yaml | 17 ++++ data/checker/request_body_max_set_base.yaml | 16 ++++ .../request_body_max_set_revision.yaml | 17 ++++ ...equest_parameter_extensible_enum_base.yaml | 60 ++++++++++++++ ...st_parameter_extensible_enum_revision.yaml | 59 ++++++++++++++ ...request_parameter_max_length_set_base.yaml | 15 ++++ ...est_parameter_max_length_set_revision.yaml | 16 ++++ ...request_property_extensible_enum_base.yaml | 24 ++++++ ...est_property_extensible_enum_revision.yaml | 23 ++++++ .../request_property_max_length_set_base.yaml | 22 +++++ ...uest_property_max_length_set_revision.yaml | 23 ++++++ .../request_property_max_set_base.yaml | 22 +++++ .../request_property_max_set_revision.yaml | 23 ++++++ docs/BREAKING-CHANGES-EXAMPLES.md | 7 ++ 111 files changed, 2294 insertions(+), 1803 deletions(-) create mode 100644 checker/check_request_parameter_x_extensible_enum_value_removed_test.go create mode 100644 checker/check_request_parameters_max_length_set_test.go create mode 100644 checker/check_request_property_max_length_set_test.go create mode 100644 checker/check_request_property_max_set_test.go create mode 100644 checker/check_request_property_x_extensible_enum_value_removed_test.go create mode 100644 data/checker/request_body_max_length_set_base.yaml create mode 100644 data/checker/request_body_max_length_set_revision.yaml create mode 100644 data/checker/request_body_max_set_base.yaml create mode 100644 data/checker/request_body_max_set_revision.yaml create mode 100644 data/checker/request_parameter_extensible_enum_base.yaml create mode 100644 data/checker/request_parameter_extensible_enum_revision.yaml create mode 100644 data/checker/request_parameter_max_length_set_base.yaml create mode 100644 data/checker/request_parameter_max_length_set_revision.yaml create mode 100644 data/checker/request_property_extensible_enum_base.yaml create mode 100644 data/checker/request_property_extensible_enum_revision.yaml create mode 100644 data/checker/request_property_max_length_set_base.yaml create mode 100644 data/checker/request_property_max_length_set_revision.yaml create mode 100644 data/checker/request_property_max_set_base.yaml create mode 100644 data/checker/request_property_max_set_revision.yaml diff --git a/checker/api_change.go b/checker/api_change.go index 6a0b507c..50035e8c 100644 --- a/checker/api_change.go +++ b/checker/api_change.go @@ -5,6 +5,8 @@ import ( "strings" "github.com/TwiN/go-color" + "github.com/getkin/kin-openapi/openapi3" + "github.com/tufin/oasdiff/diff" "github.com/tufin/oasdiff/load" ) @@ -26,6 +28,19 @@ type ApiChange struct { SourceColumnEnd int } +func NewApiChange(id string, level Level, args []any, comment string, operationsSources *diff.OperationsSourcesMap, operation *openapi3.Operation, method, path string) ApiChange { + return ApiChange{ + Id: id, + Level: level, + Args: args, + Comment: comment, + OperationId: operation.OperationID, + Operation: method, + Path: path, + Source: load.NewSource((*operationsSources)[operation]), + } +} + func (c ApiChange) GetSection() string { return "paths" } diff --git a/checker/check_added_required_request_body.go b/checker/check_added_required_request_body.go index 734b0d5f..447facb4 100644 --- a/checker/check_added_required_request_body.go +++ b/checker/check_added_required_request_body.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -32,15 +31,16 @@ func AddedRequestBodyCheck(diffReport *diff.Diff, operationsSources *diff.Operat logLevel = ERR } - source := (*operationsSources)[operationItem.Revision] - result = append(result, ApiChange{ - Id: id, - Level: logLevel, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + logLevel, + nil, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_api_added.go b/checker/check_api_added.go index d0f4e40c..efebb391 100644 --- a/checker/check_api_added.go +++ b/checker/check_api_added.go @@ -3,7 +3,6 @@ package checker import ( "github.com/getkin/kin-openapi/openapi3" "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -16,15 +15,17 @@ func APIAddedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSour return result } - appendErr := func(path, opName string, opConfig *openapi3.Operation) { - result = append(result, ApiChange{ - Id: EndpointAddedId, - Level: INFO, - Operation: opName, - OperationId: opConfig.OperationID, - Path: path, - Source: load.NewSource((*operationsSources)[opConfig]), - }) + appendErr := func(path, method string, operation *openapi3.Operation) { + result = append(result, NewApiChange( + EndpointAddedId, + INFO, + nil, + "", + operationsSources, + operation, + method, + path, + )) } for _, path := range diffReport.PathsDiff.Added { diff --git a/checker/check_api_deprecation.go b/checker/check_api_deprecation.go index ce8776e4..ca82b81b 100644 --- a/checker/check_api_deprecation.go +++ b/checker/check_api_deprecation.go @@ -5,7 +5,6 @@ import ( "cloud.google.com/go/civil" "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -29,7 +28,6 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio } for operation, operationDiff := range pathItem.OperationsDiff.Modified { op := pathItem.Revision.GetOperation(operation) - source := (*operationsSources)[op] if operationDiff.DeprecatedDiff == nil { continue @@ -37,14 +35,16 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio if operationDiff.DeprecatedDiff.To == nil || operationDiff.DeprecatedDiff.To == false { // not breaking changes - result = append(result, ApiChange{ - Id: EndpointReactivatedId, - Level: INFO, - Operation: operation, - OperationId: op.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + EndpointReactivatedId, + INFO, + nil, + "", + operationsSources, + op, + operation, + path, + )) continue } @@ -67,42 +67,46 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio date, err := getSunsetDate(sunset) if err != nil { - result = append(result, ApiChange{ - Id: APIDeprecatedSunsetParseId, - Level: ERR, - Args: []any{err}, - Operation: operation, - OperationId: op.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + APIDeprecatedSunsetParseId, + ERR, + []any{err}, + "", + operationsSources, + op, + operation, + path, + )) continue } days := date.DaysSince(civil.DateOf(time.Now())) if days < int(deprecationDays) { - result = append(result, ApiChange{ - Id: APISunsetDateTooSmallId, - Level: ERR, - Args: []any{date, deprecationDays}, - Operation: operation, - OperationId: op.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + APISunsetDateTooSmallId, + ERR, + []any{date, deprecationDays}, + "", + operationsSources, + op, + operation, + path, + )) continue } // not breaking changes - result = append(result, ApiChange{ - Id: EndpointDeprecatedId, - Level: INFO, - Operation: operation, - OperationId: op.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + EndpointDeprecatedId, + INFO, + nil, + "", + operationsSources, + op, + operation, + path, + )) } } diff --git a/checker/check_api_operation_id_updated.go b/checker/check_api_operation_id_updated.go index 6ef8a30d..7fe56a37 100644 --- a/checker/check_api_operation_id_updated.go +++ b/checker/check_api_operation_id_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -27,8 +26,6 @@ func APIOperationIdUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.O } op := pathItem.Base.GetOperation(operation) - source := (*operationsSources)[op] - id := APIOperationIdRemovedId args := []any{operationItem.Base.OperationID, operationItem.Revision.OperationID} if operationItem.OperationIDDiff.From == nil || operationItem.OperationIDDiff.From == "" { @@ -37,15 +34,16 @@ func APIOperationIdUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.O args = []any{operationItem.Revision.OperationID} } - result = append(result, ApiChange{ - Id: id, - Level: config.getLogLevel(id, INFO), - Args: args, - Operation: operation, - OperationId: op.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + config.getLogLevel(id, INFO), + args, + "", + operationsSources, + op, + operation, + path, + )) } } return result diff --git a/checker/check_api_security_updated.go b/checker/check_api_security_updated.go index a8a2c19c..24b2ff6c 100644 --- a/checker/check_api_security_updated.go +++ b/checker/check_api_security_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -76,8 +75,6 @@ func APISecurityUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.Oper } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] - if operationItem.SecurityDiff == nil { continue } @@ -86,30 +83,34 @@ func APISecurityUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.Oper if addedSecurity == "" { continue } - result = append(result, ApiChange{ - Id: APISecurityAddedCheckId, - Level: INFO, - Args: []any{addedSecurity}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + + result = append(result, NewApiChange( + APISecurityAddedCheckId, + INFO, + []any{addedSecurity}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } for _, deletedSecurity := range operationItem.SecurityDiff.Deleted { if deletedSecurity == "" { continue } - result = append(result, ApiChange{ - Id: APISecurityRemovedCheckId, - Level: INFO, - Args: []any{deletedSecurity}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + + result = append(result, NewApiChange( + APISecurityRemovedCheckId, + INFO, + []any{deletedSecurity}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } for _, updatedSecurity := range operationItem.SecurityDiff.Modified { @@ -118,26 +119,28 @@ func APISecurityUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.Oper } for securitySchemeName, updatedSecuritySchemeScopes := range updatedSecurity { for _, addedScope := range updatedSecuritySchemeScopes.Added { - result = append(result, ApiChange{ - Id: APISecurityScopeAddedId, - Level: INFO, - Args: []any{addedScope, securitySchemeName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + APISecurityScopeAddedId, + INFO, + []any{addedScope, securitySchemeName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } for _, deletedScope := range updatedSecuritySchemeScopes.Deleted { - result = append(result, ApiChange{ - Id: APISecurityScopeRemovedId, - Level: INFO, - Args: []any{deletedScope, securitySchemeName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + APISecurityScopeRemovedId, + INFO, + []any{deletedScope, securitySchemeName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_api_sunset_changed.go b/checker/check_api_sunset_changed.go index 47948863..6af2378f 100644 --- a/checker/check_api_sunset_changed.go +++ b/checker/check_api_sunset_changed.go @@ -37,14 +37,16 @@ func APISunsetChangedCheck(diffReport *diff.Diff, operationsSources *diff.Operat } if operationDiff.ExtensionsDiff.Deleted.Contains(diff.SunsetExtension) { - result = append(result, ApiChange{ - Id: APISunsetDeletedId, - Level: ERR, - Operation: operation, - OperationId: opRevision.OperationID, - Path: path, - Source: load.NewSource((*operationsSources)[opRevision]), - }) + result = append(result, NewApiChange( + APISunsetDeletedId, + ERR, + nil, + "", + operationsSources, + opRevision, + operation, + path, + )) continue } @@ -75,15 +77,16 @@ func APISunsetChangedCheck(diffReport *diff.Diff, operationsSources *diff.Operat deprecationDays := getDeprecationDays(config, stability) if baseDate.After(date) && days < int(deprecationDays) { - result = append(result, ApiChange{ - Id: APISunsetDateChangedTooSmallId, - Level: ERR, - Args: []any{baseDate, date, baseDate, deprecationDays}, - Operation: operation, - OperationId: opRevision.OperationID, - Path: path, - Source: load.NewSource((*operationsSources)[opRevision]), - }) + result = append(result, NewApiChange( + APISunsetDateChangedTooSmallId, + ERR, + []any{baseDate, date, baseDate, deprecationDays}, + "", + operationsSources, + opRevision, + operation, + path, + )) } } } diff --git a/checker/check_api_tag_updated.go b/checker/check_api_tag_updated.go index b79574d1..31607ec1 100644 --- a/checker/check_api_tag_updated.go +++ b/checker/check_api_tag_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -23,35 +22,35 @@ func APITagUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.Operation for operation, operationItem := range pathItem.OperationsDiff.Modified { op := pathItem.Base.GetOperation(operation) - source := (*operationsSources)[op] if operationItem.TagsDiff == nil { continue } for _, tag := range operationItem.TagsDiff.Deleted { - result = append(result, ApiChange{ - Id: APITagRemovedId, - Level: config.getLogLevel(APITagRemovedId, INFO), - Args: []any{tag}, - Operation: operation, - OperationId: op.OperationID, - Path: path, - Source: load.NewSource(source), - }) - + result = append(result, NewApiChange( + APITagRemovedId, + config.getLogLevel(APITagRemovedId, INFO), + []any{tag}, + "", + operationsSources, + op, + operation, + path, + )) } for _, tag := range operationItem.TagsDiff.Added { - result = append(result, ApiChange{ - Id: APITagAddedId, - Level: config.getLogLevel(APITagAddedId, INFO), - Args: []any{tag}, - Operation: operation, - OperationId: op.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + APITagAddedId, + config.getLogLevel(APITagAddedId, INFO), + []any{tag}, + "", + operationsSources, + op, + operation, + path, + )) } } } diff --git a/checker/check_new_request_non_path_default_parameter.go b/checker/check_new_request_non_path_default_parameter.go index c5def3dc..61842085 100644 --- a/checker/check_new_request_non_path_default_parameter.go +++ b/checker/check_new_request_non_path_default_parameter.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -40,15 +39,16 @@ func NewRequestNonPathDefaultParameterCheck(diffReport *diff.Diff, operationsSou // TODO: if base operation had this param individually (not through the path) - continue - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{paramLoc, param.Value.Name}, - Operation: operation, - OperationId: operationItem.OperationID, - Path: path, - Source: load.NewSource((*operationsSources)[operationItem]), - }) + result = append(result, NewApiChange( + id, + level, + []any{paramLoc, param.Value.Name}, + "", + operationsSources, + operationItem, + operation, + path, + )) } } } diff --git a/checker/check_new_request_non_path_parameter.go b/checker/check_new_request_non_path_parameter.go index 43960653..f7823de9 100644 --- a/checker/check_new_request_non_path_parameter.go +++ b/checker/check_new_request_non_path_parameter.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -38,17 +37,16 @@ func NewRequestNonPathParameterCheck(diffReport *diff.Diff, operationsSources *d id = NewOptionalRequestParameterId level = INFO } - source := (*operationsSources)[operationItem.Revision] - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{paramLocation, paramName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) - + result = append(result, NewApiChange( + id, + level, + []any{paramLocation, paramName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) break } } diff --git a/checker/check_new_requried_request_header_property.go b/checker/check_new_requried_request_header_property.go index 3f8c085a..467aedb4 100644 --- a/checker/check_new_requried_request_header_property.go +++ b/checker/check_new_requried_request_header_property.go @@ -3,7 +3,6 @@ package checker import ( "github.com/getkin/kin-openapi/openapi3" "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" "golang.org/x/exp/slices" ) @@ -21,7 +20,6 @@ func NewRequiredRequestHeaderPropertyCheck(diffReport *diff.Diff, operationsSour continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ParametersDiff == nil { continue @@ -44,15 +42,16 @@ func NewRequiredRequestHeaderPropertyCheck(diffReport *diff.Diff, operationsSour return } - result = append(result, ApiChange{ - Id: NewRequiredRequestHeaderPropertyId, - Level: ERR, - Args: []any{paramName, propertyFullName(propertyPath, newPropertyName)}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + NewRequiredRequestHeaderPropertyId, + ERR, + []any{paramName, propertyFullName(propertyPath, newPropertyName)}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_request_body_became_enum.go b/checker/check_request_body_became_enum.go index 8913956e..c18ef2fd 100644 --- a/checker/check_request_body_became_enum.go +++ b/checker/check_request_body_became_enum.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -20,8 +19,6 @@ func RequestBodyBecameEnumCheck(diffReport *diff.Diff, operationsSources *diff.O } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] - if operationItem.RequestBodyDiff == nil || operationItem.RequestBodyDiff.ContentDiff == nil || operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { @@ -37,14 +34,16 @@ func RequestBodyBecameEnumCheck(diffReport *diff.Diff, operationsSources *diff.O if schemaDiff := mediaTypeDiff.SchemaDiff; schemaDiff.EnumDiff == nil || !schemaDiff.EnumDiff.EnumAdded { continue } - result = append(result, ApiChange{ - Id: RequestBodyBecameEnumId, - Level: ERR, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyBecameEnumId, + ERR, + nil, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_body_enum_deleted.go b/checker/check_request_body_enum_deleted.go index 885e7bc1..4e29871d 100644 --- a/checker/check_request_body_enum_deleted.go +++ b/checker/check_request_body_enum_deleted.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -31,7 +30,6 @@ func RequestBodyEnumValueRemovedCheck(diffReport *diff.Diff, operationsSources * mediaTypeChanges := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified - source := (*operationsSources)[operationItem.Revision] for _, mediaTypeItem := range mediaTypeChanges { if mediaTypeItem.SchemaDiff == nil { continue @@ -42,15 +40,16 @@ func RequestBodyEnumValueRemovedCheck(diffReport *diff.Diff, operationsSources * continue } for _, enumVal := range enumDiff.Deleted { - result = append(result, ApiChange{ - Id: RequestBodyEnumValueRemovedId, - Level: config.getLogLevel(RequestBodyEnumValueRemovedId, INFO), - Args: []any{enumVal}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyEnumValueRemovedId, + config.getLogLevel(RequestBodyEnumValueRemovedId, INFO), + []any{enumVal}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_body_mediatype_updated.go b/checker/check_request_body_mediatype_updated.go index ee01cb87..7c277312 100644 --- a/checker/check_request_body_mediatype_updated.go +++ b/checker/check_request_body_mediatype_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -25,32 +24,33 @@ func RequestBodyMediaTypeChangedCheck(diffReport *diff.Diff, operationsSources * operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] addedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeAdded for _, mediaType := range addedMediaTypes { - result = append(result, ApiChange{ - Id: RequestBodyMediaTypeAddedId, - Level: INFO, - Args: []any{mediaType}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMediaTypeAddedId, + INFO, + []any{mediaType}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } removedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeDeleted for _, mediaType := range removedMediaTypes { - result = append(result, ApiChange{ - Id: RequestBodyMediaTypeRemovedId, - Level: ERR, - Args: []any{mediaType}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMediaTypeRemovedId, + ERR, + []any{mediaType}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_body_required_value_updated.go b/checker/check_request_body_required_value_updated.go index b7c2f823..380c0f35 100644 --- a/checker/check_request_body_required_value_updated.go +++ b/checker/check_request_body_required_value_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -28,8 +27,6 @@ func RequestBodyRequiredUpdatedCheck(diffReport *diff.Diff, operationsSources *d continue } - source := (*operationsSources)[operationItem.Revision] - id := RequestBodyBecameOptionalId logLevel := INFO if operationItem.RequestBodyDiff.RequiredDiff.To == true { @@ -37,14 +34,16 @@ func RequestBodyRequiredUpdatedCheck(diffReport *diff.Diff, operationsSources *d logLevel = ERR } - result = append(result, ApiChange{ - Id: id, - Level: logLevel, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + logLevel, + nil, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } return result diff --git a/checker/check_request_discriminator_updated.go b/checker/check_request_discriminator_updated.go index e9f366ac..b09483d7 100644 --- a/checker/check_request_discriminator_updated.go +++ b/checker/check_request_discriminator_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -37,18 +36,18 @@ func RequestDiscriminatorUpdatedCheck(diffReport *diff.Diff, operationsSources * operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] appendResultItem := func(messageId string, a ...any) { - result = append(result, ApiChange{ - Id: messageId, - Level: INFO, - Args: a, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + messageId, + INFO, + a, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } for _, mediaTypeDiff := range operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified { diff --git a/checker/check_request_header_property_became_enum.go b/checker/check_request_header_property_became_enum.go index 15bc2246..529caaa0 100644 --- a/checker/check_request_header_property_became_enum.go +++ b/checker/check_request_header_property_became_enum.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -19,7 +18,6 @@ func RequestHeaderPropertyBecameEnumCheck(diffReport *diff.Diff, operationsSourc continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ParametersDiff == nil { continue @@ -37,15 +35,16 @@ func RequestHeaderPropertyBecameEnumCheck(diffReport *diff.Diff, operationsSourc } if paramDiff.SchemaDiff.EnumDiff != nil && paramDiff.SchemaDiff.EnumDiff.EnumAdded { - result = append(result, ApiChange{ - Id: RequestHeaderPropertyBecameEnumId, - Level: ERR, - Args: []any{paramName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestHeaderPropertyBecameEnumId, + ERR, + []any{paramName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } CheckModifiedPropertiesDiff( @@ -56,15 +55,16 @@ func RequestHeaderPropertyBecameEnumCheck(diffReport *diff.Diff, operationsSourc return } - result = append(result, ApiChange{ - Id: RequestHeaderPropertyBecameEnumId, - Level: ERR, - Args: []any{paramName, propertyFullName(propertyPath, propertyName)}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestHeaderPropertyBecameEnumId, + ERR, + []any{paramName, propertyFullName(propertyPath, propertyName)}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_request_header_property_became_required.go b/checker/check_request_header_property_became_required.go index 82701034..30e6d511 100644 --- a/checker/check_request_header_property_became_required.go +++ b/checker/check_request_header_property_became_required.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -19,7 +18,6 @@ func RequestHeaderPropertyBecameRequiredCheck(diffReport *diff.Diff, operationsS continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ParametersDiff == nil { continue @@ -50,15 +48,16 @@ func RequestHeaderPropertyBecameRequiredCheck(diffReport *diff.Diff, operationsS continue } - result = append(result, ApiChange{ - Id: RequestHeaderPropertyBecameRequiredId, - Level: ERR, - Args: []any{paramName, changedRequiredPropertyName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestHeaderPropertyBecameRequiredId, + ERR, + []any{paramName, changedRequiredPropertyName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } @@ -76,15 +75,16 @@ func RequestHeaderPropertyBecameRequiredCheck(diffReport *diff.Diff, operationsS if propertyDiff.Revision.Properties[changedRequiredPropertyName].Value.ReadOnly { continue } - result = append(result, ApiChange{ - Id: RequestHeaderPropertyBecameRequiredId, - Level: ERR, - Args: []any{paramName, propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestHeaderPropertyBecameRequiredId, + ERR, + []any{paramName, propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_request_parameter_became_enum.go b/checker/check_request_parameter_became_enum.go index b5cb3764..d1fa9c63 100644 --- a/checker/check_request_parameter_became_enum.go +++ b/checker/check_request_parameter_became_enum.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -25,7 +24,6 @@ func RequestParameterBecameEnumCheck(diffReport *diff.Diff, operationsSources *d if operationItem.ParametersDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for paramLocation, paramItems := range operationItem.ParametersDiff.Modified { for paramName, paramItem := range paramItems { if paramItem.SchemaDiff == nil { @@ -36,15 +34,16 @@ func RequestParameterBecameEnumCheck(diffReport *diff.Diff, operationsSources *d continue } - result = append(result, ApiChange{ - Id: RequestParameterBecameEnumId, - Level: ERR, - Args: []any{paramLocation, paramName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterBecameEnumId, + ERR, + []any{paramLocation, paramName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameter_enum_value_updated.go b/checker/check_request_parameter_enum_value_updated.go index 59087af3..0f1257f0 100644 --- a/checker/check_request_parameter_enum_value_updated.go +++ b/checker/check_request_parameter_enum_value_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -26,7 +25,6 @@ func RequestParameterEnumValueUpdatedCheck(diffReport *diff.Diff, operationsSour if operationItem.ParametersDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for paramLocation, paramItems := range operationItem.ParametersDiff.Modified { for paramName, paramItem := range paramItems { if paramItem.SchemaDiff == nil { @@ -37,26 +35,28 @@ func RequestParameterEnumValueUpdatedCheck(diffReport *diff.Diff, operationsSour continue } for _, enumVal := range enumDiff.Deleted { - result = append(result, ApiChange{ - Id: RequestParameterEnumValueRemovedId, - Level: ERR, - Args: []any{enumVal, paramLocation, paramName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterEnumValueRemovedId, + ERR, + []any{enumVal, paramLocation, paramName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } for _, enumVal := range enumDiff.Added { - result = append(result, ApiChange{ - Id: RequestParameterEnumValueAddedId, - Level: INFO, - Args: []any{enumVal, paramLocation, paramName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterEnumValueAddedId, + INFO, + []any{enumVal, paramLocation, paramName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameter_pattern_added_or_changed.go b/checker/check_request_parameter_pattern_added_or_changed.go index 0b8f31e7..df144d41 100644 --- a/checker/check_request_parameter_pattern_added_or_changed.go +++ b/checker/check_request_parameter_pattern_added_or_changed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -37,29 +36,29 @@ func RequestParameterPatternAddedOrChangedCheck(diffReport *diff.Diff, operation if patternDiff == nil { continue } - source := (*operationsSources)[operationItem.Revision] if patternDiff.From == "" { - result = append(result, ApiChange{ - Id: RequestParameterPatternAddedId, - Level: WARN, - Args: []any{patternDiff.To, paramLocation, paramName}, - Comment: PatternChangedCommentId, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterPatternAddedId, + WARN, + []any{patternDiff.To, paramLocation, paramName}, + PatternChangedCommentId, + operationsSources, + operationItem.Revision, + operation, + path, + )) } else if patternDiff.To == "" { - result = append(result, ApiChange{ - Id: RequestParameterPatternRemovedId, - Level: INFO, - Args: []any{patternDiff.From, paramLocation, paramName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterPatternRemovedId, + INFO, + []any{patternDiff.From, paramLocation, paramName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { level := WARN comment := PatternChangedCommentId @@ -67,16 +66,16 @@ func RequestParameterPatternAddedOrChangedCheck(diffReport *diff.Diff, operation level = INFO comment = "" } - result = append(result, ApiChange{ - Id: RequestParameterPatternChangedId, - Level: level, - Args: []any{paramLocation, paramName, patternDiff.From, patternDiff.To}, - Comment: comment, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterPatternChangedId, + level, + []any{paramLocation, paramName, patternDiff.From, patternDiff.To}, + comment, + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameter_removed.go b/checker/check_request_parameter_removed.go index 3fd01274..a8199614 100644 --- a/checker/check_request_parameter_removed.go +++ b/checker/check_request_parameter_removed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -24,16 +23,16 @@ func RequestParameterRemovedCheck(diffReport *diff.Diff, operationsSources *diff } for paramLocation, paramItems := range operationItem.ParametersDiff.Deleted { for _, paramName := range paramItems { - source := (*operationsSources)[operationItem.Revision] - result = append(result, ApiChange{ - Id: RequestParameterRemovedId, - Level: WARN, - Args: []any{paramLocation, paramName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterRemovedId, + WARN, + []any{paramLocation, paramName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameter_required_value_updated.go b/checker/check_request_parameter_required_value_updated.go index 1e3a57cb..d98db2ab 100644 --- a/checker/check_request_parameter_required_value_updated.go +++ b/checker/check_request_parameter_required_value_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -41,16 +40,16 @@ func RequestParameterRequiredValueUpdatedCheck(diffReport *diff.Diff, operations level = INFO } - source := (*operationsSources)[operationItem.Revision] - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{paramLocation, paramName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{paramLocation, paramName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameter_x_extensible_enum_value_removed.go b/checker/check_request_parameter_x_extensible_enum_value_removed.go index 06e99556..718f2dfe 100644 --- a/checker/check_request_parameter_x_extensible_enum_value_removed.go +++ b/checker/check_request_parameter_x_extensible_enum_value_removed.go @@ -1,16 +1,11 @@ package checker import ( - "encoding/json" - "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" "golang.org/x/exp/slices" ) const ( - UnparsableParameterFromXExtensibleEnumId = "unparseable-parameter-from-x-extensible-enum" - UnparsableParameterToXExtensibleEnumId = "unparseable-parameter-to-x-extensible-enum" RequestParameterXExtensibleEnumValueRemovedId = "request-parameter-x-extensible-enum-value-removed" ) @@ -30,7 +25,6 @@ func RequestParameterXExtensibleEnumValueRemovedCheck(diffReport *diff.Diff, ope if operationItem.ParametersDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for paramLocation, paramItems := range operationItem.ParametersDiff.Modified { for paramName, paramItem := range paramItems { if paramItem.SchemaDiff == nil { @@ -45,39 +39,23 @@ func RequestParameterXExtensibleEnumValueRemovedCheck(diffReport *diff.Diff, ope if paramItem.SchemaDiff.ExtensionsDiff.Modified[diff.XExtensibleEnumExtension] == nil { continue } - from, ok := paramItem.SchemaDiff.Base.Extensions[diff.XExtensibleEnumExtension].(json.RawMessage) + from, ok := paramItem.SchemaDiff.Base.Extensions[diff.XExtensibleEnumExtension].([]interface{}) if !ok { continue } - to, ok := paramItem.SchemaDiff.Revision.Extensions[diff.XExtensibleEnumExtension].(json.RawMessage) + to, ok := paramItem.SchemaDiff.Revision.Extensions[diff.XExtensibleEnumExtension].([]interface{}) if !ok { continue } - var fromSlice []string - if err := json.Unmarshal(from, &fromSlice); err != nil { - result = append(result, ApiChange{ - Id: UnparsableParameterFromXExtensibleEnumId, - Level: ERR, - Args: []any{paramLocation, paramName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) - continue + + fromSlice := make([]string, len(from)) + for i, item := range from { + fromSlice[i] = item.(string) } - var toSlice []string - if err := json.Unmarshal(to, &toSlice); err != nil { - result = append(result, ApiChange{ - Id: UnparsableParameterToXExtensibleEnumId, - Level: ERR, - Args: []any{paramLocation, paramName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) - continue + + toSlice := make([]string, len(to)) + for i, item := range to { + toSlice[i] = item.(string) } deletedVals := make([]string, 0) @@ -88,15 +66,16 @@ func RequestParameterXExtensibleEnumValueRemovedCheck(diffReport *diff.Diff, ope } for _, enumVal := range deletedVals { - result = append(result, ApiChange{ - Id: RequestParameterXExtensibleEnumValueRemovedId, - Level: ERR, - Args: []any{enumVal, paramLocation, paramName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterXExtensibleEnumValueRemovedId, + ERR, + []any{enumVal, paramLocation, paramName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameter_x_extensible_enum_value_removed_test.go b/checker/check_request_parameter_x_extensible_enum_value_removed_test.go new file mode 100644 index 00000000..c27707b8 --- /dev/null +++ b/checker/check_request_parameter_x_extensible_enum_value_removed_test.go @@ -0,0 +1,24 @@ +package checker_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/tufin/oasdiff/checker" + "github.com/tufin/oasdiff/diff" +) + +// BC: Deleting a value from an x-extensible-enum parameter is breaking +func TestRequestParameterXExtensibleEnumValueRemoved(t *testing.T) { + s1, err := open("../data/checker/request_parameter_extensible_enum_base.yaml") + require.NoError(t, err) + + s2, err := open("../data/checker/request_parameter_extensible_enum_revision.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.RequestParameterXExtensibleEnumValueRemovedCheck), d, osm) + require.Len(t, errs, 1) + require.Equal(t, checker.RequestParameterXExtensibleEnumValueRemovedId, errs[0].GetId()) +} diff --git a/checker/check_request_parameters_default_value_changed.go b/checker/check_request_parameters_default_value_changed.go index 81be4e97..050eacb3 100644 --- a/checker/check_request_parameters_default_value_changed.go +++ b/checker/check_request_parameters_default_value_changed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -24,17 +23,17 @@ func RequestParameterDefaultValueChangedCheck(diffReport *diff.Diff, operationsS if operationItem.ParametersDiff == nil { continue } - source := (*operationsSources)[operationItem.Revision] appendResultItem := func(messageId string, a ...any) { - result = append(result, ApiChange{ - Id: messageId, - Level: ERR, - Args: a, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + messageId, + ERR, + a, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } for paramLocation, paramDiffs := range operationItem.ParametersDiff.Modified { for paramName, paramDiff := range paramDiffs { diff --git a/checker/check_request_parameters_max_items_updated.go b/checker/check_request_parameters_max_items_updated.go index 8bcc5277..3c402ad6 100644 --- a/checker/check_request_parameters_max_items_updated.go +++ b/checker/check_request_parameters_max_items_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -44,17 +43,16 @@ func RequestParameterMaxItemsUpdatedCheck(diffReport *diff.Diff, operationsSourc level = INFO } - source := (*operationsSources)[operationItem.Revision] - - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{paramLocation, paramName, maxItemsDiff.From, maxItemsDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{paramLocation, paramName, maxItemsDiff.From, maxItemsDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameters_max_length_set.go b/checker/check_request_parameters_max_length_set.go index 952d9c7d..5184a005 100644 --- a/checker/check_request_parameters_max_length_set.go +++ b/checker/check_request_parameters_max_length_set.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -36,18 +35,16 @@ func RequestParameterMaxLengthSetCheck(diffReport *diff.Diff, operationsSources continue } - source := (*operationsSources)[operationItem.Revision] - - result = append(result, ApiChange{ - Id: RequestParameterMaxLengthSetId, - Level: WARN, - Args: []any{paramLocation, paramName, maxLengthDiff.To}, - Comment: commentId(RequestParameterMaxLengthSetId), - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterMaxLengthSetId, + WARN, + []any{paramLocation, paramName, maxLengthDiff.To}, + commentId(RequestParameterMaxLengthSetId), + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameters_max_length_set_test.go b/checker/check_request_parameters_max_length_set_test.go new file mode 100644 index 00000000..3cae47c9 --- /dev/null +++ b/checker/check_request_parameters_max_length_set_test.go @@ -0,0 +1,32 @@ +package checker_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/tufin/oasdiff/checker" + "github.com/tufin/oasdiff/diff" + "github.com/tufin/oasdiff/load" +) + +// CL: setting maxLength of request parameters +func TestRequestParameterMaxLengthSetCheck(t *testing.T) { + s1, err := open("../data/checker/request_parameter_max_length_set_base.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/request_parameter_max_length_set_revision.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestParameterMaxLengthSetCheck), d, osm, checker.INFO) + require.Len(t, errs, 1) + require.Equal(t, checker.ApiChange{ + Id: checker.RequestParameterMaxLengthSetId, + Args: []any{"query", "category", uint64(15)}, + Level: checker.WARN, + Comment: checker.RequestParameterMaxLengthSetId + "-comment", + Operation: "POST", + Path: "/test", + Source: load.NewSource("../data/checker/request_parameter_max_length_set_revision.yaml"), + }, errs[0]) +} diff --git a/checker/check_request_parameters_max_length_updated.go b/checker/check_request_parameters_max_length_updated.go index 46efa9f8..5aa709ec 100644 --- a/checker/check_request_parameters_max_length_updated.go +++ b/checker/check_request_parameters_max_length_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -44,17 +43,16 @@ func RequestParameterMaxLengthUpdatedCheck(diffReport *diff.Diff, operationsSour level = INFO } - source := (*operationsSources)[operationItem.Revision] - - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{paramLocation, paramName, maxLengthDiff.From, maxLengthDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{paramLocation, paramName, maxLengthDiff.From, maxLengthDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameters_max_set.go b/checker/check_request_parameters_max_set.go index 5b1d6256..348f8448 100644 --- a/checker/check_request_parameters_max_set.go +++ b/checker/check_request_parameters_max_set.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -36,18 +35,16 @@ func RequestParameterMaxSetCheck(diffReport *diff.Diff, operationsSources *diff. continue } - source := (*operationsSources)[operationItem.Revision] - - result = append(result, ApiChange{ - Id: RequestParameterMaxSetId, - Level: WARN, - Args: []any{paramLocation, paramName, maxDiff.To}, - Comment: commentId(RequestParameterMaxSetId), - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterMaxSetId, + WARN, + []any{paramLocation, paramName, maxDiff.To}, + commentId(RequestParameterMaxSetId), + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameters_max_updated.go b/checker/check_request_parameters_max_updated.go index ae061542..4ea28fd6 100644 --- a/checker/check_request_parameters_max_updated.go +++ b/checker/check_request_parameters_max_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -45,17 +44,16 @@ func RequestParameterMaxUpdatedCheck(diffReport *diff.Diff, operationsSources *d level = INFO } - source := (*operationsSources)[operationItem.Revision] - - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{paramLocation, paramName, maxDiff.From, maxDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{paramLocation, paramName, maxDiff.From, maxDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameters_min_items_set.go b/checker/check_request_parameters_min_items_set.go index 17404522..b12cb3d8 100644 --- a/checker/check_request_parameters_min_items_set.go +++ b/checker/check_request_parameters_min_items_set.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -36,17 +35,16 @@ func RequestParameterMinItemsSetCheck(diffReport *diff.Diff, operationsSources * continue } - source := (*operationsSources)[operationItem.Revision] - result = append(result, ApiChange{ - Id: RequestParameterMinItemsSetId, - Level: WARN, - Args: []any{paramLocation, paramName, minItemsDiff.To}, - Comment: commentId(RequestParameterMinItemsSetId), - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterMinItemsSetId, + WARN, + []any{paramLocation, paramName, minItemsDiff.To}, + commentId(RequestParameterMinItemsSetId), + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameters_min_items_updated.go b/checker/check_request_parameters_min_items_updated.go index dacf962c..ca7de392 100644 --- a/checker/check_request_parameters_min_items_updated.go +++ b/checker/check_request_parameters_min_items_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -44,17 +43,16 @@ func RequestParameterMinItemsUpdatedCheck(diffReport *diff.Diff, operationsSourc level = INFO } - source := (*operationsSources)[operationItem.Revision] - - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{paramLocation, paramName, minItemsDiff.From, minItemsDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{paramLocation, paramName, minItemsDiff.From, minItemsDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameters_min_length_updated.go b/checker/check_request_parameters_min_length_updated.go index 6d442cfa..3677eec8 100644 --- a/checker/check_request_parameters_min_length_updated.go +++ b/checker/check_request_parameters_min_length_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -44,17 +43,16 @@ func RequestParameterMinLengthUpdatedCheck(diffReport *diff.Diff, operationsSour level = INFO } - source := (*operationsSources)[operationItem.Revision] - - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{paramLocation, paramName, minLengthDiff.From, minLengthDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{paramLocation, paramName, minLengthDiff.From, minLengthDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameters_min_set.go b/checker/check_request_parameters_min_set.go index 5baf0e11..193364b0 100644 --- a/checker/check_request_parameters_min_set.go +++ b/checker/check_request_parameters_min_set.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -36,18 +35,16 @@ func RequestParameterMinSetCheck(diffReport *diff.Diff, operationsSources *diff. continue } - source := (*operationsSources)[operationItem.Revision] - - result = append(result, ApiChange{ - Id: RequestParameterMinSetId, - Level: WARN, - Args: []any{paramLocation, paramName, minDiff.To}, - Comment: commentId(RequestParameterMinSetId), - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterMinSetId, + WARN, + []any{paramLocation, paramName, minDiff.To}, + commentId(RequestParameterMinSetId), + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameters_min_updated.go b/checker/check_request_parameters_min_updated.go index e6971466..4b93923f 100644 --- a/checker/check_request_parameters_min_updated.go +++ b/checker/check_request_parameters_min_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -37,8 +36,6 @@ func RequestParameterMinUpdatedCheck(diffReport *diff.Diff, operationsSources *d continue } - source := (*operationsSources)[operationItem.Revision] - id := RequestParameterMinIncreasedId level := ERR if !IsIncreasedValue(minDiff) { @@ -46,15 +43,16 @@ func RequestParameterMinUpdatedCheck(diffReport *diff.Diff, operationsSources *d level = INFO } - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{paramLocation, paramName, minDiff.From, minDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{paramLocation, paramName, minDiff.From, minDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_parameters_type_changed.go b/checker/check_request_parameters_type_changed.go index 9b9edf34..1cb928cd 100644 --- a/checker/check_request_parameters_type_changed.go +++ b/checker/check_request_parameters_type_changed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -24,7 +23,6 @@ func RequestParameterTypeChangedCheck(diffReport *diff.Diff, operationsSources * if operationItem.ParametersDiff == nil { continue } - source := (*operationsSources)[operationItem.Revision] for paramLocation, paramDiffs := range operationItem.ParametersDiff.Modified { for paramName, paramDiff := range paramDiffs { @@ -38,15 +36,16 @@ func RequestParameterTypeChangedCheck(diffReport *diff.Diff, operationsSources * if !typeDiff.Empty() || !formatDiff.Empty() { - result = append(result, ApiChange{ - Id: RequestParameterTypeChangedId, - Level: conditionalError(breakingTypeFormatChangedInRequest(typeDiff, formatDiff, false, schemaDiff), INFO), - Args: []any{paramLocation, paramName, getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff)}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterTypeChangedId, + conditionalError(breakingTypeFormatChangedInRequest(typeDiff, formatDiff, false, schemaDiff), INFO), + []any{paramLocation, paramName, getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff)}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } CheckModifiedPropertiesDiff( @@ -61,16 +60,16 @@ func RequestParameterTypeChangedCheck(diffReport *diff.Diff, operationsSources * level, comment := checkRequestParameterPropertyTypeChanged(typeDiff, formatDiff, schemaDiff) - result = append(result, ApiChange{ - Id: RequestParameterPropertyTypeChangedId, - Level: level, - Args: []any{paramLocation, paramName, propertyFullName(propertyPath, propertyName), getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff)}, - Comment: comment, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestParameterPropertyTypeChangedId, + level, + []any{paramLocation, paramName, propertyFullName(propertyPath, propertyName), getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff)}, + comment, + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_request_path_parameter_added.go b/checker/check_request_path_parameter_added.go index 86ef7d45..85939d4f 100644 --- a/checker/check_request_path_parameter_added.go +++ b/checker/check_request_path_parameter_added.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -28,16 +27,16 @@ func NewRequestPathParameterCheck(diffReport *diff.Diff, operationsSources *diff } for _, paramName := range paramItems { - source := (*operationsSources)[operationItem.Revision] - result = append(result, ApiChange{ - Id: NewRequestPathParameterId, - Level: ERR, - Args: []any{paramName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + NewRequestPathParameterId, + ERR, + []any{paramName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_property_all_of_updated.go b/checker/check_request_property_all_of_updated.go index 742e553c..39e7f5d0 100644 --- a/checker/check_request_property_all_of_updated.go +++ b/checker/check_request_property_all_of_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -29,7 +28,6 @@ func RequestPropertyAllOfUpdatedCheck(diffReport *diff.Diff, operationsSources * operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -38,27 +36,29 @@ func RequestPropertyAllOfUpdatedCheck(diffReport *diff.Diff, operationsSources * } if mediaTypeDiff.SchemaDiff.AllOfDiff != nil && len(mediaTypeDiff.SchemaDiff.AllOfDiff.Added) > 0 { - result = append(result, ApiChange{ - Id: RequestBodyAllOfAddedId, - Level: ERR, - Args: []any{mediaTypeDiff.SchemaDiff.AllOfDiff.Added.String()}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyAllOfAddedId, + ERR, + []any{mediaTypeDiff.SchemaDiff.AllOfDiff.Added.String()}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } if mediaTypeDiff.SchemaDiff.AllOfDiff != nil && len(mediaTypeDiff.SchemaDiff.AllOfDiff.Deleted) > 0 { - result = append(result, ApiChange{ - Id: RequestBodyAllOfRemovedId, - Level: WARN, - Args: []any{mediaTypeDiff.SchemaDiff.AllOfDiff.Deleted.String()}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyAllOfRemovedId, + WARN, + []any{mediaTypeDiff.SchemaDiff.AllOfDiff.Deleted.String()}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } CheckModifiedPropertiesDiff( @@ -71,28 +71,29 @@ func RequestPropertyAllOfUpdatedCheck(diffReport *diff.Diff, operationsSources * propName := propertyFullName(propertyPath, propertyName) if len(propertyDiff.AllOfDiff.Added) > 0 { - result = append(result, ApiChange{ - Id: RequestPropertyAllOfAddedId, - Level: ERR, - - Args: []any{propertyDiff.AllOfDiff.Added.String(), propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyAllOfAddedId, + ERR, + []any{propertyDiff.AllOfDiff.Added.String(), propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } if len(propertyDiff.AllOfDiff.Deleted) > 0 { - result = append(result, ApiChange{ - Id: RequestPropertyAllOfRemovedId, - Level: WARN, - Args: []any{propertyDiff.AllOfDiff.Deleted.String(), propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyAllOfRemovedId, + WARN, + []any{propertyDiff.AllOfDiff.Deleted.String(), propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_request_property_any_of_updated.go b/checker/check_request_property_any_of_updated.go index 771cd590..53ab510a 100644 --- a/checker/check_request_property_any_of_updated.go +++ b/checker/check_request_property_any_of_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -29,7 +28,6 @@ func RequestPropertyAnyOfUpdatedCheck(diffReport *diff.Diff, operationsSources * operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -38,27 +36,29 @@ func RequestPropertyAnyOfUpdatedCheck(diffReport *diff.Diff, operationsSources * } if mediaTypeDiff.SchemaDiff.AnyOfDiff != nil && len(mediaTypeDiff.SchemaDiff.AnyOfDiff.Added) > 0 { - result = append(result, ApiChange{ - Id: RequestBodyAnyOfAddedId, - Level: INFO, - Args: []any{mediaTypeDiff.SchemaDiff.AnyOfDiff.Added.String()}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyAnyOfAddedId, + INFO, + []any{mediaTypeDiff.SchemaDiff.AnyOfDiff.Added.String()}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } if mediaTypeDiff.SchemaDiff.AnyOfDiff != nil && len(mediaTypeDiff.SchemaDiff.AnyOfDiff.Deleted) > 0 { - result = append(result, ApiChange{ - Id: RequestBodyAnyOfRemovedId, - Level: ERR, - Args: []any{mediaTypeDiff.SchemaDiff.AnyOfDiff.Deleted.String()}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyAnyOfRemovedId, + ERR, + []any{mediaTypeDiff.SchemaDiff.AnyOfDiff.Deleted.String()}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } CheckModifiedPropertiesDiff( @@ -71,27 +71,29 @@ func RequestPropertyAnyOfUpdatedCheck(diffReport *diff.Diff, operationsSources * propName := propertyFullName(propertyPath, propertyName) if len(propertyDiff.AnyOfDiff.Added) > 0 { - result = append(result, ApiChange{ - Id: RequestPropertyAnyOfAddedId, - Level: INFO, - Args: []any{propertyDiff.AnyOfDiff.Added.String(), propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyAnyOfAddedId, + INFO, + []any{propertyDiff.AnyOfDiff.Added.String(), propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } if len(propertyDiff.AnyOfDiff.Deleted) > 0 { - result = append(result, ApiChange{ - Id: RequestPropertyAnyOfRemovedId, - Level: ERR, - Args: []any{propertyDiff.AnyOfDiff.Deleted.String(), propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyAnyOfRemovedId, + ERR, + []any{propertyDiff.AnyOfDiff.Deleted.String(), propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_request_property_became_enum.go b/checker/check_request_property_became_enum.go index 2049aac6..98f5f945 100644 --- a/checker/check_request_property_became_enum.go +++ b/checker/check_request_property_became_enum.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -19,7 +18,6 @@ func RequestPropertyBecameEnumCheck(diffReport *diff.Diff, operationsSources *di continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.RequestBodyDiff == nil || operationItem.RequestBodyDiff.ContentDiff == nil || @@ -40,15 +38,16 @@ func RequestPropertyBecameEnumCheck(diffReport *diff.Diff, operationsSources *di return } - result = append(result, ApiChange{ - Id: RequestPropertyBecameEnumId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName)}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyBecameEnumId, + ERR, + []any{propertyFullName(propertyPath, propertyName)}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_request_property_became_not_nuallable.go b/checker/check_request_property_became_not_nuallable.go index 03767f53..05cea28e 100644 --- a/checker/check_request_property_became_not_nuallable.go +++ b/checker/check_request_property_became_not_nuallable.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -22,7 +21,6 @@ func RequestPropertyBecameNotNullableCheck(diffReport *diff.Diff, operationsSour continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.RequestBodyDiff == nil || operationItem.RequestBodyDiff.ContentDiff == nil || @@ -37,25 +35,27 @@ func RequestPropertyBecameNotNullableCheck(diffReport *diff.Diff, operationsSour if mediaTypeDiff.SchemaDiff.NullableDiff != nil { if mediaTypeDiff.SchemaDiff.NullableDiff.From == true { - result = append(result, ApiChange{ - Id: RequestBodyBecomeNotNullableId, - Level: ERR, - Operation: operation, - Path: path, - Source: load.NewSource(source), - - OperationId: operationItem.Revision.OperationID, - }) + result = append(result, NewApiChange( + RequestBodyBecomeNotNullableId, + ERR, + nil, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else if mediaTypeDiff.SchemaDiff.NullableDiff.To == true { - result = append(result, ApiChange{ - Id: RequestBodyBecomeNullableId, - Level: INFO, - Operation: operation, - Path: path, - Source: load.NewSource(source), - - OperationId: operationItem.Revision.OperationID, - }) + result = append(result, NewApiChange( + RequestBodyBecomeNullableId, + INFO, + nil, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } @@ -70,27 +70,27 @@ func RequestPropertyBecameNotNullableCheck(diffReport *diff.Diff, operationsSour propName := propertyFullName(propertyPath, propertyName) if nullableDiff.From == true { - result = append(result, ApiChange{ - Id: RequestPropertyBecomeNotNullableId, - Level: ERR, - Args: []any{propName}, - Operation: operation, - Path: path, - Source: load.NewSource(source), - - OperationId: operationItem.Revision.OperationID, - }) + result = append(result, NewApiChange( + RequestPropertyBecomeNotNullableId, + ERR, + []any{propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else if nullableDiff.To == true { - result = append(result, ApiChange{ - Id: RequestPropertyBecomeNullableId, - Level: INFO, - Args: []any{propName}, - Operation: operation, - Path: path, - Source: load.NewSource(source), - - OperationId: operationItem.Revision.OperationID, - }) + result = append(result, NewApiChange( + RequestPropertyBecomeNullableId, + INFO, + []any{propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) diff --git a/checker/check_request_property_default_value_changed.go b/checker/check_request_property_default_value_changed.go index c4b332a3..91e208a3 100644 --- a/checker/check_request_property_default_value_changed.go +++ b/checker/check_request_property_default_value_changed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -29,18 +28,18 @@ func RequestPropertyDefaultValueChangedCheck(diffReport *diff.Diff, operationsSo operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] appendResultItem := func(messageId string, a ...any) { - result = append(result, ApiChange{ - Id: messageId, - Level: INFO, - Args: a, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + messageId, + INFO, + a, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified diff --git a/checker/check_request_property_enum_value_updated.go b/checker/check_request_property_enum_value_updated.go index 1905735c..a8795412 100644 --- a/checker/check_request_property_enum_value_updated.go +++ b/checker/check_request_property_enum_value_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -25,7 +24,6 @@ func RequestPropertyEnumValueUpdatedCheck(diffReport *diff.Diff, operationsSourc operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -40,27 +38,29 @@ func RequestPropertyEnumValueUpdatedCheck(diffReport *diff.Diff, operationsSourc propName := propertyFullName(propertyPath, propertyName) for _, enumVal := range enumDiff.Deleted { - result = append(result, ApiChange{ - Id: RequestPropertyEnumValueRemovedId, - Level: conditionalError(!propertyDiff.Revision.ReadOnly, INFO), - Args: []any{enumVal, propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyEnumValueRemovedId, + conditionalError(!propertyDiff.Revision.ReadOnly, INFO), + []any{enumVal, propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } for _, enumVal := range enumDiff.Added { - result = append(result, ApiChange{ - Id: RequestPropertyEnumValueAddedId, - Level: INFO, - Args: []any{enumVal, propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyEnumValueAddedId, + INFO, + []any{enumVal, propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_request_property_max_length_set.go b/checker/check_request_property_max_length_set.go index a53a5d23..a8577b9d 100644 --- a/checker/check_request_property_max_length_set.go +++ b/checker/check_request_property_max_length_set.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -25,7 +24,6 @@ func RequestPropertyMaxLengthSetCheck(diffReport *diff.Diff, operationsSources * operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -33,16 +31,16 @@ func RequestPropertyMaxLengthSetCheck(diffReport *diff.Diff, operationsSources * maxLengthDiff := mediaTypeDiff.SchemaDiff.MaxLengthDiff if maxLengthDiff.From == nil && maxLengthDiff.To != nil { - result = append(result, ApiChange{ - Id: RequestBodyMaxLengthSetId, - Level: WARN, - Args: []any{maxLengthDiff.To}, - Comment: commentId(RequestBodyMaxLengthSetId), - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMaxLengthSetId, + WARN, + []any{maxLengthDiff.To}, + commentId(RequestBodyMaxLengthSetId), + operationsSources, + operationItem.Revision, + operation, + path, + )) } } @@ -61,16 +59,16 @@ func RequestPropertyMaxLengthSetCheck(diffReport *diff.Diff, operationsSources * return } - result = append(result, ApiChange{ - Id: RequestPropertyMaxLengthSetId, - Level: WARN, - Args: []any{propertyFullName(propertyPath, propertyName), maxLengthDiff.To}, - Comment: commentId(RequestPropertyMaxLengthSetId), - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMaxLengthSetId, + WARN, + []any{propertyFullName(propertyPath, propertyName), maxLengthDiff.To}, + commentId(RequestPropertyMaxLengthSetId), + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_request_property_max_length_set_test.go b/checker/check_request_property_max_length_set_test.go new file mode 100644 index 00000000..e71c06df --- /dev/null +++ b/checker/check_request_property_max_length_set_test.go @@ -0,0 +1,56 @@ +package checker_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/tufin/oasdiff/checker" + "github.com/tufin/oasdiff/diff" + "github.com/tufin/oasdiff/load" +) + +// CL: setting maxLength of request body +func TestRequestBodyMaxLengthSetCheck(t *testing.T) { + s1, err := open("../data/checker/request_body_max_length_set_base.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/request_body_max_length_set_revision.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthSetCheck), d, osm, checker.INFO) + require.Len(t, errs, 1) + require.Equal(t, checker.ApiChange{ + Id: checker.RequestBodyMaxLengthSetId, + Args: []any{uint64(15)}, + Level: checker.WARN, + Comment: checker.RequestBodyMaxLengthSetId + "-comment", + Operation: "POST", + OperationId: "addPet", + Path: "/pets", + Source: load.NewSource("../data/checker/request_body_max_length_set_revision.yaml"), + }, errs[0]) +} + +// CL: setting maxLength of request propreties +func TestRequestPropertyMaxLengthSetCheck(t *testing.T) { + s1, err := open("../data/checker/request_property_max_length_set_base.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/request_property_max_length_set_revision.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxLengthSetCheck), d, osm, checker.INFO) + require.Len(t, errs, 1) + require.Equal(t, checker.ApiChange{ + Id: checker.RequestPropertyMaxLengthSetId, + Args: []any{"age", uint64(15)}, + Level: checker.WARN, + Comment: checker.RequestPropertyMaxLengthSetId + "-comment", + Operation: "POST", + OperationId: "addPet", + Path: "/pets", + Source: load.NewSource("../data/checker/request_property_max_length_set_revision.yaml"), + }, errs[0]) +} diff --git a/checker/check_request_property_max_length_updated.go b/checker/check_request_property_max_length_updated.go index 4ff8ef3e..72992102 100644 --- a/checker/check_request_property_max_length_updated.go +++ b/checker/check_request_property_max_length_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -27,7 +26,6 @@ func RequestPropertyMaxLengthUpdatedCheck(diffReport *diff.Diff, operationsSourc operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -36,25 +34,27 @@ func RequestPropertyMaxLengthUpdatedCheck(diffReport *diff.Diff, operationsSourc if maxLengthDiff.From != nil && maxLengthDiff.To != nil { if IsDecreasedValue(maxLengthDiff) { - result = append(result, ApiChange{ - Id: RequestBodyMaxLengthDecreasedId, - Level: ERR, - Args: []any{maxLengthDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMaxLengthDecreasedId, + ERR, + []any{maxLengthDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { - result = append(result, ApiChange{ - Id: RequestBodyMaxLengthIncreasedId, - Level: INFO, - Args: []any{maxLengthDiff.From, maxLengthDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMaxLengthIncreasedId, + INFO, + []any{maxLengthDiff.From, maxLengthDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } @@ -74,25 +74,27 @@ func RequestPropertyMaxLengthUpdatedCheck(diffReport *diff.Diff, operationsSourc propName := propertyFullName(propertyPath, propertyName) if IsDecreasedValue(maxLengthDiff) { - result = append(result, ApiChange{ - Id: RequestPropertyMaxLengthDecreasedId, - Level: conditionalError(!propertyDiff.Revision.ReadOnly, INFO), - Args: []any{propName, maxLengthDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMaxLengthDecreasedId, + conditionalError(!propertyDiff.Revision.ReadOnly, INFO), + []any{propName, maxLengthDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { - result = append(result, ApiChange{ - Id: RequestPropertyMaxLengthIncreasedId, - Level: INFO, - Args: []any{propName, maxLengthDiff.From, maxLengthDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMaxLengthIncreasedId, + INFO, + []any{propName, maxLengthDiff.From, maxLengthDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) diff --git a/checker/check_request_property_max_set.go b/checker/check_request_property_max_set.go index d10e7384..6f91c6d3 100644 --- a/checker/check_request_property_max_set.go +++ b/checker/check_request_property_max_set.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -25,7 +24,6 @@ func RequestPropertyMaxSetCheck(diffReport *diff.Diff, operationsSources *diff.O operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -33,16 +31,16 @@ func RequestPropertyMaxSetCheck(diffReport *diff.Diff, operationsSources *diff.O maxDiff := mediaTypeDiff.SchemaDiff.MaxDiff if maxDiff.From == nil && maxDiff.To != nil { - result = append(result, ApiChange{ - Id: RequestBodyMaxSetId, - Level: WARN, - Args: []any{maxDiff.To}, - Comment: commentId(RequestBodyMaxSetId), - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMaxSetId, + WARN, + []any{maxDiff.To}, + commentId(RequestBodyMaxSetId), + operationsSources, + operationItem.Revision, + operation, + path, + )) } } @@ -61,16 +59,16 @@ func RequestPropertyMaxSetCheck(diffReport *diff.Diff, operationsSources *diff.O return } - result = append(result, ApiChange{ - Id: RequestPropertyMaxSetId, - Level: WARN, - Args: []any{propertyFullName(propertyPath, propertyName), maxDiff.To}, - Comment: commentId(RequestPropertyMaxSetId), - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMaxSetId, + WARN, + []any{propertyFullName(propertyPath, propertyName), maxDiff.To}, + commentId(RequestPropertyMaxSetId), + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_request_property_max_set_test.go b/checker/check_request_property_max_set_test.go new file mode 100644 index 00000000..e5ca8ca5 --- /dev/null +++ b/checker/check_request_property_max_set_test.go @@ -0,0 +1,56 @@ +package checker_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/tufin/oasdiff/checker" + "github.com/tufin/oasdiff/diff" + "github.com/tufin/oasdiff/load" +) + +// CL: setting max of request body +func TestRequestBodyMaxSetCheck(t *testing.T) { + s1, err := open("../data/checker/request_body_max_set_base.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/request_body_max_set_revision.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxSetCheck), d, osm, checker.INFO) + require.Len(t, errs, 1) + require.Equal(t, checker.ApiChange{ + Id: checker.RequestBodyMaxSetId, + Args: []any{float64(15)}, + Level: checker.WARN, + Comment: checker.RequestBodyMaxSetId + "-comment", + Operation: "POST", + OperationId: "addPet", + Path: "/pets", + Source: load.NewSource("../data/checker/request_body_max_set_revision.yaml"), + }, errs[0]) +} + +// CL: setting max of request propreties +func TestRequestPropertyMaxSetCheck(t *testing.T) { + s1, err := open("../data/checker/request_property_max_set_base.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/request_property_max_set_revision.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyMaxSetCheck), d, osm, checker.INFO) + require.Len(t, errs, 1) + require.Equal(t, checker.ApiChange{ + Id: checker.RequestPropertyMaxSetId, + Args: []any{"age", float64(15)}, + Level: checker.WARN, + Comment: checker.RequestPropertyMaxSetId + "-comment", + Operation: "POST", + OperationId: "addPet", + Path: "/pets", + Source: load.NewSource("../data/checker/request_property_max_set_revision.yaml"), + }, errs[0]) +} diff --git a/checker/check_request_property_max_updated.go b/checker/check_request_property_max_updated.go index bfb4e9c4..0ba417f5 100644 --- a/checker/check_request_property_max_updated.go +++ b/checker/check_request_property_max_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -27,7 +26,6 @@ func RequestPropertyMaxDecreasedCheck(diffReport *diff.Diff, operationsSources * operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -36,25 +34,27 @@ func RequestPropertyMaxDecreasedCheck(diffReport *diff.Diff, operationsSources * if maxDiff.From != nil && maxDiff.To != nil { if IsDecreasedValue(maxDiff) { - result = append(result, ApiChange{ - Id: RequestBodyMaxDecreasedId, - Level: ERR, - Args: []any{maxDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMaxDecreasedId, + ERR, + []any{maxDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { - result = append(result, ApiChange{ - Id: RequestBodyMaxIncreasedId, - Level: INFO, - Args: []any{maxDiff.From, maxDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMaxIncreasedId, + INFO, + []any{maxDiff.From, maxDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } @@ -74,25 +74,27 @@ func RequestPropertyMaxDecreasedCheck(diffReport *diff.Diff, operationsSources * propName := propertyFullName(propertyPath, propertyName) if IsDecreasedValue(maxDiff) { - result = append(result, ApiChange{ - Id: RequestPropertyMaxDecreasedId, - Level: conditionalError(!propertyDiff.Revision.ReadOnly, INFO), - Args: []any{propName, maxDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMaxDecreasedId, + conditionalError(!propertyDiff.Revision.ReadOnly, INFO), + []any{propName, maxDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { - result = append(result, ApiChange{ - Id: RequestPropertyMaxIncreasedId, - Level: INFO, - Args: []any{propName, maxDiff.From, maxDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMaxIncreasedId, + INFO, + []any{propName, maxDiff.From, maxDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) diff --git a/checker/check_request_property_min_items_increased.go b/checker/check_request_property_min_items_increased.go index 850564c1..411e9830 100644 --- a/checker/check_request_property_min_items_increased.go +++ b/checker/check_request_property_min_items_increased.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -25,7 +24,6 @@ func RequestPropertyMinItemsIncreasedCheck(diffReport *diff.Diff, operationsSour operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -34,15 +32,16 @@ func RequestPropertyMinItemsIncreasedCheck(diffReport *diff.Diff, operationsSour if minItemsDiff.From != nil && minItemsDiff.To != nil { if IsIncreasedValue(minItemsDiff) { - result = append(result, ApiChange{ - Id: RequestBodyMinItemsIncreasedId, - Level: ERR, - Args: []any{minItemsDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMinItemsIncreasedId, + ERR, + []any{minItemsDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } @@ -65,15 +64,16 @@ func RequestPropertyMinItemsIncreasedCheck(diffReport *diff.Diff, operationsSour return } - result = append(result, ApiChange{ - Id: RequestPropertyMinItemsIncreasedId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName), minItemsDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMinItemsIncreasedId, + ERR, + []any{propertyFullName(propertyPath, propertyName), minItemsDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_request_property_min_items_set.go b/checker/check_request_property_min_items_set.go index 73866323..c9acabd6 100644 --- a/checker/check_request_property_min_items_set.go +++ b/checker/check_request_property_min_items_set.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -25,7 +24,6 @@ func RequestPropertyMinItemsSetCheck(diffReport *diff.Diff, operationsSources *d operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -33,16 +31,16 @@ func RequestPropertyMinItemsSetCheck(diffReport *diff.Diff, operationsSources *d minItemsDiff := mediaTypeDiff.SchemaDiff.MinItemsDiff if minItemsDiff.From == nil && minItemsDiff.To != nil { - result = append(result, ApiChange{ - Id: RequestBodyMinItemsSetId, - Level: WARN, - Args: []any{minItemsDiff.To}, - Comment: commentId(RequestBodyMinItemsSetId), - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMinItemsSetId, + WARN, + []any{minItemsDiff.To}, + commentId(RequestBodyMinItemsSetId), + operationsSources, + operationItem.Revision, + operation, + path, + )) } } @@ -61,16 +59,16 @@ func RequestPropertyMinItemsSetCheck(diffReport *diff.Diff, operationsSources *d return } - result = append(result, ApiChange{ - Id: RequestPropertyMinItemsSetId, - Level: WARN, - Args: []any{propertyFullName(propertyPath, propertyName), minItemsDiff.To}, - Comment: commentId(RequestPropertyMinItemsSetId), - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMinItemsSetId, + WARN, + []any{propertyFullName(propertyPath, propertyName), minItemsDiff.To}, + commentId(RequestPropertyMinItemsSetId), + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_request_property_min_length_updated.go b/checker/check_request_property_min_length_updated.go index bfc980ef..7ec7566f 100644 --- a/checker/check_request_property_min_length_updated.go +++ b/checker/check_request_property_min_length_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -27,7 +26,6 @@ func RequestPropertyMinLengthUpdatedCheck(diffReport *diff.Diff, operationsSourc operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -36,25 +34,27 @@ func RequestPropertyMinLengthUpdatedCheck(diffReport *diff.Diff, operationsSourc if minLengthDiff.From != nil && minLengthDiff.To != nil { if IsIncreasedValue(minLengthDiff) { - result = append(result, ApiChange{ - Id: RequestBodyMinLengthIncreasedId, - Level: ERR, - Args: []any{minLengthDiff.From, minLengthDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMinLengthIncreasedId, + ERR, + []any{minLengthDiff.From, minLengthDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { - result = append(result, ApiChange{ - Id: RequestBodyMinLengthDecreasedId, - Level: INFO, - Args: []any{minLengthDiff.From, minLengthDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMinLengthDecreasedId, + INFO, + []any{minLengthDiff.From, minLengthDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } @@ -74,25 +74,27 @@ func RequestPropertyMinLengthUpdatedCheck(diffReport *diff.Diff, operationsSourc propName := propertyFullName(propertyPath, propertyName) if IsDecreasedValue(minLengthDiff) { - result = append(result, ApiChange{ - Id: RequestPropertyMinLengthDecreasedId, - Level: INFO, - Args: []any{propName, minLengthDiff.From, minLengthDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMinLengthDecreasedId, + INFO, + []any{propName, minLengthDiff.From, minLengthDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { - result = append(result, ApiChange{ - Id: RequestPropertyMinLengthIncreasedId, - Level: ERR, - Args: []any{propName, minLengthDiff.From, minLengthDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMinLengthIncreasedId, + ERR, + []any{propName, minLengthDiff.From, minLengthDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_request_property_min_set.go b/checker/check_request_property_min_set.go index 24410935..ef7829aa 100644 --- a/checker/check_request_property_min_set.go +++ b/checker/check_request_property_min_set.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -25,7 +24,6 @@ func RequestPropertyMinSetCheck(diffReport *diff.Diff, operationsSources *diff.O operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -33,16 +31,16 @@ func RequestPropertyMinSetCheck(diffReport *diff.Diff, operationsSources *diff.O minDiff := mediaTypeDiff.SchemaDiff.MinDiff if minDiff.From == nil && minDiff.To != nil { - result = append(result, ApiChange{ - Id: RequestBodyMinSetId, - Level: WARN, - Args: []any{minDiff.To}, - Comment: commentId(RequestBodyMinSetId), - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMinSetId, + WARN, + []any{minDiff.To}, + commentId(RequestBodyMinSetId), + operationsSources, + operationItem.Revision, + operation, + path, + )) } } @@ -61,16 +59,16 @@ func RequestPropertyMinSetCheck(diffReport *diff.Diff, operationsSources *diff.O return } - result = append(result, ApiChange{ - Id: RequestPropertyMinSetId, - Level: WARN, - Args: []any{propertyFullName(propertyPath, propertyName), minDiff.To}, - Comment: commentId(RequestPropertyMinSetId), - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMinSetId, + WARN, + []any{propertyFullName(propertyPath, propertyName), minDiff.To}, + commentId(RequestPropertyMinSetId), + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_request_property_min_updated.go b/checker/check_request_property_min_updated.go index 9703ac53..10bd6c87 100644 --- a/checker/check_request_property_min_updated.go +++ b/checker/check_request_property_min_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -27,7 +26,6 @@ func RequestPropertyMinIncreasedCheck(diffReport *diff.Diff, operationsSources * operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -36,25 +34,27 @@ func RequestPropertyMinIncreasedCheck(diffReport *diff.Diff, operationsSources * if minDiff.From != nil && minDiff.To != nil { if IsIncreasedValue(minDiff) { - result = append(result, ApiChange{ - Id: RequestBodyMinIncreasedId, - Level: ERR, - Args: []any{minDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMinIncreasedId, + ERR, + []any{minDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { - result = append(result, ApiChange{ - Id: RequestBodyMinDecreasedId, - Level: INFO, - Args: []any{minDiff.From, minDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyMinDecreasedId, + INFO, + []any{minDiff.From, minDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } @@ -74,25 +74,27 @@ func RequestPropertyMinIncreasedCheck(diffReport *diff.Diff, operationsSources * propName := propertyFullName(propertyPath, propertyName) if IsIncreasedValue(minDiff) { - result = append(result, ApiChange{ - Id: RequestPropertyMinIncreasedId, - Level: conditionalError(!propertyDiff.Revision.ReadOnly, INFO), - Args: []any{propName, minDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMinIncreasedId, + conditionalError(!propertyDiff.Revision.ReadOnly, INFO), + []any{propName, minDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { - result = append(result, ApiChange{ - Id: RequestPropertyMinDecreasedId, - Level: INFO, - Args: []any{propName, minDiff.From, minDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyMinDecreasedId, + INFO, + []any{propName, minDiff.From, minDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_request_property_one_of_updated.go b/checker/check_request_property_one_of_updated.go index 27ea2500..f2e61538 100644 --- a/checker/check_request_property_one_of_updated.go +++ b/checker/check_request_property_one_of_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -29,7 +28,6 @@ func RequestPropertyOneOfUpdatedCheck(diffReport *diff.Diff, operationsSources * operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -38,27 +36,29 @@ func RequestPropertyOneOfUpdatedCheck(diffReport *diff.Diff, operationsSources * } if mediaTypeDiff.SchemaDiff.OneOfDiff != nil && len(mediaTypeDiff.SchemaDiff.OneOfDiff.Added) > 0 { - result = append(result, ApiChange{ - Id: RequestBodyOneOfAddedId, - Level: INFO, - Args: []any{mediaTypeDiff.SchemaDiff.OneOfDiff.Added.String()}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyOneOfAddedId, + INFO, + []any{mediaTypeDiff.SchemaDiff.OneOfDiff.Added.String()}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } if mediaTypeDiff.SchemaDiff.OneOfDiff != nil && len(mediaTypeDiff.SchemaDiff.OneOfDiff.Deleted) > 0 { - result = append(result, ApiChange{ - Id: RequestBodyOneOfRemovedId, - Level: ERR, - Args: []any{mediaTypeDiff.SchemaDiff.OneOfDiff.Deleted.String()}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyOneOfRemovedId, + ERR, + []any{mediaTypeDiff.SchemaDiff.OneOfDiff.Deleted.String()}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } CheckModifiedPropertiesDiff( @@ -71,27 +71,29 @@ func RequestPropertyOneOfUpdatedCheck(diffReport *diff.Diff, operationsSources * propName := propertyFullName(propertyPath, propertyName) if len(propertyDiff.OneOfDiff.Added) > 0 { - result = append(result, ApiChange{ - Id: RequestPropertyOneOfAddedId, - Level: INFO, - Args: []any{propertyDiff.OneOfDiff.Added.String(), propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyOneOfAddedId, + INFO, + []any{propertyDiff.OneOfDiff.Added.String(), propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } if len(propertyDiff.OneOfDiff.Deleted) > 0 { - result = append(result, ApiChange{ - Id: RequestPropertyOneOfRemovedId, - Level: ERR, - Args: []any{propertyDiff.OneOfDiff.Deleted.String(), propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyOneOfRemovedId, + ERR, + []any{propertyDiff.OneOfDiff.Deleted.String(), propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_request_property_pattern_added_or_changed.go b/checker/check_request_property_pattern_added_or_changed.go index 98c256a6..8f6fa28e 100644 --- a/checker/check_request_property_pattern_added_or_changed.go +++ b/checker/check_request_property_pattern_added_or_changed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -36,30 +35,30 @@ func RequestPropertyPatternUpdatedCheck(diffReport *diff.Diff, operationsSources return } - source := (*operationsSources)[operationItem.Revision] propName := propertyFullName(propertyPath, propertyName) if patternDiff.To == "" { - result = append(result, ApiChange{ - Id: RequestPropertyPatternRemovedId, - Level: INFO, - Args: []any{patternDiff.From, propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyPatternRemovedId, + INFO, + []any{patternDiff.From, propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else if patternDiff.From == "" { - result = append(result, ApiChange{ - Id: RequestPropertyPatternAddedId, - Level: WARN, - Args: []any{patternDiff.To, propName}, - Comment: PatternChangedCommentId, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyPatternAddedId, + WARN, + []any{patternDiff.To, propName}, + PatternChangedCommentId, + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { level := WARN comment := PatternChangedCommentId @@ -67,16 +66,16 @@ func RequestPropertyPatternUpdatedCheck(diffReport *diff.Diff, operationsSources level = INFO comment = "" } - result = append(result, ApiChange{ - Id: RequestPropertyPatternChangedId, - Level: level, - Args: []any{propName, patternDiff.From, patternDiff.To}, - Comment: comment, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyPatternChangedId, + level, + []any{propName, patternDiff.From, patternDiff.To}, + comment, + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_request_property_required_updated.go b/checker/check_request_property_required_updated.go index cdb063b4..fa6d1294 100644 --- a/checker/check_request_property_required_updated.go +++ b/checker/check_request_property_required_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -21,7 +20,6 @@ func RequestPropertyRequiredUpdatedCheck(diffReport *diff.Diff, operationsSource continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.RequestBodyDiff == nil || operationItem.RequestBodyDiff.ContentDiff == nil || @@ -42,26 +40,28 @@ func RequestPropertyRequiredUpdatedCheck(diffReport *diff.Diff, operationsSource } if schemaDiff.Revision.Properties[changedRequiredPropertyName].Value.Default == nil { - result = append(result, ApiChange{ - Id: RequestPropertyBecameRequiredId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyBecameRequiredId, + ERR, + []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { // property has a default value, so making it required is not a breaking change - result = append(result, ApiChange{ - Id: RequestPropertyBecameRequiredWithDefaultId, - Level: INFO, - Args: []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyBecameRequiredWithDefaultId, + INFO, + []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } for _, changedRequiredPropertyName := range schemaDiff.RequiredDiff.Deleted { @@ -69,15 +69,16 @@ func RequestPropertyRequiredUpdatedCheck(diffReport *diff.Diff, operationsSource continue } - result = append(result, ApiChange{ - Id: RequestPropertyBecameOptionalId, - Level: INFO, - Args: []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyBecameOptionalId, + INFO, + []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName))}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_request_property_type_changed.go b/checker/check_request_property_type_changed.go index c9ba7113..037e280c 100644 --- a/checker/check_request_property_type_changed.go +++ b/checker/check_request_property_type_changed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -25,7 +24,6 @@ func RequestPropertyTypeChangedCheck(diffReport *diff.Diff, operationsSources *d operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for mediaType, mediaTypeDiff := range modifiedMediaTypes { @@ -39,15 +37,16 @@ func RequestPropertyTypeChangedCheck(diffReport *diff.Diff, operationsSources *d if !typeDiff.Empty() || !formatDiff.Empty() { - result = append(result, ApiChange{ - Id: RequestBodyTypeChangedId, - Level: conditionalError(breakingTypeFormatChangedInRequestProperty(typeDiff, formatDiff, mediaType, schemaDiff), INFO), - Args: []any{getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff)}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestBodyTypeChangedId, + conditionalError(breakingTypeFormatChangedInRequestProperty(typeDiff, formatDiff, mediaType, schemaDiff), INFO), + []any{getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff)}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } CheckModifiedPropertiesDiff( @@ -65,15 +64,16 @@ func RequestPropertyTypeChangedCheck(diffReport *diff.Diff, operationsSources *d if !typeDiff.Empty() || !formatDiff.Empty() { - result = append(result, ApiChange{ - Id: RequestPropertyTypeChangedId, - Level: conditionalError(breakingTypeFormatChangedInRequestProperty(typeDiff, formatDiff, mediaType, schemaDiff), INFO), - Args: []any{propertyFullName(propertyPath, propertyName), getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff)}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyTypeChangedId, + conditionalError(breakingTypeFormatChangedInRequestProperty(typeDiff, formatDiff, mediaType, schemaDiff), INFO), + []any{propertyFullName(propertyPath, propertyName), getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff)}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_request_property_updated.go b/checker/check_request_property_updated.go index 42ad52b0..91d194a2 100644 --- a/checker/check_request_property_updated.go +++ b/checker/check_request_property_updated.go @@ -3,7 +3,6 @@ package checker import ( "github.com/getkin/kin-openapi/openapi3" "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" "golang.org/x/exp/slices" ) @@ -35,22 +34,22 @@ func RequestPropertyUpdatedCheck(diffReport *diff.Diff, operationsSources *diff. mediaTypeDiff.SchemaDiff, func(propertyPath string, propertyName string, propertyItem *openapi3.Schema, parent *diff.SchemaDiff) { if !propertyItem.ReadOnly { - source := (*operationsSources)[operationItem.Revision] - result = append(result, ApiChange{ - Id: RequestPropertyRemovedId, - Level: WARN, - Args: []any{propertyFullName(propertyPath, propertyName)}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + + result = append(result, NewApiChange( + RequestPropertyRemovedId, + WARN, + []any{propertyFullName(propertyPath, propertyName)}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) CheckAddedPropertiesDiff( mediaTypeDiff.SchemaDiff, func(propertyPath string, propertyName string, propertyItem *openapi3.Schema, parent *diff.SchemaDiff) { - source := (*operationsSources)[operationItem.Revision] if propertyItem.ReadOnly { return } @@ -59,36 +58,39 @@ func RequestPropertyUpdatedCheck(diffReport *diff.Diff, operationsSources *diff. if slices.Contains(parent.Revision.Required, propertyName) { if propertyItem.Default == nil { - result = append(result, ApiChange{ - Id: NewRequiredRequestPropertyId, - Level: ERR, - Args: []any{propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + NewRequiredRequestPropertyId, + ERR, + []any{propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { - result = append(result, ApiChange{ - Id: NewRequiredRequestPropertyWithDefaultId, - Level: INFO, - Args: []any{propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + NewRequiredRequestPropertyWithDefaultId, + INFO, + []any{propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } else { - result = append(result, ApiChange{ - Id: NewOptionalRequestPropertyId, - Level: INFO, - Args: []any{propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + NewOptionalRequestPropertyId, + INFO, + []any{propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_request_property_write_only_read_only.go b/checker/check_request_property_write_only_read_only.go index 0e85b93f..cdbc343a 100644 --- a/checker/check_request_property_write_only_read_only.go +++ b/checker/check_request_property_write_only_read_only.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" "golang.org/x/exp/slices" ) @@ -27,7 +26,6 @@ func RequestPropertyWriteOnlyReadOnlyCheck(diffReport *diff.Diff, operationsSour continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.RequestBodyDiff == nil || operationItem.RequestBodyDiff.ContentDiff == nil || @@ -60,15 +58,16 @@ func RequestPropertyWriteOnlyReadOnlyCheck(diffReport *diff.Diff, operationsSour id = RequestRequiredPropertyBecameWriteOnlyCheckId } - result = append(result, ApiChange{ - Id: id, - Level: INFO, - Args: []any{propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + INFO, + []any{propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) return } @@ -76,15 +75,16 @@ func RequestPropertyWriteOnlyReadOnlyCheck(diffReport *diff.Diff, operationsSour if writeOnlyDiff.To == true { id = RequestOptionalPropertyBecameWriteOnlyCheckId } - result = append(result, ApiChange{ - Id: id, - Level: INFO, - Args: []any{propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + INFO, + []any{propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) CheckModifiedPropertiesDiff( @@ -106,15 +106,16 @@ func RequestPropertyWriteOnlyReadOnlyCheck(diffReport *diff.Diff, operationsSour if readOnlyDiff.To == true { id = RequestRequiredPropertyBecameReadOnlyCheckId } - result = append(result, ApiChange{ - Id: id, - Level: INFO, - Args: []any{propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + INFO, + []any{propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) return } @@ -122,15 +123,16 @@ func RequestPropertyWriteOnlyReadOnlyCheck(diffReport *diff.Diff, operationsSour if readOnlyDiff.To == true { id = RequestOptionalPropertyBecameReadOnlyCheckId } - result = append(result, ApiChange{ - Id: id, - Level: INFO, - Args: []any{propName}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + INFO, + []any{propName}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_request_property_x_extensible_enum_value_removed.go b/checker/check_request_property_x_extensible_enum_value_removed.go index d8e2f73a..6a726957 100644 --- a/checker/check_request_property_x_extensible_enum_value_removed.go +++ b/checker/check_request_property_x_extensible_enum_value_removed.go @@ -1,16 +1,11 @@ package checker import ( - "encoding/json" - "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" "golang.org/x/exp/slices" ) const ( - UnparseablePropertyFromXExtensibleEnumId = "unparseable-property-from-x-extensible-enum" - UnparseablePropertyToXExtensibleEnumId = "unparseable-property-to-x-extensible-enum" RequestPropertyXExtensibleEnumValueRemovedId = "request-property-x-extensible-enum-value-removed" ) @@ -29,7 +24,6 @@ func RequestPropertyXExtensibleEnumValueRemovedCheck(diffReport *diff.Diff, oper operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { continue } - source := (*operationsSources)[operationItem.Revision] modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified for _, mediaTypeDiff := range modifiedMediaTypes { @@ -45,39 +39,23 @@ func RequestPropertyXExtensibleEnumValueRemovedCheck(diffReport *diff.Diff, oper if propertyDiff.ExtensionsDiff.Modified[diff.XExtensibleEnumExtension] == nil { return } - from, ok := propertyDiff.Base.Extensions[diff.XExtensibleEnumExtension].(json.RawMessage) + from, ok := propertyDiff.Base.Extensions[diff.XExtensibleEnumExtension].([]interface{}) if !ok { return } - to, ok := propertyDiff.Base.Extensions[diff.XExtensibleEnumExtension].(json.RawMessage) + to, ok := propertyDiff.Revision.Extensions[diff.XExtensibleEnumExtension].([]interface{}) if !ok { return } - var fromSlice []string - if err := json.Unmarshal(from, &fromSlice); err != nil { - result = append(result, ApiChange{ - Id: UnparseablePropertyFromXExtensibleEnumId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName)}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) - return + + fromSlice := make([]string, len(from)) + for i, item := range from { + fromSlice[i] = item.(string) } - var toSlice []string - if err := json.Unmarshal(to, &toSlice); err != nil { - result = append(result, ApiChange{ - Id: UnparseablePropertyToXExtensibleEnumId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName)}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) - return + + toSlice := make([]string, len(to)) + for i, item := range to { + toSlice[i] = item.(string) } deletedVals := make([]string, 0) @@ -91,15 +69,16 @@ func RequestPropertyXExtensibleEnumValueRemovedCheck(diffReport *diff.Diff, oper return } for _, enumVal := range deletedVals { - result = append(result, ApiChange{ - Id: RequestPropertyXExtensibleEnumValueRemovedId, - Level: ERR, - Args: []any{enumVal, propertyFullName(propertyPath, propertyName)}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequestPropertyXExtensibleEnumValueRemovedId, + ERR, + []any{enumVal, propertyFullName(propertyPath, propertyName)}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_request_property_x_extensible_enum_value_removed_test.go b/checker/check_request_property_x_extensible_enum_value_removed_test.go new file mode 100644 index 00000000..9e218c85 --- /dev/null +++ b/checker/check_request_property_x_extensible_enum_value_removed_test.go @@ -0,0 +1,24 @@ +package checker_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/tufin/oasdiff/checker" + "github.com/tufin/oasdiff/diff" +) + +// BC: Deleting a value from an x-extensible-enum property is breaking +func TestRequestPropertyXExtensibleEnumValueRemovedCheck(t *testing.T) { + s1, err := open("../data/checker/request_property_extensible_enum_base.yaml") + require.NoError(t, err) + + s2, err := open("../data/checker/request_property_extensible_enum_revision.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibility(singleCheckConfig(checker.RequestPropertyXExtensibleEnumValueRemovedCheck), d, osm) + require.Len(t, errs, 1) + require.Equal(t, checker.RequestPropertyXExtensibleEnumValueRemovedId, errs[0].GetId()) +} diff --git a/checker/check_response_discriminator_updated.go b/checker/check_response_discriminator_updated.go index 346ee744..302d61ee 100644 --- a/checker/check_response_discriminator_updated.go +++ b/checker/check_response_discriminator_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -35,18 +34,18 @@ func ResponseDiscriminatorUpdatedCheck(diffReport *diff.Diff, operationsSources if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] appendResultItem := func(messageId string, a ...any) { - result = append(result, ApiChange{ - Id: messageId, - Level: INFO, - Args: a, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + messageId, + INFO, + a, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } for responseStatus, responsesDiff := range operationItem.ResponsesDiff.Modified { diff --git a/checker/check_response_header_became_optional.go b/checker/check_response_header_became_optional.go index 4e0e5eca..66044ece 100644 --- a/checker/check_response_header_became_optional.go +++ b/checker/check_response_header_became_optional.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -25,7 +24,6 @@ func ResponseHeaderBecameOptionalCheck(diffReport *diff.Diff, operationsSources if operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { if responseDiff.HeadersDiff == nil { continue @@ -40,15 +38,16 @@ func ResponseHeaderBecameOptionalCheck(diffReport *diff.Diff, operationsSources continue } - result = append(result, ApiChange{ - Id: ResponseHeaderBecameOptionalId, - Level: ERR, - Args: []any{headerName, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseHeaderBecameOptionalId, + ERR, + []any{headerName, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_response_header_removed.go b/checker/check_response_header_removed.go index c40b910f..ce78f51f 100644 --- a/checker/check_response_header_removed.go +++ b/checker/check_response_header_removed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -26,7 +25,6 @@ func ResponseHeaderRemovedCheck(diffReport *diff.Diff, operationsSources *diff.O if operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { if responseDiff.HeadersDiff == nil { continue @@ -38,25 +36,27 @@ func ResponseHeaderRemovedCheck(diffReport *diff.Diff, operationsSources *diff.O } required := responseDiff.Base.Headers[headerName].Value.Required if required { - result = append(result, ApiChange{ - Id: RequiredResponseHeaderRemovedId, - Level: ERR, - Args: []any{headerName, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + RequiredResponseHeaderRemovedId, + ERR, + []any{headerName, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } else { - result = append(result, ApiChange{ - Id: OptionalResponseHeaderRemovedId, - Level: WARN, - Args: []any{headerName, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + OptionalResponseHeaderRemovedId, + WARN, + []any{headerName, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_response_mediatype_enum_value_removed.go b/checker/check_response_mediatype_enum_value_removed.go index 06588616..c9b4d946 100644 --- a/checker/check_response_mediatype_enum_value_removed.go +++ b/checker/check_response_mediatype_enum_value_removed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -25,7 +24,6 @@ func ResponseMediaTypeEnumValueRemovedCheck(diffReport *diff.Diff, operationsSou if operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for _, responseItems := range operationItem.ResponsesDiff.Modified { if responseItems.ContentDiff == nil { continue @@ -45,15 +43,16 @@ func ResponseMediaTypeEnumValueRemovedCheck(diffReport *diff.Diff, operationsSou } for _, enumVal := range enumDiff.Deleted { - result = append(result, ApiChange{ - Id: ResponseMediaTypeEnumValueRemovedId, - Level: config.getLogLevel(ResponseMediaTypeEnumValueRemovedId, ERR), - Args: []any{mediaType, enumVal}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseMediaTypeEnumValueRemovedId, + config.getLogLevel(ResponseMediaTypeEnumValueRemovedId, ERR), + []any{mediaType, enumVal}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_response_mediatype_updated.go b/checker/check_response_mediatype_updated.go index 86043c9f..1114c005 100644 --- a/checker/check_response_mediatype_updated.go +++ b/checker/check_response_mediatype_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -26,7 +25,6 @@ func ResponseMediaTypeUpdatedCheck(diffReport *diff.Diff, operationsSources *dif if operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responsesDiff := range operationItem.ResponsesDiff.Modified { if responsesDiff.ContentDiff == nil { continue @@ -35,26 +33,28 @@ func ResponseMediaTypeUpdatedCheck(diffReport *diff.Diff, operationsSources *dif continue } for _, mediaType := range responsesDiff.ContentDiff.MediaTypeDeleted { - result = append(result, ApiChange{ - Id: ResponseMediaTypeRemovedId, - Level: ERR, - Args: []any{mediaType, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseMediaTypeRemovedId, + ERR, + []any{mediaType, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } for _, mediaType := range responsesDiff.ContentDiff.MediaTypeAdded { - result = append(result, ApiChange{ - Id: ResponseMediaTypeAddedId, - Level: INFO, - Args: []any{mediaType, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseMediaTypeAddedId, + INFO, + []any{mediaType, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/check_response_optional_property_updated.go b/checker/check_response_optional_property_updated.go index 74960cae..f94a1707 100644 --- a/checker/check_response_optional_property_updated.go +++ b/checker/check_response_optional_property_updated.go @@ -3,7 +3,6 @@ package checker import ( "github.com/getkin/kin-openapi/openapi3" "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" "golang.org/x/exp/slices" ) @@ -24,7 +23,6 @@ func ResponseOptionalPropertyUpdatedCheck(diffReport *diff.Diff, operationsSourc continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ResponsesDiff == nil { continue @@ -52,15 +50,16 @@ func ResponseOptionalPropertyUpdatedCheck(diffReport *diff.Diff, operationsSourc return } - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) CheckAddedPropertiesDiff( mediaTypeDiff.SchemaDiff, @@ -75,15 +74,16 @@ func ResponseOptionalPropertyUpdatedCheck(diffReport *diff.Diff, operationsSourc return } - result = append(result, ApiChange{ - Id: id, - Level: INFO, - Args: []any{propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + INFO, + []any{propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_response_optional_property_write_only_read_only.go b/checker/check_response_optional_property_write_only_read_only.go index be126ccb..d7547bb7 100644 --- a/checker/check_response_optional_property_write_only_read_only.go +++ b/checker/check_response_optional_property_write_only_read_only.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" "golang.org/x/exp/slices" ) @@ -23,7 +22,6 @@ func ResponseOptionalPropertyWriteOnlyReadOnlyCheck(diffReport *diff.Diff, opera continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ResponsesDiff == nil { continue @@ -63,15 +61,16 @@ func ResponseOptionalPropertyWriteOnlyReadOnlyCheck(diffReport *diff.Diff, opera id = ResponseOptionalPropertyBecameWriteOnlyId } - result = append(result, ApiChange{ - Id: id, - Level: INFO, - Args: []any{propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + INFO, + []any{propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) CheckModifiedPropertiesDiff( @@ -96,15 +95,16 @@ func ResponseOptionalPropertyWriteOnlyReadOnlyCheck(diffReport *diff.Diff, opera id = ResponseOptionalPropertyBecameReadOnlyId } - result = append(result, ApiChange{ - Id: id, - Level: INFO, - Args: []any{propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + INFO, + []any{propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_response_pattern_added_or_changed.go b/checker/check_response_pattern_added_or_changed.go index f34a9a24..00293760 100644 --- a/checker/check_response_pattern_added_or_changed.go +++ b/checker/check_response_pattern_added_or_changed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -21,7 +20,6 @@ func ResponsePatternAddedOrChangedCheck(diffReport *diff.Diff, operationsSources continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ResponsesDiff == nil { continue @@ -59,15 +57,16 @@ func ResponsePatternAddedOrChangedCheck(diffReport *diff.Diff, operationsSources args = []any{propName, patternDiff.To, responseStatus} } - result = append(result, ApiChange{ - Id: id, - Level: INFO, - Args: args, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + INFO, + args, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_response_property_all_of_updated.go b/checker/check_response_property_all_of_updated.go index 9dfc7712..117a02a7 100644 --- a/checker/check_response_property_all_of_updated.go +++ b/checker/check_response_property_all_of_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -27,7 +26,6 @@ func ResponsePropertyAllOfUpdatedCheck(diffReport *diff.Diff, operationsSources if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responsesDiff := range operationItem.ResponsesDiff.Modified { if responsesDiff.ContentDiff == nil || responsesDiff.ContentDiff.MediaTypeModified == nil { @@ -41,27 +39,29 @@ func ResponsePropertyAllOfUpdatedCheck(diffReport *diff.Diff, operationsSources } if mediaTypeDiff.SchemaDiff.AllOfDiff != nil && len(mediaTypeDiff.SchemaDiff.AllOfDiff.Added) > 0 { - result = append(result, ApiChange{ - Id: ResponseBodyAllOfAddedId, - Level: INFO, - Args: []any{mediaTypeDiff.SchemaDiff.AllOfDiff.Added.String(), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyAllOfAddedId, + INFO, + []any{mediaTypeDiff.SchemaDiff.AllOfDiff.Added.String(), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } if mediaTypeDiff.SchemaDiff.AllOfDiff != nil && len(mediaTypeDiff.SchemaDiff.AllOfDiff.Deleted) > 0 { - result = append(result, ApiChange{ - Id: ResponseBodyAllOfRemovedId, - Level: INFO, - Args: []any{mediaTypeDiff.SchemaDiff.AllOfDiff.Deleted.String(), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyAllOfRemovedId, + INFO, + []any{mediaTypeDiff.SchemaDiff.AllOfDiff.Deleted.String(), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } CheckModifiedPropertiesDiff( @@ -73,28 +73,30 @@ func ResponsePropertyAllOfUpdatedCheck(diffReport *diff.Diff, operationsSources if len(propertyDiff.AllOfDiff.Added) > 0 { - result = append(result, ApiChange{ - Id: ResponsePropertyAllOfAddedId, - Level: INFO, - Args: []any{propertyDiff.AllOfDiff.Added.String(), propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyAllOfAddedId, + INFO, + []any{propertyDiff.AllOfDiff.Added.String(), propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } if len(propertyDiff.AllOfDiff.Deleted) > 0 { - result = append(result, ApiChange{ - Id: ResponsePropertyAllOfRemovedId, - Level: INFO, - Args: []any{propertyDiff.AllOfDiff.Deleted.String(), propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyAllOfRemovedId, + INFO, + []any{propertyDiff.AllOfDiff.Deleted.String(), propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_response_property_any_of_updated.go b/checker/check_response_property_any_of_updated.go index 8222bcec..6bf8bb36 100644 --- a/checker/check_response_property_any_of_updated.go +++ b/checker/check_response_property_any_of_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -27,7 +26,6 @@ func ResponsePropertyAnyOfUpdatedCheck(diffReport *diff.Diff, operationsSources if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responsesDiff := range operationItem.ResponsesDiff.Modified { if responsesDiff.ContentDiff == nil || responsesDiff.ContentDiff.MediaTypeModified == nil { @@ -41,27 +39,30 @@ func ResponsePropertyAnyOfUpdatedCheck(diffReport *diff.Diff, operationsSources } if mediaTypeDiff.SchemaDiff.AnyOfDiff != nil && len(mediaTypeDiff.SchemaDiff.AnyOfDiff.Added) > 0 { - result = append(result, ApiChange{ - Id: ResponseBodyAnyOfAddedId, - Level: INFO, - Args: []any{mediaTypeDiff.SchemaDiff.AnyOfDiff.Added.String(), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + + result = append(result, NewApiChange( + ResponseBodyAnyOfAddedId, + INFO, + []any{mediaTypeDiff.SchemaDiff.AnyOfDiff.Added.String(), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } if mediaTypeDiff.SchemaDiff.AnyOfDiff != nil && len(mediaTypeDiff.SchemaDiff.AnyOfDiff.Deleted) > 0 { - result = append(result, ApiChange{ - Id: ResponseBodyAnyOfRemovedId, - Level: INFO, - Args: []any{mediaTypeDiff.SchemaDiff.AnyOfDiff.Deleted.String(), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyAnyOfRemovedId, + INFO, + []any{mediaTypeDiff.SchemaDiff.AnyOfDiff.Deleted.String(), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } CheckModifiedPropertiesDiff( @@ -73,28 +74,30 @@ func ResponsePropertyAnyOfUpdatedCheck(diffReport *diff.Diff, operationsSources if len(propertyDiff.AnyOfDiff.Added) > 0 { - result = append(result, ApiChange{ - Id: ResponsePropertyAnyOfAddedId, - Level: INFO, - Args: []any{propertyDiff.AnyOfDiff.Added.String(), propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyAnyOfAddedId, + INFO, + []any{propertyDiff.AnyOfDiff.Added.String(), propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } if len(propertyDiff.AnyOfDiff.Deleted) > 0 { - result = append(result, ApiChange{ - Id: ResponsePropertyAnyOfRemovedId, - Level: INFO, - Args: []any{propertyDiff.AnyOfDiff.Deleted.String(), propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyAnyOfRemovedId, + INFO, + []any{propertyDiff.AnyOfDiff.Deleted.String(), propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_response_property_became_nuallable.go b/checker/check_response_property_became_nuallable.go index a6aaa1d8..71be93bf 100644 --- a/checker/check_response_property_became_nuallable.go +++ b/checker/check_response_property_became_nuallable.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -20,7 +19,6 @@ func ResponsePropertyBecameNullableCheck(diffReport *diff.Diff, operationsSource continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ResponsesDiff == nil { continue @@ -39,14 +37,16 @@ func ResponsePropertyBecameNullableCheck(diffReport *diff.Diff, operationsSource } if mediaTypeDiff.SchemaDiff.NullableDiff != nil && mediaTypeDiff.SchemaDiff.NullableDiff.To == true { - result = append(result, ApiChange{ - Id: ResponseBodyBecameNullableId, - Level: ERR, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyBecameNullableId, + ERR, + nil, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } CheckModifiedPropertiesDiff( @@ -60,15 +60,16 @@ func ResponsePropertyBecameNullableCheck(diffReport *diff.Diff, operationsSource return } - result = append(result, ApiChange{ - Id: ResponsePropertyBecameNullableId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyBecameNullableId, + ERR, + []any{propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_response_property_became_optional.go b/checker/check_response_property_became_optional.go index 72f3d49d..0a3fd8d6 100644 --- a/checker/check_response_property_became_optional.go +++ b/checker/check_response_property_became_optional.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -20,7 +19,6 @@ func ResponsePropertyBecameOptionalCheck(diffReport *diff.Diff, operationsSource continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ResponsesDiff == nil { continue @@ -51,15 +49,16 @@ func ResponsePropertyBecameOptionalCheck(diffReport *diff.Diff, operationsSource level = INFO } - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{changedRequiredPropertyName, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{changedRequiredPropertyName, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } @@ -86,15 +85,16 @@ func ResponsePropertyBecameOptionalCheck(diffReport *diff.Diff, operationsSource continue } - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName)), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName)), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_response_property_became_required.go b/checker/check_response_property_became_required.go index cf791119..12f9e906 100644 --- a/checker/check_response_property_became_required.go +++ b/checker/check_response_property_became_required.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -20,7 +19,6 @@ func ResponsePropertyBecameRequiredCheck(diffReport *diff.Diff, operationsSource continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ResponsesDiff == nil { continue @@ -53,15 +51,16 @@ func ResponsePropertyBecameRequiredCheck(diffReport *diff.Diff, operationsSource id = ResponseWriteOnlyPropertyBecameRequiredId } - result = append(result, ApiChange{ - Id: id, - Level: INFO, - Args: []any{changedRequiredPropertyName, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + INFO, + []any{propertyFullName("", changedRequiredPropertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } @@ -86,15 +85,16 @@ func ResponsePropertyBecameRequiredCheck(diffReport *diff.Diff, operationsSource id = ResponseWriteOnlyPropertyBecameRequiredId } - result = append(result, ApiChange{ - Id: id, - Level: INFO, - Args: []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName)), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + INFO, + []any{propertyFullName(propertyPath, propertyFullName(propertyName, changedRequiredPropertyName)), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_response_property_default_value_changed.go b/checker/check_response_property_default_value_changed.go index 7b372297..e671161a 100644 --- a/checker/check_response_property_default_value_changed.go +++ b/checker/check_response_property_default_value_changed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -24,21 +23,21 @@ func ResponsePropertyDefaultValueChangedCheck(diffReport *diff.Diff, operationsS continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } appendResultItem := func(messageId string, a ...any) { - result = append(result, ApiChange{ - Id: messageId, - Level: INFO, - Args: a, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + messageId, + INFO, + a, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { diff --git a/checker/check_response_property_enum_value_added.go b/checker/check_response_property_enum_value_added.go index bb53d9af..30f5a263 100644 --- a/checker/check_response_property_enum_value_added.go +++ b/checker/check_response_property_enum_value_added.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -23,7 +22,6 @@ func ResponsePropertyEnumValueAddedCheck(diffReport *diff.Diff, operationsSource if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { if responseDiff == nil || responseDiff.ContentDiff == nil || @@ -52,16 +50,16 @@ func ResponsePropertyEnumValueAddedCheck(diffReport *diff.Diff, operationsSource } for _, enumVal := range enumDiff.Added { - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{enumVal, propertyFullName(propertyPath, propertyName), responseStatus}, - Comment: comment, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{enumVal, propertyFullName(propertyPath, propertyName), responseStatus}, + comment, + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_response_property_enum_value_removed.go b/checker/check_response_property_enum_value_removed.go index b5568272..66547617 100644 --- a/checker/check_response_property_enum_value_removed.go +++ b/checker/check_response_property_enum_value_removed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -23,7 +22,6 @@ func ResponseParameterEnumValueRemovedCheck(diffReport *diff.Diff, operationsSou continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { if responseDiff == nil || responseDiff.ContentDiff == nil || @@ -40,15 +38,16 @@ func ResponseParameterEnumValueRemovedCheck(diffReport *diff.Diff, operationsSou } for _, enumVal := range enumDiff.Deleted { - result = append(result, ApiChange{ - Id: ResponsePropertyEnumValueRemovedId, - Level: config.getLogLevel(ResponsePropertyEnumValueRemovedId, INFO), - Args: []any{enumVal, propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyEnumValueRemovedId, + config.getLogLevel(ResponsePropertyEnumValueRemovedId, INFO), + []any{enumVal, propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_response_property_max_increased.go b/checker/check_response_property_max_increased.go index dae86ebd..8afb5098 100644 --- a/checker/check_response_property_max_increased.go +++ b/checker/check_response_property_max_increased.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -23,7 +22,6 @@ func ResponsePropertyMaxIncreasedCheck(diffReport *diff.Diff, operationsSources if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { if responseDiff == nil || responseDiff.ContentDiff == nil || @@ -37,15 +35,16 @@ func ResponsePropertyMaxIncreasedCheck(diffReport *diff.Diff, operationsSources if maxDiff.From != nil && maxDiff.To != nil { if IsIncreasedValue(maxDiff) { - result = append(result, ApiChange{ - Id: ResponseBodyMaxIncreasedId, - Level: ERR, - Args: []any{maxDiff.From, maxDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyMaxIncreasedId, + ERR, + []any{maxDiff.From, maxDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } @@ -69,15 +68,16 @@ func ResponsePropertyMaxIncreasedCheck(diffReport *diff.Diff, operationsSources return } - result = append(result, ApiChange{ - Id: ResponsePropertyMaxIncreasedId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName), maxDiff.From, maxDiff.To, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyMaxIncreasedId, + ERR, + []any{propertyFullName(propertyPath, propertyName), maxDiff.From, maxDiff.To, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } diff --git a/checker/check_response_property_max_length_increased.go b/checker/check_response_property_max_length_increased.go index 6608f75b..ce5e9dc6 100644 --- a/checker/check_response_property_max_length_increased.go +++ b/checker/check_response_property_max_length_increased.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -23,7 +22,6 @@ func ResponsePropertyMaxLengthIncreasedCheck(diffReport *diff.Diff, operationsSo if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { if responseDiff == nil || responseDiff.ContentDiff == nil || @@ -37,15 +35,16 @@ func ResponsePropertyMaxLengthIncreasedCheck(diffReport *diff.Diff, operationsSo if maxLengthDiff.From != nil && maxLengthDiff.To != nil { if IsIncreasedValue(maxLengthDiff) { - result = append(result, ApiChange{ - Id: ResponseBodyMaxLengthIncreasedId, - Level: ERR, - Args: []any{maxLengthDiff.From, maxLengthDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyMaxLengthIncreasedId, + ERR, + []any{maxLengthDiff.From, maxLengthDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } @@ -69,15 +68,16 @@ func ResponsePropertyMaxLengthIncreasedCheck(diffReport *diff.Diff, operationsSo return } - result = append(result, ApiChange{ - Id: ResponsePropertyMaxLengthIncreasedId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName), maxLengthDiff.From, maxLengthDiff.To, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyMaxLengthIncreasedId, + ERR, + []any{propertyFullName(propertyPath, propertyName), maxLengthDiff.From, maxLengthDiff.To, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_response_property_max_length_unset.go b/checker/check_response_property_max_length_unset.go index 8569541d..b2b4feea 100644 --- a/checker/check_response_property_max_length_unset.go +++ b/checker/check_response_property_max_length_unset.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -23,7 +22,6 @@ func ResponsePropertyMaxLengthUnsetCheck(diffReport *diff.Diff, operationsSource if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { if responseDiff == nil || responseDiff.ContentDiff == nil || @@ -36,15 +34,16 @@ func ResponsePropertyMaxLengthUnsetCheck(diffReport *diff.Diff, operationsSource maxLengthDiff := mediaTypeDiff.SchemaDiff.MaxLengthDiff if maxLengthDiff.From != nil && maxLengthDiff.To == nil { - result = append(result, ApiChange{ - Id: ResponseBodyMaxLengthUnsetId, - Level: ERR, - Args: []any{maxLengthDiff.From}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyMaxLengthUnsetId, + ERR, + []any{maxLengthDiff.From}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } @@ -63,15 +62,16 @@ func ResponsePropertyMaxLengthUnsetCheck(diffReport *diff.Diff, operationsSource return } - result = append(result, ApiChange{ - Id: ResponsePropertyMaxLengthUnsetId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName), maxLengthDiff.From, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyMaxLengthUnsetId, + ERR, + []any{propertyFullName(propertyPath, propertyName), maxLengthDiff.From, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_response_property_min_decreased.go b/checker/check_response_property_min_decreased.go index 7be83ad3..cff0b317 100644 --- a/checker/check_response_property_min_decreased.go +++ b/checker/check_response_property_min_decreased.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -23,7 +22,6 @@ func ResponsePropertyMinDecreasedCheck(diffReport *diff.Diff, operationsSources if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { if responseDiff == nil || responseDiff.ContentDiff == nil || @@ -37,15 +35,16 @@ func ResponsePropertyMinDecreasedCheck(diffReport *diff.Diff, operationsSources if minDiff.From != nil && minDiff.To != nil { if IsDecreasedValue(minDiff) { - result = append(result, ApiChange{ - Id: ResponseBodyMinDecreasedId, - Level: ERR, - Args: []any{minDiff.From, minDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyMinDecreasedId, + ERR, + []any{minDiff.From, minDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } @@ -69,15 +68,16 @@ func ResponsePropertyMinDecreasedCheck(diffReport *diff.Diff, operationsSources return } - result = append(result, ApiChange{ - Id: ResponsePropertyMinDecreasedId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName), minDiff.From, minDiff.To, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyMinDecreasedId, + ERR, + []any{propertyFullName(propertyPath, propertyName), minDiff.From, minDiff.To, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_response_property_min_items_decreased.go b/checker/check_response_property_min_items_decreased.go index 4e238500..682f4774 100644 --- a/checker/check_response_property_min_items_decreased.go +++ b/checker/check_response_property_min_items_decreased.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -23,7 +22,6 @@ func ResponsePropertyMinItemsDecreasedCheck(diffReport *diff.Diff, operationsSou if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { if responseDiff == nil || responseDiff.ContentDiff == nil || @@ -37,15 +35,16 @@ func ResponsePropertyMinItemsDecreasedCheck(diffReport *diff.Diff, operationsSou if minItemsDiff.From != nil && minItemsDiff.To != nil { if IsDecreasedValue(minItemsDiff) { - result = append(result, ApiChange{ - Id: ResponseBodyMinItemsDecreasedId, - Level: ERR, - Args: []any{minItemsDiff.From, minItemsDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyMinItemsDecreasedId, + ERR, + []any{minItemsDiff.From, minItemsDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } @@ -69,15 +68,16 @@ func ResponsePropertyMinItemsDecreasedCheck(diffReport *diff.Diff, operationsSou return } - result = append(result, ApiChange{ - Id: ResponsePropertyMinItemsDecreasedId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName), minItemsDiff.From, minItemsDiff.To, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyMinItemsDecreasedId, + ERR, + []any{propertyFullName(propertyPath, propertyName), minItemsDiff.From, minItemsDiff.To, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_response_property_min_items_unset.go b/checker/check_response_property_min_items_unset.go index 80b5e97e..af7d8b37 100644 --- a/checker/check_response_property_min_items_unset.go +++ b/checker/check_response_property_min_items_unset.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -23,7 +22,6 @@ func ResponsePropertyMinItemsUnsetCheck(diffReport *diff.Diff, operationsSources if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { if responseDiff == nil || responseDiff.ContentDiff == nil || @@ -36,15 +34,16 @@ func ResponsePropertyMinItemsUnsetCheck(diffReport *diff.Diff, operationsSources minItemsDiff := mediaTypeDiff.SchemaDiff.MinItemsDiff if minItemsDiff.From != nil && minItemsDiff.To == nil { - result = append(result, ApiChange{ - Id: ResponseBodyMinItemsUnsetId, - Level: ERR, - Args: []any{minItemsDiff.From}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyMinItemsUnsetId, + ERR, + []any{minItemsDiff.From}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } @@ -63,15 +62,16 @@ func ResponsePropertyMinItemsUnsetCheck(diffReport *diff.Diff, operationsSources return } - result = append(result, ApiChange{ - Id: ResponsePropertyMinItemsUnsetId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName), minItemsDiff.From, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyMinItemsUnsetId, + ERR, + []any{propertyFullName(propertyPath, propertyName), minItemsDiff.From, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } diff --git a/checker/check_response_property_min_length_decreased.go b/checker/check_response_property_min_length_decreased.go index 89cf92f7..faf59808 100644 --- a/checker/check_response_property_min_length_decreased.go +++ b/checker/check_response_property_min_length_decreased.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -23,7 +22,6 @@ func ResponsePropertyMinLengthDecreasedCheck(diffReport *diff.Diff, operationsSo if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { if responseDiff == nil || responseDiff.ContentDiff == nil || @@ -37,15 +35,16 @@ func ResponsePropertyMinLengthDecreasedCheck(diffReport *diff.Diff, operationsSo if minLengthDiff.From != nil && minLengthDiff.To != nil { if IsDecreasedValue(minLengthDiff) { - result = append(result, ApiChange{ - Id: ResponseBodyMinLengthDecreasedId, - Level: ERR, - Args: []any{minLengthDiff.From, minLengthDiff.To}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyMinLengthDecreasedId, + ERR, + []any{minLengthDiff.From, minLengthDiff.To}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } @@ -69,15 +68,16 @@ func ResponsePropertyMinLengthDecreasedCheck(diffReport *diff.Diff, operationsSo return } - result = append(result, ApiChange{ - Id: ResponsePropertyMinLengthDecreasedId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName), minLengthDiff.From, minLengthDiff.To, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyMinLengthDecreasedId, + ERR, + []any{propertyFullName(propertyPath, propertyName), minLengthDiff.From, minLengthDiff.To, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_response_property_one_of_updated.go b/checker/check_response_property_one_of_updated.go index 19a909cb..4540deca 100644 --- a/checker/check_response_property_one_of_updated.go +++ b/checker/check_response_property_one_of_updated.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -27,7 +26,6 @@ func ResponsePropertyOneOfUpdated(diffReport *diff.Diff, operationsSources *diff if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for responseStatus, responsesDiff := range operationItem.ResponsesDiff.Modified { if responsesDiff.ContentDiff == nil || responsesDiff.ContentDiff.MediaTypeModified == nil { @@ -41,27 +39,29 @@ func ResponsePropertyOneOfUpdated(diffReport *diff.Diff, operationsSources *diff } if mediaTypeDiff.SchemaDiff.OneOfDiff != nil && len(mediaTypeDiff.SchemaDiff.OneOfDiff.Added) > 0 { - result = append(result, ApiChange{ - Id: ResponseBodyOneOfAddedId, - Level: INFO, - Args: []any{mediaTypeDiff.SchemaDiff.OneOfDiff.Added.String(), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyOneOfAddedId, + INFO, + []any{mediaTypeDiff.SchemaDiff.OneOfDiff.Added.String(), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } if mediaTypeDiff.SchemaDiff.OneOfDiff != nil && len(mediaTypeDiff.SchemaDiff.OneOfDiff.Deleted) > 0 { - result = append(result, ApiChange{ - Id: ResponseBodyOneOfRemovedId, - Level: INFO, - Args: []any{mediaTypeDiff.SchemaDiff.OneOfDiff.Deleted.String(), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyOneOfRemovedId, + INFO, + []any{mediaTypeDiff.SchemaDiff.OneOfDiff.Deleted.String(), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } CheckModifiedPropertiesDiff( @@ -74,27 +74,29 @@ func ResponsePropertyOneOfUpdated(diffReport *diff.Diff, operationsSources *diff propName := propertyFullName(propertyPath, propertyName) if len(propertyDiff.OneOfDiff.Added) > 0 { - result = append(result, ApiChange{ - Id: ResponsePropertyOneOfAddedId, - Level: INFO, - Args: []any{propertyDiff.OneOfDiff.Added.String(), propName, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyOneOfAddedId, + INFO, + []any{propertyDiff.OneOfDiff.Added.String(), propName, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } if len(propertyDiff.OneOfDiff.Deleted) > 0 { - result = append(result, ApiChange{ - Id: ResponsePropertyOneOfRemovedId, - Level: INFO, - Args: []any{propertyDiff.OneOfDiff.Deleted.String(), propName, responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyOneOfRemovedId, + INFO, + []any{propertyDiff.OneOfDiff.Deleted.String(), propName, responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_response_property_type_changed.go b/checker/check_response_property_type_changed.go index c6e26caa..8c1374a7 100644 --- a/checker/check_response_property_type_changed.go +++ b/checker/check_response_property_type_changed.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -20,7 +19,6 @@ func ResponsePropertyTypeChangedCheck(diffReport *diff.Diff, operationsSources * continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { continue } @@ -39,15 +37,16 @@ func ResponsePropertyTypeChangedCheck(diffReport *diff.Diff, operationsSources * formatDiff := schemaDiff.FormatDiff if breakingTypeFormatChangedInResponseProperty(typeDiff, formatDiff, mediaType, schemaDiff) { - result = append(result, ApiChange{ - Id: ResponseBodyTypeChangedId, - Level: ERR, - Args: []any{getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponseBodyTypeChangedId, + ERR, + []any{getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } @@ -64,15 +63,16 @@ func ResponsePropertyTypeChangedCheck(diffReport *diff.Diff, operationsSources * if breakingTypeFormatChangedInResponseProperty(typeDiff, formatDiff, mediaType, schemaDiff) { - result = append(result, ApiChange{ - Id: ResponsePropertyTypeChangedId, - Level: ERR, - Args: []any{propertyFullName(propertyPath, propertyName), getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + ResponsePropertyTypeChangedId, + ERR, + []any{propertyFullName(propertyPath, propertyName), getBaseType(schemaDiff), getBaseFormat(schemaDiff), getRevisionType(schemaDiff), getRevisionFormat(schemaDiff), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } }) } diff --git a/checker/check_response_required_property_updated.go b/checker/check_response_required_property_updated.go index 7accecbb..13a1c50f 100644 --- a/checker/check_response_required_property_updated.go +++ b/checker/check_response_required_property_updated.go @@ -3,7 +3,6 @@ package checker import ( "github.com/getkin/kin-openapi/openapi3" "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" "golang.org/x/exp/slices" ) @@ -24,7 +23,6 @@ func ResponseRequiredPropertyUpdatedCheck(diffReport *diff.Diff, operationsSourc continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ResponsesDiff == nil { continue @@ -52,15 +50,16 @@ func ResponseRequiredPropertyUpdatedCheck(diffReport *diff.Diff, operationsSourc return } - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) CheckAddedPropertiesDiff( mediaTypeDiff.SchemaDiff, @@ -74,15 +73,16 @@ func ResponseRequiredPropertyUpdatedCheck(diffReport *diff.Diff, operationsSourc return } - result = append(result, ApiChange{ - Id: id, - Level: INFO, - Args: []any{propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + INFO, + []any{propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_response_required_property_write_only_read_only.go b/checker/check_response_required_property_write_only_read_only.go index 1a88652a..b1a33349 100644 --- a/checker/check_response_required_property_write_only_read_only.go +++ b/checker/check_response_required_property_write_only_read_only.go @@ -2,7 +2,6 @@ package checker import ( "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" "golang.org/x/exp/slices" ) @@ -23,7 +22,6 @@ func ResponseRequiredPropertyWriteOnlyReadOnlyCheck(diffReport *diff.Diff, opera continue } for operation, operationItem := range pathItem.OperationsDiff.Modified { - source := (*operationsSources)[operationItem.Revision] if operationItem.ResponsesDiff == nil { continue @@ -67,16 +65,16 @@ func ResponseRequiredPropertyWriteOnlyReadOnlyCheck(diffReport *diff.Diff, opera comment = "" } - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{propertyFullName(propertyPath, propertyName), responseStatus}, - Comment: comment, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{propertyFullName(propertyPath, propertyName), responseStatus}, + comment, + operationsSources, + operationItem.Revision, + operation, + path, + )) }) CheckModifiedPropertiesDiff( @@ -103,15 +101,16 @@ func ResponseRequiredPropertyWriteOnlyReadOnlyCheck(diffReport *diff.Diff, opera level = INFO } - result = append(result, ApiChange{ - Id: id, - Level: level, - Args: []any{propertyFullName(propertyPath, propertyName), responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + level, + []any{propertyFullName(propertyPath, propertyName), responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) }) } } diff --git a/checker/check_response_status_updated.go b/checker/check_response_status_updated.go index 3edcfb4a..3628f07b 100644 --- a/checker/check_response_status_updated.go +++ b/checker/check_response_status_updated.go @@ -5,7 +5,6 @@ import ( "strings" "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/load" ) const ( @@ -47,7 +46,6 @@ func responseStatusUpdated(diffReport *diff.Diff, operationsSources *diff.Operat if operationItem.ResponsesDiff.Modified == nil { continue } - source := (*operationsSources)[operationItem.Revision] for _, responseStatus := range operationItem.ResponsesDiff.Deleted { status, err := strconv.Atoi(responseStatus) if err != nil { @@ -55,15 +53,16 @@ func responseStatusUpdated(diffReport *diff.Diff, operationsSources *diff.Operat } if filter(status) { - result = append(result, ApiChange{ - Id: id, - Level: config.getLogLevel(id, defaultLevel), - Args: []any{responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + id, + config.getLogLevel(id, defaultLevel), + []any{responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } @@ -75,15 +74,16 @@ func responseStatusUpdated(diffReport *diff.Diff, operationsSources *diff.Operat } if filter(status) { - result = append(result, ApiChange{ - Id: addedId, - Level: config.getLogLevel(addedId, INFO), - Args: []any{responseStatus}, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + addedId, + config.getLogLevel(addedId, INFO), + []any{responseStatus}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) } } } diff --git a/checker/checker.go b/checker/checker.go index 0d0a5e86..ad44fbbd 100644 --- a/checker/checker.go +++ b/checker/checker.go @@ -111,16 +111,17 @@ func removeDraftAndAlphaOperationsDiffs(config *Config, diffReport *diff.Diff, r baseStability == STABILITY_BETA && revisionStability != STABILITY_BETA && revisionStability != STABILITY_STABLE || baseStability == STABILITY_ALPHA && revisionStability != STABILITY_ALPHA && revisionStability != STABILITY_BETA && revisionStability != STABILITY_STABLE || revisionStability == "" && baseStability != "" { - source := (*operationsSources)[pathDiff.Revision.GetOperation(operation)] - result = append(result, ApiChange{ - Id: APIStabilityDecreasedId, - Args: []any{baseStability, revisionStability}, - Level: ERR, - Operation: operation, - OperationId: operationItem.Revision.OperationID, - Path: path, - Source: load.NewSource(source), - }) + result = append(result, NewApiChange( + APIStabilityDecreasedId, + ERR, + []any{baseStability, revisionStability}, + "", + operationsSources, + operationItem.Revision, + operation, + path, + )) + continue } if revisionStability == STABILITY_DRAFT || revisionStability == STABILITY_ALPHA { diff --git a/checker/localizations/localizations.go b/checker/localizations/localizations.go index 9bf2620d..f2f3afc3 100644 --- a/checker/localizations/localizations.go +++ b/checker/localizations/localizations.go @@ -1,6 +1,6 @@ // Code generated by go-localize; DO NOT EDIT. // This file was generated by robots at -// 2024-06-29 22:12:45.259129 +0300 IDT m=+0.006377824 +// 2024-07-03 20:03:30.088423 +0300 IDT m=+0.012970085 package localizations @@ -537,10 +537,6 @@ var localizations = map[string]string{ "en.messages.sunset-deleted-description": "sunset deleted", "en.messages.total-changes": "%d changes: %d %s, %d %s, %d %s\n", "en.messages.total-errors": "%d breaking changes: %d %s, %d %s\n", - "en.messages.unparseable-parameter-from-x-extensible-enum-description": "unparseable x-extensible-enum in original request parameter", - "en.messages.unparseable-parameter-to-x-extensible-enum-description": "unparseable x-extensible-enum in revised request parameter", - "en.messages.unparseable-property-from-x-extensible-enum-description": "unparseable x-extensible-enum in original request property", - "en.messages.unparseable-property-to-x-extensible-enum-description": "unparseable x-extensible-enum in revised request property", "ru.messages.api-deprecated-sunset-missing": "API устарел без даты прекращения действия", "ru.messages.api-deprecated-sunset-parse": "не удалось проанализировать дату заката: %v", "ru.messages.api-global-security-added": "схема безопасности %s была добавлена к API", diff --git a/checker/localizations_src/en/messages.yaml b/checker/localizations_src/en/messages.yaml index a5fd4d48..c8f29e1f 100644 --- a/checker/localizations_src/en/messages.yaml +++ b/checker/localizations_src/en/messages.yaml @@ -524,7 +524,3 @@ response-write-only-property-became-optional-description: response write-only pr response-write-only-property-became-required-description: response write-only property became required response-write-only-property-enum-value-added-description: response write-only property enum value added sunset-deleted-description: sunset deleted -unparseable-parameter-from-x-extensible-enum-description: unparseable x-extensible-enum in original request parameter -unparseable-parameter-to-x-extensible-enum-description: unparseable x-extensible-enum in revised request parameter -unparseable-property-from-x-extensible-enum-description: unparseable x-extensible-enum in original request property -unparseable-property-to-x-extensible-enum-description: unparseable x-extensible-enum in revised request property \ No newline at end of file diff --git a/checker/rules.go b/checker/rules.go index bc569ef1..c9b41128 100644 --- a/checker/rules.go +++ b/checker/rules.go @@ -143,8 +143,6 @@ func GetAllRules() []BackwardCompatibilityRule { newBackwardCompatibilityRule(RequestParameterTypeChangedId, ERR, true, RequestParameterTypeChangedCheck), newBackwardCompatibilityRule(RequestParameterPropertyTypeChangedId, ERR, true, RequestParameterTypeChangedCheck), // RequestParameterXExtensibleEnumValueRemovedCheck - newBackwardCompatibilityRule(UnparsableParameterFromXExtensibleEnumId, ERR, true, RequestParameterXExtensibleEnumValueRemovedCheck), - newBackwardCompatibilityRule(UnparsableParameterToXExtensibleEnumId, ERR, true, RequestParameterXExtensibleEnumValueRemovedCheck), newBackwardCompatibilityRule(RequestParameterXExtensibleEnumValueRemovedId, ERR, true, RequestParameterXExtensibleEnumValueRemovedCheck), // RequestPropertyAllOfUpdatedCheck newBackwardCompatibilityRule(RequestBodyAllOfAddedId, ERR, true, RequestPropertyAllOfUpdatedCheck), @@ -239,8 +237,6 @@ func GetAllRules() []BackwardCompatibilityRule { newBackwardCompatibilityRule(RequestRequiredPropertyBecameReadOnlyCheckId, INFO, true, RequestPropertyWriteOnlyReadOnlyCheck), newBackwardCompatibilityRule(RequestRequiredPropertyBecameNonReadOnlyCheckId, INFO, true, RequestPropertyWriteOnlyReadOnlyCheck), // RequestPropertyXExtensibleEnumValueRemovedCheck - newBackwardCompatibilityRule(UnparseablePropertyFromXExtensibleEnumId, ERR, true, RequestPropertyXExtensibleEnumValueRemovedCheck), - newBackwardCompatibilityRule(UnparseablePropertyToXExtensibleEnumId, ERR, true, RequestPropertyXExtensibleEnumValueRemovedCheck), newBackwardCompatibilityRule(RequestPropertyXExtensibleEnumValueRemovedId, ERR, true, RequestPropertyXExtensibleEnumValueRemovedCheck), // ResponseDiscriminatorUpdatedCheck newBackwardCompatibilityRule(ResponseBodyDiscriminatorAddedId, INFO, true, ResponseDiscriminatorUpdatedCheck), diff --git a/data/checker/request_body_max_length_set_base.yaml b/data/checker/request_body_max_length_set_base.yaml new file mode 100644 index 00000000..1d810788 --- /dev/null +++ b/data/checker/request_body_max_length_set_base.yaml @@ -0,0 +1,16 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /pets: + post: + operationId: addPet + requestBody: + content: + text/plain: + schema: + type: string + responses: + "200": + description: OK diff --git a/data/checker/request_body_max_length_set_revision.yaml b/data/checker/request_body_max_length_set_revision.yaml new file mode 100644 index 00000000..8c23a83e --- /dev/null +++ b/data/checker/request_body_max_length_set_revision.yaml @@ -0,0 +1,17 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /pets: + post: + operationId: addPet + requestBody: + content: + text/plain: + schema: + type: string + maxLength: 15 + responses: + "200": + description: OK diff --git a/data/checker/request_body_max_set_base.yaml b/data/checker/request_body_max_set_base.yaml new file mode 100644 index 00000000..a51bb0c0 --- /dev/null +++ b/data/checker/request_body_max_set_base.yaml @@ -0,0 +1,16 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /pets: + post: + operationId: addPet + requestBody: + content: + text/plain: + schema: + type: number + responses: + "200": + description: OK diff --git a/data/checker/request_body_max_set_revision.yaml b/data/checker/request_body_max_set_revision.yaml new file mode 100644 index 00000000..65255d6c --- /dev/null +++ b/data/checker/request_body_max_set_revision.yaml @@ -0,0 +1,17 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /pets: + post: + operationId: addPet + requestBody: + content: + text/plain: + schema: + type: number + maximum: 15 + responses: + "200": + description: OK diff --git a/data/checker/request_parameter_extensible_enum_base.yaml b/data/checker/request_parameter_extensible_enum_base.yaml new file mode 100644 index 00000000..39e802ad --- /dev/null +++ b/data/checker/request_parameter_extensible_enum_base.yaml @@ -0,0 +1,60 @@ +openapi: 3.0.1 +info: + title: Tufin + version: "2.0" +servers: +- url: https://localhost:9080 +paths: + /api/v1.0/groups: + post: + operationId: createOneGroup + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/GroupView' + description: Creates one project. + required: true + parameters: + - in: path + name: groupId + required: true + schema: + type: string + x-extensible-enum: + - "1" + - "2" + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/GroupView' + description: OK + "409": + content: + application/json: + schema: + $ref: '#/components/schemas/GroupView' + description: Conflict + summary: Create One Project +components: + schemas: + GroupView: + type: object + properties: + data: + type: object + properties: + created: + type: string + format: date-time + readOnly: true + pattern: "^[a-z]+$" + id: + type: string + readOnly: true + name: + type: string + required: + - name \ No newline at end of file diff --git a/data/checker/request_parameter_extensible_enum_revision.yaml b/data/checker/request_parameter_extensible_enum_revision.yaml new file mode 100644 index 00000000..6405ba9e --- /dev/null +++ b/data/checker/request_parameter_extensible_enum_revision.yaml @@ -0,0 +1,59 @@ +openapi: 3.0.1 +info: + title: Tufin + version: "2.0" +servers: +- url: https://localhost:9080 +paths: + /api/v1.0/groups: + post: + operationId: createOneGroup + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/GroupView' + description: Creates one project. + required: true + parameters: + - in: path + name: groupId + required: true + schema: + type: string + x-extensible-enum: + - "1" + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/GroupView' + description: OK + "409": + content: + application/json: + schema: + $ref: '#/components/schemas/GroupView' + description: Conflict + summary: Create One Project +components: + schemas: + GroupView: + type: object + properties: + data: + type: object + properties: + created: + type: string + format: date-time + readOnly: true + pattern: "^[a-z]+$" + id: + type: string + readOnly: true + name: + type: string + required: + - name \ No newline at end of file diff --git a/data/checker/request_parameter_max_length_set_base.yaml b/data/checker/request_parameter_max_length_set_base.yaml new file mode 100644 index 00000000..2266e188 --- /dev/null +++ b/data/checker/request_parameter_max_length_set_base.yaml @@ -0,0 +1,15 @@ +openapi: 3.0.1 +info: + title: Test API + version: "1.0" +paths: + /test: + post: + parameters: + - in: query + name: category + schema: + type: string + responses: + "200": + description: OK diff --git a/data/checker/request_parameter_max_length_set_revision.yaml b/data/checker/request_parameter_max_length_set_revision.yaml new file mode 100644 index 00000000..9a9a8449 --- /dev/null +++ b/data/checker/request_parameter_max_length_set_revision.yaml @@ -0,0 +1,16 @@ +openapi: 3.0.1 +info: + title: Test API + version: "2.0" +paths: + /test: + post: + parameters: + - in: query + name: category + schema: + type: string + maxLength: 15 + responses: + "200": + description: OK diff --git a/data/checker/request_property_extensible_enum_base.yaml b/data/checker/request_property_extensible_enum_base.yaml new file mode 100644 index 00000000..9b90bb98 --- /dev/null +++ b/data/checker/request_property_extensible_enum_base.yaml @@ -0,0 +1,24 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /pets: + post: + operationId: addPet + requestBody: + content: + application/json: + schema: + type: object + properties: + name: + type: string + x-extensible-enum: + - available + - pending + - sold + responses: + "200": + description: OK + diff --git a/data/checker/request_property_extensible_enum_revision.yaml b/data/checker/request_property_extensible_enum_revision.yaml new file mode 100644 index 00000000..3edefb38 --- /dev/null +++ b/data/checker/request_property_extensible_enum_revision.yaml @@ -0,0 +1,23 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /pets: + post: + operationId: addPet + requestBody: + content: + application/json: + schema: + type: object + properties: + name: + type: string + x-extensible-enum: + - available + - pending + responses: + "200": + description: OK + diff --git a/data/checker/request_property_max_length_set_base.yaml b/data/checker/request_property_max_length_set_base.yaml new file mode 100644 index 00000000..5d8ec950 --- /dev/null +++ b/data/checker/request_property_max_length_set_base.yaml @@ -0,0 +1,22 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /pets: + post: + operationId: addPet + requestBody: + content: + application/json: + schema: + type: object + properties: + age: + type: string + required: + - age + responses: + "200": + description: OK + diff --git a/data/checker/request_property_max_length_set_revision.yaml b/data/checker/request_property_max_length_set_revision.yaml new file mode 100644 index 00000000..687a264b --- /dev/null +++ b/data/checker/request_property_max_length_set_revision.yaml @@ -0,0 +1,23 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /pets: + post: + operationId: addPet + requestBody: + content: + application/json: + schema: + type: object + properties: + age: + type: string + maxLength: 15 + required: + - age + responses: + "200": + description: OK + diff --git a/data/checker/request_property_max_set_base.yaml b/data/checker/request_property_max_set_base.yaml new file mode 100644 index 00000000..04a11be8 --- /dev/null +++ b/data/checker/request_property_max_set_base.yaml @@ -0,0 +1,22 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /pets: + post: + operationId: addPet + requestBody: + content: + application/json: + schema: + type: object + properties: + age: + type: integer + required: + - age + responses: + "200": + description: OK + diff --git a/data/checker/request_property_max_set_revision.yaml b/data/checker/request_property_max_set_revision.yaml new file mode 100644 index 00000000..0cbdc334 --- /dev/null +++ b/data/checker/request_property_max_set_revision.yaml @@ -0,0 +1,23 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /pets: + post: + operationId: addPet + requestBody: + content: + application/json: + schema: + type: object + properties: + age: + type: integer + maximum: 15 + required: + - age + responses: + "200": + description: OK + diff --git a/docs/BREAKING-CHANGES-EXAMPLES.md b/docs/BREAKING-CHANGES-EXAMPLES.md index 68d78ea5..2031f9ba 100644 --- a/docs/BREAKING-CHANGES-EXAMPLES.md +++ b/docs/BREAKING-CHANGES-EXAMPLES.md @@ -1,6 +1,8 @@ # Examples of Breaking and Non-Breaking Changes These examples are automatically generated from unit tests. ## Examples of breaking changes +[Deleting a value from an x-extensible-enum parameter is breaking](../checker/check_request_parameter_x_extensible_enum_value_removed_test.go?plain=1#L11) +[Deleting a value from an x-extensible-enum property is breaking](../checker/check_request_property_x_extensible_enum_value_removed_test.go?plain=1#L11) [adding 'allOf' subschema to the request body or request body property is breaking](../checker/check_breaking_test.go?plain=1#L712) [adding a new required property in request body is breaking](../checker/check_breaking_property_test.go?plain=1#L353) [adding a pattern to a schema is breaking for recursive properties](../checker/check_breaking_test.go?plain=1#L490) @@ -330,5 +332,10 @@ These examples are automatically generated from unit tests. [removing request property pattern](../checker/check_request_property_pattern_added_or_changed_test.go?plain=1#L60) [removing response body default value or response body property default value](../checker/check_response_property_default_value_changed_test.go?plain=1#L97) [removing response property pattern](../checker/check_response_pattern_added_or_changed_test.go?plain=1#L62) +[setting max of request body](../checker/check_request_property_max_set_test.go?plain=1#L12) +[setting max of request propreties](../checker/check_request_property_max_set_test.go?plain=1#L35) +[setting maxLength of request body](../checker/check_request_property_max_length_set_test.go?plain=1#L12) +[setting maxLength of request parameters](../checker/check_request_parameters_max_length_set_test.go?plain=1#L12) +[setting maxLength of request propreties](../checker/check_request_property_max_length_set_test.go?plain=1#L35) [updating an existing operation id](../checker/check_api_operation_id_updated_test.go?plain=1#L36) [updating an existing tag](../checker/check_api_tag_updated_test.go?plain=1#L64)