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_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, + )) } }) }