Skip to content

Commit

Permalink
get levels from the rules table (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison authored Jul 17, 2024
1 parent 9733a40 commit 3fd2ca2
Show file tree
Hide file tree
Showing 102 changed files with 347 additions and 272 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
go-version: '1.22'
cache: false
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v6
with:
# Require: The version of golangci-lint to use.
# When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version.
Expand Down
4 changes: 2 additions & 2 deletions checker/api_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ 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 {
func NewApiChange(id string, config *Config, args []any, comment string, operationsSources *diff.OperationsSourcesMap, operation *openapi3.Operation, method, path string) ApiChange {
return ApiChange{
Id: id,
Level: level,
Level: config.getLogLevel(id),
Args: args,
Comment: comment,
OperationId: operation.OperationID,
Expand Down
4 changes: 1 addition & 3 deletions checker/check_added_required_request_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ func AddedRequestBodyCheck(diffReport *diff.Diff, operationsSources *diff.Operat
}
if operationItem.RequestBodyDiff.Added {
id := AddedOptionalRequestBodyId
logLevel := INFO

if operationItem.Revision.RequestBody.Value.Required {
id = AddedRequiredRequestBodyId
logLevel = ERR
}

result = append(result, NewApiChange(
id,
logLevel,
config,
nil,
"",
operationsSources,
Expand Down
2 changes: 1 addition & 1 deletion checker/check_api_added.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func APIAddedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSour
appendErr := func(path, method string, operation *openapi3.Operation) {
result = append(result, NewApiChange(
EndpointAddedId,
INFO,
config,
nil,
"",
operationsSources,
Expand Down
10 changes: 5 additions & 5 deletions checker/check_api_deprecation.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio
// not breaking changes
result = append(result, NewApiChange(
EndpointReactivatedId,
INFO,
config,
nil,
"",
operationsSources,
Expand All @@ -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(op, operationsSources, path, operation))
result = append(result, getAPIDeprecatedSunsetMissing(config, op, operationsSources, path, operation))
}
continue
}
Expand All @@ -69,7 +69,7 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio
if err != nil {
result = append(result, NewApiChange(
APIDeprecatedSunsetParseId,
ERR,
config,
[]any{err},
"",
operationsSources,
Expand All @@ -85,7 +85,7 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio
if days < int(deprecationDays) {
result = append(result, NewApiChange(
APISunsetDateTooSmallId,
ERR,
config,
[]any{date, deprecationDays},
"",
operationsSources,
Expand All @@ -99,7 +99,7 @@ func APIDeprecationCheck(diffReport *diff.Diff, operationsSources *diff.Operatio
// not breaking changes
result = append(result, NewApiChange(
EndpointDeprecatedId,
INFO,
config,
nil,
"",
operationsSources,
Expand Down
2 changes: 1 addition & 1 deletion checker/check_api_operation_id_updated.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func APIOperationIdUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.O

result = append(result, NewApiChange(
id,
config.getLogLevel(id),
config,
args,
"",
operationsSources,
Expand Down
16 changes: 8 additions & 8 deletions checker/check_api_removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo

for operation := range diffReport.PathsDiff.Base.Value(path).Operations() {
op := diffReport.PathsDiff.Base.Value(path).GetOperation(operation)
if change := checkAPIRemoval(APIPathRemovedWithoutDeprecationId, APIPathRemovedBeforeSunsetId, op, operationsSources, operation, path); change != nil {
if change := checkAPIRemoval(config, APIPathRemovedWithoutDeprecationId, APIPathRemovedBeforeSunsetId, op, operationsSources, operation, path); change != nil {
result = append(result, change)
}
}
Expand All @@ -41,7 +41,7 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo
}
for _, operation := range pathItem.OperationsDiff.Deleted {
op := pathItem.Base.GetOperation(operation)
if change := checkAPIRemoval(APIRemovedWithoutDeprecationId, APIRemovedBeforeSunsetId, op, operationsSources, operation, path); change != nil {
if change := checkAPIRemoval(config, APIRemovedWithoutDeprecationId, APIRemovedBeforeSunsetId, op, operationsSources, operation, path); change != nil {
result = append(result, change)
}
}
Expand All @@ -50,11 +50,11 @@ func APIRemovedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSo
return result
}

func checkAPIRemoval(deprecationId, sunsetId string, op *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method, path string) Change {
func checkAPIRemoval(config *Config, deprecationId, sunsetId string, op *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method, path string) Change {
if !op.Deprecated {
return NewApiChange(
deprecationId,
ERR,
config,
nil,
"",
operationsSources,
Expand All @@ -71,13 +71,13 @@ func checkAPIRemoval(deprecationId, sunsetId string, op *openapi3.Operation, ope

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

if civil.DateOf(time.Now()).Before(date) {
return NewApiChange(
sunsetId,
ERR,
config,
[]any{date},
"",
operationsSources,
Expand All @@ -89,10 +89,10 @@ func checkAPIRemoval(deprecationId, sunsetId string, op *openapi3.Operation, ope
return nil
}

func getAPIPathSunsetParse(operation *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method string, path string, err error) Change {
func getAPIPathSunsetParse(config *Config, operation *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method string, path string, err error) Change {
return NewApiChange(
APIPathSunsetParseId,
ERR,
config,
[]any{err},
"",
operationsSources,
Expand Down
8 changes: 4 additions & 4 deletions checker/check_api_security_updated.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func APISecurityUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.Oper

result = append(result, NewApiChange(
APISecurityAddedCheckId,
INFO,
config,
[]any{addedSecurity},
"",
operationsSources,
Expand All @@ -103,7 +103,7 @@ func APISecurityUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.Oper

result = append(result, NewApiChange(
APISecurityRemovedCheckId,
INFO,
config,
[]any{deletedSecurity},
"",
operationsSources,
Expand All @@ -121,7 +121,7 @@ func APISecurityUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.Oper
for _, addedScope := range updatedSecuritySchemeScopes.Added {
result = append(result, NewApiChange(
APISecurityScopeAddedId,
INFO,
config,
[]any{addedScope, securitySchemeName},
"",
operationsSources,
Expand All @@ -133,7 +133,7 @@ func APISecurityUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.Oper
for _, deletedScope := range updatedSecuritySchemeScopes.Deleted {
result = append(result, NewApiChange(
APISecurityScopeRemovedId,
INFO,
config,
[]any{deletedScope, securitySchemeName},
"",
operationsSources,
Expand Down
12 changes: 6 additions & 6 deletions checker/check_api_sunset_changed.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func APISunsetChangedCheck(diffReport *diff.Diff, operationsSources *diff.Operat
if operationDiff.ExtensionsDiff.Deleted.Contains(diff.SunsetExtension) {
result = append(result, NewApiChange(
APISunsetDeletedId,
ERR,
config,
nil,
"",
operationsSources,
Expand All @@ -55,13 +55,13 @@ func APISunsetChangedCheck(diffReport *diff.Diff, operationsSources *diff.Operat

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

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

Expand All @@ -78,7 +78,7 @@ func APISunsetChangedCheck(diffReport *diff.Diff, operationsSources *diff.Operat
if baseDate.After(date) && days < int(deprecationDays) {
result = append(result, NewApiChange(
APISunsetDateChangedTooSmallId,
ERR,
config,
[]any{baseDate, date, baseDate, deprecationDays},
"",
operationsSources,
Expand Down Expand Up @@ -115,10 +115,10 @@ func getDeprecationDays(config *Config, stability string) uint {
}
}

func getAPIDeprecatedSunsetMissing(operation *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method string, path string) Change {
func getAPIDeprecatedSunsetMissing(config *Config, operation *openapi3.Operation, operationsSources *diff.OperationsSourcesMap, method string, path string) Change {
return NewApiChange(
APIDeprecatedSunsetMissingId,
ERR,
config,
nil,
"",
operationsSources,
Expand Down
4 changes: 2 additions & 2 deletions checker/check_api_tag_updated.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func APITagUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.Operation
for _, tag := range operationItem.TagsDiff.Deleted {
result = append(result, NewApiChange(
APITagRemovedId,
config.getLogLevel(APITagRemovedId),
config,
[]any{tag},
"",
operationsSources,
Expand All @@ -43,7 +43,7 @@ func APITagUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.Operation
for _, tag := range operationItem.TagsDiff.Added {
result = append(result, NewApiChange(
APITagAddedId,
config.getLogLevel(APITagAddedId),
config,
[]any{tag},
"",
operationsSources,
Expand Down
4 changes: 1 addition & 3 deletions checker/check_new_request_non_path_default_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ func NewRequestNonPathDefaultParameterCheck(diffReport *diff.Diff, operationsSou
continue
}
id := NewRequiredRequestDefaultParameterToExistingPathId
level := ERR
if !param.Value.Required {
id = NewOptionalRequestDefaultParameterToExistingPathId
level = INFO
}

for operation, operationItem := range pathItem.Revision.Operations() {
Expand All @@ -41,7 +39,7 @@ func NewRequestNonPathDefaultParameterCheck(diffReport *diff.Diff, operationsSou

result = append(result, NewApiChange(
id,
level,
config,
[]any{paramLoc, param.Value.Name},
"",
operationsSources,
Expand Down
4 changes: 1 addition & 3 deletions checker/check_new_request_non_path_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ func NewRequestNonPathParameterCheck(diffReport *diff.Diff, operationsSources *d
for _, param := range operationItem.Revision.Parameters {
if param.Value.Name == paramName {
id := NewRequiredRequestParameterId
level := ERR
if !param.Value.Required {
id = NewOptionalRequestParameterId
level = INFO
}
result = append(result, NewApiChange(
id,
level,
config,
[]any{paramLocation, paramName},
"",
operationsSources,
Expand Down
2 changes: 1 addition & 1 deletion checker/check_new_requried_request_header_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewRequiredRequestHeaderPropertyCheck(diffReport *diff.Diff, operationsSour

result = append(result, NewApiChange(
NewRequiredRequestHeaderPropertyId,
ERR,
config,
[]any{paramName, propertyFullName(propertyPath, newPropertyName)},
"",
operationsSources,
Expand Down
2 changes: 1 addition & 1 deletion checker/check_request_body_became_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func RequestBodyBecameEnumCheck(diffReport *diff.Diff, operationsSources *diff.O
}
result = append(result, NewApiChange(
RequestBodyBecameEnumId,
ERR,
config,
nil,
"",
operationsSources,
Expand Down
2 changes: 1 addition & 1 deletion checker/check_request_body_enum_deleted.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func RequestBodyEnumValueRemovedCheck(diffReport *diff.Diff, operationsSources *
for _, enumVal := range enumDiff.Deleted {
result = append(result, NewApiChange(
RequestBodyEnumValueRemovedId,
config.getLogLevel(RequestBodyEnumValueRemovedId),
config,
[]any{enumVal},
"",
operationsSources,
Expand Down
4 changes: 2 additions & 2 deletions checker/check_request_body_mediatype_updated.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func RequestBodyMediaTypeChangedCheck(diffReport *diff.Diff, operationsSources *
for _, mediaType := range addedMediaTypes {
result = append(result, NewApiChange(
RequestBodyMediaTypeAddedId,
INFO,
config,
[]any{mediaType},
"",
operationsSources,
Expand All @@ -43,7 +43,7 @@ func RequestBodyMediaTypeChangedCheck(diffReport *diff.Diff, operationsSources *
for _, mediaType := range removedMediaTypes {
result = append(result, NewApiChange(
RequestBodyMediaTypeRemovedId,
ERR,
config,
[]any{mediaType},
"",
operationsSources,
Expand Down
4 changes: 1 addition & 3 deletions checker/check_request_body_required_value_updated.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ func RequestBodyRequiredUpdatedCheck(diffReport *diff.Diff, operationsSources *d
}

id := RequestBodyBecameOptionalId
logLevel := INFO
if operationItem.RequestBodyDiff.RequiredDiff.To == true {
id = RequestBodyBecameRequiredId
logLevel = ERR
}

result = append(result, NewApiChange(
id,
logLevel,
config,
nil,
"",
operationsSources,
Expand Down
2 changes: 1 addition & 1 deletion checker/check_request_discriminator_updated.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func RequestDiscriminatorUpdatedCheck(diffReport *diff.Diff, operationsSources *
appendResultItem := func(messageId string, a ...any) {
result = append(result, NewApiChange(
messageId,
INFO,
config,
a,
"",
operationsSources,
Expand Down
4 changes: 2 additions & 2 deletions checker/check_request_header_property_became_enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func RequestHeaderPropertyBecameEnumCheck(diffReport *diff.Diff, operationsSourc
if paramDiff.SchemaDiff.EnumDiff != nil && paramDiff.SchemaDiff.EnumDiff.EnumAdded {
result = append(result, NewApiChange(
RequestHeaderPropertyBecameEnumId,
ERR,
config,
[]any{paramName},
"",
operationsSources,
Expand All @@ -57,7 +57,7 @@ func RequestHeaderPropertyBecameEnumCheck(diffReport *diff.Diff, operationsSourc

result = append(result, NewApiChange(
RequestHeaderPropertyBecameEnumId,
ERR,
config,
[]any{paramName, propertyFullName(propertyPath, propertyName)},
"",
operationsSources,
Expand Down
Loading

0 comments on commit 3fd2ca2

Please sign in to comment.