-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feature) Add optional checker for enum removal (#210)
* Add enum optional checkers * Improve property check * Minor fixes * Address comments
- Loading branch information
Showing
13 changed files
with
372 additions
and
18 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package checker | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
const requestBodyEnumRemovedId = "request-body-enum-value-removed" | ||
|
||
func RequestBodyEnumValueRemovedCheck(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.RequestBodyDiff == nil { | ||
continue | ||
} | ||
if operationItem.RequestBodyDiff.ContentDiff == nil { | ||
continue | ||
} | ||
if operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { | ||
continue | ||
} | ||
|
||
mediaTypeChanges := operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified | ||
|
||
source := (*operationsSources)[operationItem.Revision] | ||
for _, mediaTypeItem := range mediaTypeChanges { | ||
if mediaTypeItem.SchemaDiff == nil { | ||
continue | ||
} | ||
|
||
enumDiff := mediaTypeItem.SchemaDiff.EnumDiff | ||
if enumDiff == nil || enumDiff.Deleted == nil { | ||
continue | ||
} | ||
for _, enumVal := range enumDiff.Deleted { | ||
result = append(result, BackwardCompatibilityError{ | ||
Id: requestBodyEnumRemovedId, | ||
Level: ERR, | ||
Text: fmt.Sprintf(config.i18n(requestBodyEnumRemovedId), ColorizedValue(enumVal)), | ||
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,56 @@ | ||
package checker | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
const responseMediatypeEnumValueRemovedId = "response-mediatype-enum-value-removed" | ||
|
||
func ResponseMediaTypeEnumValueRemovedCheck(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.ResponsesDiff == nil { | ||
continue | ||
} | ||
if operationItem.ResponsesDiff.Modified == nil { | ||
continue | ||
} | ||
source := (*operationsSources)[operationItem.Revision] | ||
for _, responseItems := range operationItem.ResponsesDiff.Modified { | ||
for mediaType, mediaTypeItem := range responseItems.ContentDiff.MediaTypeModified { | ||
if mediaTypeItem.SchemaDiff == nil { | ||
continue | ||
} | ||
|
||
enumDiff := mediaTypeItem.SchemaDiff.EnumDiff | ||
if enumDiff == nil { | ||
continue | ||
} | ||
|
||
for _, enumVal := range enumDiff.Deleted { | ||
result = append(result, BackwardCompatibilityError{ | ||
Id: responseMediatypeEnumValueRemovedId, | ||
Level: ERR, | ||
Text: fmt.Sprintf(config.i18n(responseMediatypeEnumValueRemovedId), mediaType, ColorizedValue(enumVal)), | ||
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,58 @@ | ||
package checker | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
const responsePropertyEnumValueRemovedId = "response-property-enum-value-removed" | ||
|
||
func ResponseParameterEnumValueRemovedCheck(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.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { | ||
continue | ||
} | ||
|
||
source := (*operationsSources)[operationItem.Revision] | ||
for responseStatus, responseDiff := range operationItem.ResponsesDiff.Modified { | ||
if responseDiff == nil || | ||
responseDiff.ContentDiff == nil || | ||
responseDiff.ContentDiff.MediaTypeModified == nil { | ||
continue | ||
} | ||
for _, mediaTypeDiff := range responseDiff.ContentDiff.MediaTypeModified { | ||
CheckModifiedPropertiesDiff( | ||
mediaTypeDiff.SchemaDiff, | ||
func(propertyPath string, propertyName string, propertyDiff *diff.SchemaDiff, parent *diff.SchemaDiff) { | ||
enumDiff := propertyDiff.EnumDiff | ||
if enumDiff == nil || enumDiff.Deleted == nil { | ||
return | ||
} | ||
|
||
for _, enumVal := range enumDiff.Deleted { | ||
result = append(result, BackwardCompatibilityError{ | ||
Id: responsePropertyEnumValueRemovedId, | ||
Level: ERR, | ||
Text: fmt.Sprintf(config.i18n(responsePropertyEnumValueRemovedId), enumVal, ColorizedValue(propertyFullName(propertyPath, propertyName)), ColorizedValue(responseStatus)), | ||
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
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
Oops, something went wrong.