Skip to content

Commit

Permalink
use ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven committed Jul 3, 2024
1 parent b9e5b13 commit acf9bfe
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 130 deletions.
42 changes: 20 additions & 22 deletions checker/check_request_property_max_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package checker

import (
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand All @@ -25,24 +24,23 @@ 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 {
if mediaTypeDiff.SchemaDiff != nil && mediaTypeDiff.SchemaDiff.MaxDiff != nil {
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,
))

Check warning on line 43 in checker/check_request_property_max_set.go

View check run for this annotation

Codecov / codecov/patch

checker/check_request_property_max_set.go#L34-L43

Added lines #L34 - L43 were not covered by tests
}
}

Expand All @@ -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},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))

Check warning on line 71 in checker/check_request_property_max_set.go

View check run for this annotation

Codecov / codecov/patch

checker/check_request_property_max_set.go#L62-L71

Added lines #L62 - L71 were not covered by tests
})
}
}
Expand Down
78 changes: 40 additions & 38 deletions checker/check_request_property_max_updated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package checker

import (
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand All @@ -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 {
Expand All @@ -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,
))
}
}
}
Expand All @@ -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,
))
}

})
Expand Down
40 changes: 20 additions & 20 deletions checker/check_request_property_min_items_increased.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package checker

import (
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand All @@ -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 {
Expand All @@ -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,
))

Check warning on line 44 in checker/check_request_property_min_items_increased.go

View check run for this annotation

Codecov / codecov/patch

checker/check_request_property_min_items_increased.go#L35-L44

Added lines #L35 - L44 were not covered by tests
}
}
}
Expand All @@ -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,
))

Check warning on line 76 in checker/check_request_property_min_items_increased.go

View check run for this annotation

Codecov / codecov/patch

checker/check_request_property_min_items_increased.go#L67-L76

Added lines #L67 - L76 were not covered by tests
})
}
}
Expand Down
78 changes: 40 additions & 38 deletions checker/check_request_property_min_length_updated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package checker

import (
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand All @@ -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 {
Expand All @@ -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,
))
}
}
}
Expand All @@ -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,
))
}
})
}
Expand Down
22 changes: 10 additions & 12 deletions checker/check_request_property_min_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package checker

import (
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
))

Check warning on line 71 in checker/check_request_property_min_set.go

View check run for this annotation

Codecov / codecov/patch

checker/check_request_property_min_set.go#L62-L71

Added lines #L62 - L71 were not covered by tests
})
}
}
Expand Down

0 comments on commit acf9bfe

Please sign in to comment.