Skip to content

Commit

Permalink
use opInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison committed Feb 2, 2025
1 parent 7d06418 commit 0a91efa
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 61 deletions.
2 changes: 1 addition & 1 deletion checker/check_api_deprecation.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio
if !ok {
// if deprecation policy is defined and sunset is missing, it's a breaking change
if deprecationDays > 0 {
result = append(result, getAPIDeprecatedSunsetMissing(config, op, operationsSources, path, operation))
result = append(result, getAPIDeprecatedSunsetMissing(newOpInfo(config, op, operationsSources, operation, path)))
}
continue
}
Expand Down
58 changes: 29 additions & 29 deletions checker/check_api_removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

"cloud.google.com/go/civil"
"github.com/getkin/kin-openapi/openapi3"
"github.com/tufin/oasdiff/diff"
)

Expand Down Expand Up @@ -44,7 +43,8 @@ func checkRemovedPaths(pathsDiff *diff.PathsDiff, operationsSources *diff.Operat
continue
}

if change := checkAPIRemoval(config, true, op, operationsSources, operation, path); change != nil {
opInfo := newOpInfo(config, op, operationsSources, operation, path)
if change := checkAPIRemoval(opInfo, true); change != nil {
result = append(result, change)
}
}
Expand All @@ -64,8 +64,8 @@ func checkRemovedOperations(pathsDiff *diff.PathsDiff, operationsSources *diff.O
continue
}
for _, operation := range pathItem.OperationsDiff.Deleted {
op := pathItem.Base.GetOperation(operation)
if change := checkAPIRemoval(config, false, op, operationsSources, operation, path); change != nil {
opInfo := newOpInfo(config, pathItem.Base.GetOperation(operation), operationsSources, operation, path)
if change := checkAPIRemoval(opInfo, false); change != nil {
result = append(result, change)
}
}
Expand All @@ -74,63 +74,63 @@ func checkRemovedOperations(pathsDiff *diff.PathsDiff, operationsSources *diff.O
return result
}

func checkAPIRemoval(config *Config, isPath bool, op *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method, path string) Change {
if !op.Deprecated {
func checkAPIRemoval(opInfo opInfo, isPath bool) Change {
if !opInfo.operation.Deprecated {
return NewApiChange(
getWithoutDeprecationId(isPath),
config,
opInfo.config,
nil,
"",
operationsSources,
op,
method,
path,
opInfo.operationsSources,
opInfo.operation,
opInfo.method,
opInfo.path,
)
}
sunset, ok := getSunset(op.Extensions)
sunset, ok := getSunset(opInfo.operation.Extensions)
if !ok {
return NewApiChange(
getWithDeprecationId(isPath),
config,
opInfo.config,
nil,
"",
operationsSources,
op,
method,
path,
opInfo.operationsSources,
opInfo.operation,
opInfo.method,
opInfo.path,
)
}

date, err := getSunsetDate(sunset)
if err != nil {
return getAPIPathSunsetParse(config, op, operationsSources, method, path, err)
return getAPIPathSunsetParse(opInfo, err)
}

if civil.DateOf(time.Now()).Before(date) {
return NewApiChange(
getBeforeSunsetId(isPath),
config,
opInfo.config,
[]any{date},
"",
operationsSources,
op,
method,
path,
opInfo.operationsSources,
opInfo.operation,
opInfo.method,
opInfo.path,
)
}
return nil
}

func getAPIPathSunsetParse(config *Config, operation *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method string, path string, err error) Change {
func getAPIPathSunsetParse(opInfo opInfo, err error) Change {
return NewApiChange(
APIPathSunsetParseId,
config,
opInfo.config,
[]any{err},
"",
operationsSources,
operation,
method,
path,
opInfo.operationsSources,
opInfo.operation,
opInfo.method,
opInfo.path,
)
}

Expand Down
19 changes: 10 additions & 9 deletions checker/check_api_sunset_changed.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

"cloud.google.com/go/civil"
"github.com/getkin/kin-openapi/openapi3"
"github.com/tufin/oasdiff/diff"
)

Expand Down Expand Up @@ -55,13 +54,15 @@ func APISunsetChangedCheck(diffReport *diff.Diff, operationsSources *diff.Operat

date, err := getSunsetDate(opRevision.Extensions[diff.SunsetExtension])
if err != nil {
result = append(result, getAPIPathSunsetParse(config, opRevision, operationsSources, path, operation, err))
opInfo := newOpInfo(config, opRevision, operationsSources, operation, path)
result = append(result, getAPIPathSunsetParse(opInfo, err))
continue
}

baseDate, err := getSunsetDate(opBase.Extensions[diff.SunsetExtension])
if err != nil {
result = append(result, getAPIPathSunsetParse(config, opBase, operationsSources, path, operation, err))
opInfo := newOpInfo(config, opBase, operationsSources, operation, path)
result = append(result, getAPIPathSunsetParse(opInfo, err))
continue
}

Expand Down Expand Up @@ -115,15 +116,15 @@ func getDeprecationDays(config *Config, stability string) uint {
}
}

func getAPIDeprecatedSunsetMissing(config *Config, operation *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method string, path string) Change {
func getAPIDeprecatedSunsetMissing(opInfo opInfo) Change {
return NewApiChange(
APIDeprecatedSunsetMissingId,
config,
opInfo.config,
nil,
"",
operationsSources,
operation,
method,
path,
opInfo.operationsSources,
opInfo.operation,
opInfo.method,
opInfo.path,
)
}
2 changes: 1 addition & 1 deletion checker/check_parameter_deprecation.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func ParameterDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Op
if !ok {
// if deprecation policy is defined and sunset is missing, it's a breaking change
if deprecationDays > 0 {
result = append(result, getAPIDeprecatedSunsetMissing(config, op, operationsSources, path, operation))
result = append(result, getAPIDeprecatedSunsetMissing(newOpInfo(config, op, operationsSources, operation, path)))
}

Check warning on line 73 in checker/check_parameter_deprecation.go

View check run for this annotation

Codecov / codecov/patch

checker/check_parameter_deprecation.go#L72-L73

Added lines #L72 - L73 were not covered by tests
continue
}
Expand Down
42 changes: 21 additions & 21 deletions checker/check_request_parameter_removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,59 +49,59 @@ func RequestParameterRemovedCheck(diffReport *diff.Diff, operationsSources *diff
return result
}

func checkParameterRemoval(oi opInfo, param *openapi3.Parameter) Change {
func checkParameterRemoval(opInfo opInfo, param *openapi3.Parameter) Change {

if !param.Deprecated {
return NewApiChange(
RequestParameterRemovedId,
oi.config,
opInfo.config,
[]any{param.In, param.Name},
commentId(RequestParameterRemovedId),
oi.operationsSources,
oi.operation,
oi.method,
oi.path,
opInfo.operationsSources,
opInfo.operation,
opInfo.method,
opInfo.path,
)
}

sunset, ok := getSunset(param.Extensions)
if !ok {
return NewApiChange(
RequestParameterRemovedWithDeprecationId,
oi.config,
opInfo.config,
[]any{param.In, param.Name},
"",
oi.operationsSources,
oi.operation,
oi.method,
oi.path,
opInfo.operationsSources,
opInfo.operation,
opInfo.method,
opInfo.path,
)
}

Check warning on line 79 in checker/check_request_parameter_removed.go

View check run for this annotation

Codecov / codecov/patch

checker/check_request_parameter_removed.go#L69-L79

Added lines #L69 - L79 were not covered by tests

date, err := getSunsetDate(sunset)
if err != nil {
return NewApiChange(
RequestParameterSunsetParseId,
oi.config,
opInfo.config,
[]any{param.In, param.Name, err},
"",
oi.operationsSources,
oi.operation,
oi.method,
oi.path,
opInfo.operationsSources,
opInfo.operation,
opInfo.method,
opInfo.path,
)
}

if civil.DateOf(time.Now()).Before(date) {
return NewApiChange(
ParameterRemovedBeforeSunsetId,
oi.config,
opInfo.config,
[]any{param.In, param.Name, date},
"",
oi.operationsSources,
oi.operation,
oi.method,
oi.path,
opInfo.operationsSources,
opInfo.operation,
opInfo.method,
opInfo.path,
)
}
return nil
Expand Down

0 comments on commit 0a91efa

Please sign in to comment.