-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
224 changing a request property to enum should be breaking (#230)
* added unit test * initial checker * changing a request property to enum is breaking * adding an enum value is not breaking * changing type and adding enum simultaneously * RequestParameterBecameEnumCheck * RequestHeaderPropertyBecameEnumCheck * doc * russian messages * seperate checks
- Loading branch information
Reuven Harrison
authored
Apr 30, 2023
1 parent
53093d6
commit c3bbf82
Showing
24 changed files
with
665 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,27 @@ | ||
# How to Add Custom Breaking-Changes Checks | ||
|
||
## Unit Tests and Documentation | ||
1. write a unit test for your scenario and add a comment "BC: \<use-case\> is breaking" | ||
2. optionally, add additional unit tests and comment them with "is breaking" or "is not breaking" | ||
3. Update the breaking-changes examples doc: | ||
``` | ||
./scripts/test.sh | ||
``` | ||
4. make sure that [BREAKING-CHANGES.md](BREAKING-CHANGES.md) contains your comments | ||
## Unit Test | ||
1. Add a unit test for your scenario in one of the test files under [checker](checker) with a comment "BC: \<use-case\> is breaking" | ||
2. Add any acompanying OpenAPI specs under [data](data) | ||
|
||
## Localized Backwards Compatibility Messages | ||
1. add localized texts under [checker/localizations_src](checker/localizations_src) (you can use Google Translate for Russian) | ||
1. Add localized texts under [checker/localizations_src](checker/localizations_src) (you can use Google Translate for Russian) | ||
2. Update [localization source file](checker/localizations/localizations.go): | ||
``` | ||
go-localize -input checker/localizations_src -output checker/localizations | ||
``` | ||
3. make sure that [checker/localizations/localizations.go](checker/localizations/localizations.go) contains the new messages | ||
3. Make sure that [checker/localizations/localizations.go](checker/localizations/localizations.go) contains the new messages | ||
## Write the Checker Function | ||
1. create new go file under [checker](checker) and name it by the breaking-change use case | ||
2. create a check func inside the file and name it accordingly | ||
3. add the checker func to defaultChecks | ||
4. verify that all unit tests pass | ||
1. Create new go file under [checker](checker) and name it by the breaking-change use case | ||
2. Create a check func inside the file and name it accordingly | ||
3. Add the checker func to the defaultChecks or optionalChecks list | ||
## Documentation | ||
1. Optionally, add additional unit tests and comment them with "BC: \<use-case\> is breaking" or "BC: \<use-case\> is not breaking" | ||
2. Update [BREAKING-CHANGES.md](BREAKING-CHANGES.md): | ||
``` | ||
./scripts/test.sh | ||
``` | ||
3. Make sure that [BREAKING-CHANGES.md](BREAKING-CHANGES.md) was updated with your use-cases | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package checker | ||
|
||
import ( | ||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
const requestBodyBecameEnumId = "request-body-became-enum" | ||
|
||
func RequestBodyBecameEnumCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config BackwardCompatibilityCheckConfig) []BackwardCompatibilityError { | ||
result := make([]BackwardCompatibilityError, 0) | ||
if diffReport.PathsDiff == nil { | ||
return result | ||
} | ||
for path, pathItem := range diffReport.PathsDiff.Modified { | ||
if pathItem.OperationsDiff == nil { | ||
continue | ||
} | ||
for operation, operationItem := range pathItem.OperationsDiff.Modified { | ||
|
||
source := (*operationsSources)[operationItem.Revision] | ||
|
||
if operationItem.RequestBodyDiff == nil || | ||
operationItem.RequestBodyDiff.ContentDiff == nil || | ||
operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { | ||
continue | ||
} | ||
|
||
modifiedMediaTypes := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified | ||
|
||
for _, mediaTypeDiff := range modifiedMediaTypes { | ||
if mediaTypeDiff.SchemaDiff == nil { | ||
continue | ||
} | ||
if schemaDiff := mediaTypeDiff.SchemaDiff; schemaDiff.EnumDiff == nil || !schemaDiff.EnumDiff.EnumAdded { | ||
continue | ||
} | ||
result = append(result, BackwardCompatibilityError{ | ||
Id: requestBodyBecameEnumId, | ||
Level: ERR, | ||
Text: config.i18n(requestBodyBecameEnumId), | ||
Operation: operation, | ||
Path: path, | ||
Source: source, | ||
}) | ||
} | ||
} | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package checker | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
const requestHeaderPropertyBecameEnumId = "request-header-property-became-enum" | ||
|
||
func RequestHeaderPropertyBecameEnumCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config BackwardCompatibilityCheckConfig) []BackwardCompatibilityError { | ||
result := make([]BackwardCompatibilityError, 0) | ||
if diffReport.PathsDiff == nil { | ||
return result | ||
} | ||
for path, pathItem := range diffReport.PathsDiff.Modified { | ||
if pathItem.OperationsDiff == nil { | ||
continue | ||
} | ||
for operation, operationItem := range pathItem.OperationsDiff.Modified { | ||
source := (*operationsSources)[operationItem.Revision] | ||
|
||
if operationItem.ParametersDiff == nil { | ||
continue | ||
} | ||
|
||
for paramLocation, paramDiffs := range operationItem.ParametersDiff.Modified { | ||
|
||
if paramLocation != "header" { | ||
continue | ||
} | ||
|
||
for paramName, paramDiff := range paramDiffs { | ||
if paramDiff.SchemaDiff == nil { | ||
continue | ||
} | ||
|
||
if paramDiff.SchemaDiff.EnumDiff != nil && paramDiff.SchemaDiff.EnumDiff.EnumAdded { | ||
result = append(result, BackwardCompatibilityError{ | ||
Id: requestHeaderPropertyBecameEnumId, | ||
Level: ERR, | ||
Text: fmt.Sprintf(config.i18n(requestHeaderPropertyBecameEnumId), ColorizedValue(paramName)), | ||
Operation: operation, | ||
Path: path, | ||
Source: source, | ||
}) | ||
} | ||
|
||
CheckModifiedPropertiesDiff( | ||
paramDiff.SchemaDiff, | ||
func(propertyPath string, propertyName string, propertyDiff *diff.SchemaDiff, parent *diff.SchemaDiff) { | ||
|
||
if enumDiff := propertyDiff.EnumDiff; enumDiff == nil || !enumDiff.EnumAdded { | ||
return | ||
} | ||
|
||
result = append(result, BackwardCompatibilityError{ | ||
Id: requestHeaderPropertyBecameEnumId, | ||
Level: ERR, | ||
Text: fmt.Sprintf(config.i18n(requestHeaderPropertyBecameEnumId), ColorizedValue(paramName), ColorizedValue(propertyFullName(propertyPath, propertyName))), | ||
Operation: operation, | ||
Path: path, | ||
Source: source, | ||
}) | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package checker | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
const requestParameterBecameEnumId = "request-parameter-became-enum" | ||
|
||
func RequestParameterBecameEnumCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config BackwardCompatibilityCheckConfig) []BackwardCompatibilityError { | ||
result := make([]BackwardCompatibilityError, 0) | ||
if diffReport.PathsDiff == nil { | ||
return result | ||
} | ||
for path, pathItem := range diffReport.PathsDiff.Modified { | ||
if pathItem.OperationsDiff == nil { | ||
continue | ||
} | ||
for operation, operationItem := range pathItem.OperationsDiff.Modified { | ||
if operationItem.ParametersDiff == nil { | ||
continue | ||
} | ||
if operationItem.ParametersDiff.Modified == nil { | ||
continue | ||
} | ||
source := (*operationsSources)[operationItem.Revision] | ||
for paramLocation, paramItems := range operationItem.ParametersDiff.Modified { | ||
for paramName, paramItem := range paramItems { | ||
if paramItem.SchemaDiff == nil { | ||
continue | ||
} | ||
|
||
if enumDiff := paramItem.SchemaDiff.EnumDiff; enumDiff == nil || !enumDiff.EnumAdded { | ||
continue | ||
} | ||
|
||
result = append(result, BackwardCompatibilityError{ | ||
Id: requestParameterBecameEnumId, | ||
Level: ERR, | ||
Text: fmt.Sprintf(config.i18n(requestParameterBecameEnumId), ColorizedValue(paramLocation), ColorizedValue(paramName)), | ||
Operation: operation, | ||
Path: path, | ||
Source: source, | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
return result | ||
} |
Oops, something went wrong.