Skip to content

Commit

Permalink
use ctor (#576)
Browse files Browse the repository at this point in the history
Co-authored-by: Reuven <[email protected]>
  • Loading branch information
reuvenharrison and Reuven authored Jul 11, 2024
1 parent 2ab458f commit ea17e6d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 47 deletions.
57 changes: 30 additions & 27 deletions checker/check_api_removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"cloud.google.com/go/civil"
"github.com/getkin/kin-openapi/openapi3"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand Down Expand Up @@ -53,14 +52,16 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo

func checkAPIRemoval(deprecationId, sunsetId string, op *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method, path string) Change {
if !op.Deprecated {
return ApiChange{
Id: deprecationId,
Level: ERR,
Operation: method,
OperationId: op.OperationID,
Path: path,
Source: load.NewSource((*operationsSources)[op]),
}
return NewApiChange(
deprecationId,
ERR,
nil,
"",
operationsSources,
op,
method,
path,
)
}
sunset, ok := getSunset(op.Extensions)
if !ok {
Expand All @@ -74,27 +75,29 @@ func checkAPIRemoval(deprecationId, sunsetId string, op *openapi3.Operation, ope
}

if civil.DateOf(time.Now()).Before(date) {
return ApiChange{
Id: sunsetId,
Level: ERR,
Args: []any{date},
Operation: method,
OperationId: op.OperationID,
Path: path,
Source: load.NewSource((*operationsSources)[op]),
}
return NewApiChange(
sunsetId,
ERR,
[]any{date},
"",
operationsSources,
op,
method,
path,
)
}
return nil
}

func getAPIPathSunsetParse(operation *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method string, path string, err error) Change {
return ApiChange{
Id: APIPathSunsetParseId,
Level: ERR,
Args: []any{err},
Operation: method,
OperationId: operation.OperationID,
Path: path,
Source: load.NewSource((*operationsSources)[operation]),
}
return NewApiChange(
APIPathSunsetParseId,
ERR,
[]any{err},
"",
operationsSources,
operation,
method,
path,
)
}
20 changes: 10 additions & 10 deletions checker/check_api_sunset_changed.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"cloud.google.com/go/civil"
"github.com/getkin/kin-openapi/openapi3"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand Down Expand Up @@ -117,13 +116,14 @@ func getDeprecationDays(config *Config, stability string) uint {
}

func getAPIDeprecatedSunsetMissing(operation *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method string, path string) Change {
return ApiChange{
Id: APIDeprecatedSunsetMissingId,
Level: ERR,
Args: []any{},
Operation: method,
OperationId: operation.OperationID,
Path: path,
Source: load.NewSource((*operationsSources)[operation]),
}
return NewApiChange(
APIDeprecatedSunsetMissingId,
ERR,
nil,
"",
operationsSources,
operation,
method,
path,
)
}
20 changes: 10 additions & 10 deletions checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

"github.com/getkin/kin-openapi/openapi3"
"github.com/tufin/oasdiff/diff"
"github.com/tufin/oasdiff/load"
)

const (
Expand Down Expand Up @@ -133,15 +132,16 @@ func removeDraftAndAlphaOperationsDiffs(config *Config, diffReport *diff.Diff, r
}

func getAPIInvalidStabilityLevel(operation *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method string, path string, err error) Change {
return ApiChange{
Id: APIInvalidStabilityLevelId,
Level: ERR,
Args: []any{err},
Operation: method,
OperationId: operation.OperationID,
Path: path,
Source: load.NewSource((*operationsSources)[operation]),
}
return NewApiChange(
APIInvalidStabilityLevelId,
ERR,
[]any{err},
"",
operationsSources,
operation,
method,
path,
)
}

func getStabilityLevel(i map[string]interface{}) (string, error) {
Expand Down

0 comments on commit ea17e6d

Please sign in to comment.