Skip to content

Commit

Permalink
change constructors (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison authored Jul 4, 2024
1 parent 39b7e93 commit 2a50ce0
Show file tree
Hide file tree
Showing 111 changed files with 2,294 additions and 1,803 deletions.
15 changes: 15 additions & 0 deletions checker/api_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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"
}
Expand Down
20 changes: 10 additions & 10 deletions checker/check_added_required_request_body.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 @@ -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,
))
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions checker/check_api_added.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package checker
import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand All @@ -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 {
Expand Down
76 changes: 40 additions & 36 deletions checker/check_api_deprecation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"cloud.google.com/go/civil"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand All @@ -29,22 +28,23 @@ 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
}

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
}

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

Expand Down
22 changes: 10 additions & 12 deletions checker/check_api_operation_id_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,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 == "" {
Expand All @@ -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
Expand Down
81 changes: 42 additions & 39 deletions checker/check_api_security_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 @@ -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
}
Expand All @@ -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 {
Expand All @@ -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,
))
}
}
}
Expand Down
Loading

0 comments on commit 2a50ce0

Please sign in to comment.