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 583212b commit 17392a3
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 129 deletions.
59 changes: 30 additions & 29 deletions checker/check_request_property_x_extensible_enum_value_removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"

"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
"golang.org/x/exp/slices"
)

Expand All @@ -29,7 +28,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 {
Expand All @@ -55,28 +53,30 @@ func RequestPropertyXExtensibleEnumValueRemovedCheck(diffReport *diff.Diff, oper
}
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),
})
result = append(result, NewApiChange(
UnparseablePropertyFromXExtensibleEnumId,
ERR,
[]any{propertyFullName(propertyPath, propertyName)},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))

Check warning on line 65 in checker/check_request_property_x_extensible_enum_value_removed.go

View check run for this annotation

Codecov / codecov/patch

checker/check_request_property_x_extensible_enum_value_removed.go#L56-L65

Added lines #L56 - L65 were not covered by tests
return
}
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),
})
result = append(result, NewApiChange(
UnparseablePropertyToXExtensibleEnumId,
ERR,
[]any{propertyFullName(propertyPath, propertyName)},
"",
operationsSources,
operationItem.Revision,
operation,
path,
))

Check warning on line 79 in checker/check_request_property_x_extensible_enum_value_removed.go

View check run for this annotation

Codecov / codecov/patch

checker/check_request_property_x_extensible_enum_value_removed.go#L70-L79

Added lines #L70 - L79 were not covered by tests
return
}

Expand All @@ -91,15 +91,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,
))

Check warning on line 103 in checker/check_request_property_x_extensible_enum_value_removed.go

View check run for this annotation

Codecov / codecov/patch

checker/check_request_property_x_extensible_enum_value_removed.go#L94-L103

Added lines #L94 - L103 were not covered by tests
}
})
}
Expand Down
21 changes: 10 additions & 11 deletions checker/check_response_discriminator_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 Down Expand Up @@ -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 {
Expand Down
21 changes: 10 additions & 11 deletions checker/check_response_header_became_optional.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 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
Expand All @@ -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,
))
}
}
}
Expand Down
40 changes: 20 additions & 20 deletions checker/check_response_header_removed.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 @@ -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
Expand All @@ -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,
))
}
}
}
Expand Down
21 changes: 10 additions & 11 deletions checker/check_response_mediatype_enum_value_removed.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 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
Expand All @@ -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,
))
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions checker/check_response_property_became_optional.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,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,
))
}
})
}
Expand Down
Loading

0 comments on commit 17392a3

Please sign in to comment.