Skip to content

Commit

Permalink
Add support for -include-checks on changelog (#294)
Browse files Browse the repository at this point in the history
* Extend include-checks to work with changelog

* Default other checkers to INFO

* Include all checkers in GetCHecks

* Fix swapped checker IDs

* Rename struct

* Remove unused method

* Add tests

* Add tests
  • Loading branch information
blva authored Jun 13, 2023
1 parent 586b5f2 commit 6cba0db
Show file tree
Hide file tree
Showing 18 changed files with 450 additions and 28 deletions.
2 changes: 1 addition & 1 deletion checker/check-api-operation-id-removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func APIOperationIdRemovedCheck(diffReport *diff.Diff, operationsSources *diff.O

result = append(result, BackwardCompatibilityError{
Id: apiOperationRemovedCheckId,
Level: ERR,
Level: config.getLogLevel(apiOperationRemovedCheckId, INFO),
Text: fmt.Sprintf(config.i18n(apiOperationRemovedCheckId), ColorizedValue(operationItem.Base.OperationID), ColorizedValue(operationItem.Revision.OperationID)),
Operation: operation,
OperationId: op.OperationID,
Expand Down
2 changes: 1 addition & 1 deletion checker/check-api-tag-removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func APITagRemovedCheck(diffReport *diff.Diff, operationsSources *diff.Operation
for _, tag := range operationItem.TagsDiff.Deleted {
result = append(result, BackwardCompatibilityError{
Id: apiTagRemovedCheckId,
Level: ERR,
Level: config.getLogLevel(apiTagRemovedCheckId, INFO),
Text: fmt.Sprintf(config.i18n(apiTagRemovedCheckId), ColorizedValue(tag)),
Operation: operation,
OperationId: op.OperationID,
Expand Down
2 changes: 1 addition & 1 deletion checker/check-components-schemas-removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func APIComponentsSchemaRemovedCheck(diffReport *diff.Diff, operationsSources *d
for _, deletedSchema := range diffReport.ComponentsDiff.SchemasDiff.Deleted {
result = append(result, BackwardCompatibilityError{
Id: apiSchemasRemovedCheckId,
Level: ERR,
Level: config.getLogLevel(apiSchemasRemovedCheckId, INFO),
Text: fmt.Sprintf(config.i18n(apiSchemasRemovedCheckId), ColorizedValue(deletedSchema)),
Operation: "N/A",
Path: "",
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 @@ -43,7 +43,7 @@ func RequestBodyEnumValueRemovedCheck(diffReport *diff.Diff, operationsSources *
for _, enumVal := range enumDiff.Deleted {
result = append(result, BackwardCompatibilityError{
Id: requestBodyEnumRemovedId,
Level: ERR,
Level: config.getLogLevel(requestBodyEnumRemovedId, INFO),
Text: fmt.Sprintf(config.i18n(requestBodyEnumRemovedId), ColorizedValue(enumVal)),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Expand Down
2 changes: 1 addition & 1 deletion checker/check-response-mediatype-enum-value-removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ResponseMediaTypeEnumValueRemovedCheck(diffReport *diff.Diff, operationsSou
for _, enumVal := range enumDiff.Deleted {
result = append(result, BackwardCompatibilityError{
Id: responseMediatypeEnumValueRemovedId,
Level: ERR,
Level: config.getLogLevel(responseMediatypeEnumValueRemovedId, ERR),
Text: fmt.Sprintf(config.i18n(responseMediatypeEnumValueRemovedId), mediaType, ColorizedValue(enumVal)),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Expand Down
2 changes: 1 addition & 1 deletion checker/check-response-property-enum-value-removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func ResponseParameterEnumValueRemovedCheck(diffReport *diff.Diff, operationsSou
for _, enumVal := range enumDiff.Deleted {
result = append(result, BackwardCompatibilityError{
Id: responsePropertyEnumValueRemovedId,
Level: ERR,
Level: config.getLogLevel(responsePropertyEnumValueRemovedId, INFO),
Text: fmt.Sprintf(config.i18n(responsePropertyEnumValueRemovedId), enumVal, ColorizedValue(propertyFullName(propertyPath, propertyName)), ColorizedValue(responseStatus)),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Expand Down
8 changes: 4 additions & 4 deletions checker/check-response-success-status-removed.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ func ResponseSuccessStatusRemoved(diffReport *diff.Diff, operationsSources *diff
return status >= 200 && status <= 299
}

return ResponseSuccessRemoved(diffReport, operationsSources, config, success, "response-success-status-removed")
return ResponseSuccessRemoved(diffReport, operationsSources, config, success, "response-success-status-removed", ERR)
}

func ResponseNonSuccessStatusRemoved(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config BackwardCompatibilityCheckConfig) []BackwardCompatibilityError {
notSuccess := func(status int) bool {
return status < 200 || status > 299
}

return ResponseSuccessRemoved(diffReport, operationsSources, config, notSuccess, "response-non-success-status-removed")
return ResponseSuccessRemoved(diffReport, operationsSources, config, notSuccess, "response-non-success-status-removed", INFO)
}

func ResponseSuccessRemoved(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config BackwardCompatibilityCheckConfig, filter func(int) bool, id string) []BackwardCompatibilityError {
func ResponseSuccessRemoved(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config BackwardCompatibilityCheckConfig, filter func(int) bool, id string, defaultLevel Level) []BackwardCompatibilityError {
result := make([]BackwardCompatibilityError, 0)
if diffReport.PathsDiff == nil {
return result
Expand All @@ -49,7 +49,7 @@ func ResponseSuccessRemoved(diffReport *diff.Diff, operationsSources *diff.Opera
if filter(status) {
result = append(result, BackwardCompatibilityError{
Id: id,
Level: ERR,
Level: config.getLogLevel(id, defaultLevel),
Text: fmt.Sprintf(config.i18n(id), ColorizedValue(responseStatus)),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Expand Down
8 changes: 8 additions & 0 deletions checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,20 @@ type BackwardCompatibilityCheckConfig struct {
MinSunsetBetaDays int
MinSunsetStableDays int
Localizer localizations.Localizer
LogLevelOverrides map[string]Level
}

func (c *BackwardCompatibilityCheckConfig) i18n(messageID string) string {
return c.Localizer.Get("messages." + messageID)
}

func (c *BackwardCompatibilityCheckConfig) getLogLevel(checkerId string, defaultLevel Level) Level {
if level, ok := c.LogLevelOverrides[checkerId]; ok {
return level
}
return defaultLevel
}

func CheckBackwardCompatibility(config BackwardCompatibilityCheckConfig, diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap) BackwardCompatibilityErrors {
return CheckBackwardCompatibilityUntilLevel(config, diffReport, operationsSources, WARN)
}
Expand Down
28 changes: 16 additions & 12 deletions checker/default_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,28 @@ func GetDefaultChecks() BackwardCompatibilityCheckConfig {
}

func GetChecks(includeChecks utils.StringList) BackwardCompatibilityCheckConfig {
return getBackwardCompatibilityCheckConfig(append(defaultChecks(), includedChecks(includeChecks)...))
return getBackwardCompatibilityCheckConfig(allChecks(), LevelOverrides(includeChecks))
}

func GetAllChecks() BackwardCompatibilityCheckConfig {
return getBackwardCompatibilityCheckConfig(allChecks())
func LevelOverrides(includeChecks utils.StringList) map[string]Level {
result := map[string]Level{}
for _, s := range includeChecks {
// if the checker was explicitly included with the `-include-checks`,
// it means that it's output is considered a breaking change,
// so the returned level should overwritten to ERR.
result[s] = ERR
}
return result
}

func GetAllChecks(includeChecks utils.StringList) BackwardCompatibilityCheckConfig {
return getBackwardCompatibilityCheckConfig(allChecks(), LevelOverrides(includeChecks))
}

func getBackwardCompatibilityCheckConfig(checks []BackwardCompatibilityCheck) BackwardCompatibilityCheckConfig {
func getBackwardCompatibilityCheckConfig(checks []BackwardCompatibilityCheck, levelOverrides map[string]Level) BackwardCompatibilityCheckConfig {
return BackwardCompatibilityCheckConfig{
Checks: checks,
LogLevelOverrides: levelOverrides,
MinSunsetBetaDays: 31,
MinSunsetStableDays: 180,
Localizer: *localizations.New("en", "en"),
Expand Down Expand Up @@ -47,14 +59,6 @@ func ValidateIncludeChecks(includeChecks utils.StringList) utils.StringList {
return result.Sort()
}

func includedChecks(includeChecks utils.StringList) []BackwardCompatibilityCheck {
result := []BackwardCompatibilityCheck{}
for _, s := range includeChecks {
result = append(result, optionalChecks[s])
}
return result
}

func defaultChecks() []BackwardCompatibilityCheck {
return []BackwardCompatibilityCheck{
RequestParameterRemovedCheck,
Expand Down
73 changes: 73 additions & 0 deletions data/run_test/breaking_changes_include_checks_base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
openapi: 3.0.1
info:
title: Tufin
version: "1.0"
servers:
- url: https://localhost:9080
paths:
/api/v1.0/groups:
post:
tags:
- Group
operationId: createOneGroup
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/GroupView'
description: Creates one project.
required: true
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/GroupView'
description: OK
"409":
content:
application/json:
schema:
$ref: '#/components/schemas/GroupView'
description: Conflict
summary: Create One Project
/api/v1.0/groups/{groupId}:
get:
operationId: returnOneGroup
parameters:
- $ref: '#/components/parameters/groupId'
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/GroupView'
description: OK
summary: Return One Project
components:
parameters:
groupId:
in: path
name: groupId
required: true
schema:
type: string
schemas:
GroupView:
type: object
properties:
data:
type: object
properties:
created:
type: string
format: date-time
readOnly: true
pattern: "^[a-z]+$"
id:
type: string
readOnly: true
name:
type: string
required:
- name
65 changes: 65 additions & 0 deletions data/run_test/breaking_changes_include_checks_revision.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
openapi: 3.0.1
info:
title: Tufin
version: "1.0"
servers:
- url: https://localhost:9080
paths:
/api/v1.0/groups:
post:
operationId: createOneGroup
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/GroupView'
description: Creates one project.
required: true
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/GroupView'
description: OK
summary: Create One Project
/api/v1.0/groups/{groupId}:
get:
operationId: returnOneGroup
parameters:
- $ref: '#/components/parameters/groupId'
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/GroupView'
description: OK
summary: Return One Project
components:
parameters:
groupId:
in: path
name: groupId
required: true
schema:
type: string
schemas:
GroupView:
type: object
properties:
data:
type: object
properties:
created:
type: string
format: date-time
readOnly: true
pattern: "^[a-z]+$"
id:
type: string
readOnly: true
name:
type: string
required:
- name
55 changes: 55 additions & 0 deletions data/run_test/changelog_base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
openapi: 3.0.1
info:
title: Tufin
version: "1.0"
servers:
- url: https://localhost:9080
paths:
/api/v1.0/groups:
post:
operationId: createOneGroup
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/GroupView'
description: Creates one project.
required: true
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/GroupView'
description: OK
"409":
content:
application/json:
schema:
$ref: '#/components/schemas/GroupView'
description: Conflict
summary: Create One Project
components:
parameters:
groupId:
in: path
name: groupId
required: true
schema:
type: string
schemas:
GroupView:
type: object
properties:
created:
type: string
format: date-time
readOnly: true
pattern: ".*"
id:
type: string
readOnly: true
name:
type: string
required:
- name
Loading

0 comments on commit 6cba0db

Please sign in to comment.