Skip to content

Commit

Permalink
new check: added-optional-request-body (#531)
Browse files Browse the repository at this point in the history
Co-authored-by: Reuven <[email protected]>
  • Loading branch information
reuvenharrison and Reuven authored Apr 24, 2024
1 parent 341d77d commit e62904c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
18 changes: 13 additions & 5 deletions checker/check-added-required-request-body.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (

const (
AddedRequiredRequestBodyId = "added-required-request-body"
AddedOptionalRequestBodyId = "added-optional-request-body"
)

func AddedRequiredRequestBodyCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config *Config) Changes {
func AddedRequestBodyCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config *Config) Changes {
result := make(Changes, 0)
if diffReport.PathsDiff == nil {
return result
Expand All @@ -22,12 +23,19 @@ func AddedRequiredRequestBodyCheck(diffReport *diff.Diff, operationsSources *dif
if operationItem.RequestBodyDiff == nil {
continue
}
if operationItem.RequestBodyDiff.Added &&
operationItem.Revision.RequestBody.Value.Required {
if operationItem.RequestBodyDiff.Added {
id := AddedOptionalRequestBodyId
logLevel := INFO

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

source := (*operationsSources)[operationItem.Revision]
result = append(result, ApiChange{
Id: AddedRequiredRequestBodyId,
Level: ERR,
Id: id,
Level: logLevel,
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Expand Down
4 changes: 3 additions & 1 deletion checker/localizations/localizations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions checker/localizations_src/en/messages.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
at: at
in: in
added-required-request-body: added required request body
added-optional-request-body: added optional request body
request-parameter-removed: deleted the %s request parameter %s
total-errors: "%d breaking changes: %d %s, %d %s\\n"
total-changes: "%d changes: %d %s, %d %s, %d %s\\n"
Expand Down
1 change: 1 addition & 0 deletions checker/localizations_src/ru/messages.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
at: в
in: в
added-required-request-body: добавлено обязательное тело запроса
added-optional-request-body: добавлено необязательное тело запроса
request-parameter-removed: удалён %s параметр запроса %s
total-errors: "%s критические изменения: %s %s, %s %s\\n"
total-changes: "%s изменений: %s %s, %s %s, %s %s\\n"
Expand Down
3 changes: 2 additions & 1 deletion checker/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func GetAllRules() []BackwardCompatibilityRule {
newBackwardCompatibilityRule(APISunsetDeletedId, ERR, true, APISunsetChangedCheck),
newBackwardCompatibilityRule(APISunsetDateChangedTooSmallId, ERR, true, APISunsetChangedCheck),
// AddedRequiredRequestBodyCheck
newBackwardCompatibilityRule(AddedRequiredRequestBodyId, ERR, true, AddedRequiredRequestBodyCheck),
newBackwardCompatibilityRule(AddedRequiredRequestBodyId, ERR, true, AddedRequestBodyCheck),
newBackwardCompatibilityRule(AddedOptionalRequestBodyId, INFO, true, AddedRequestBodyCheck),
// NewRequestNonPathDefaultParameterCheck
newBackwardCompatibilityRule(NewRequiredRequestDefaultParameterToExistingPathId, ERR, true, NewRequestNonPathDefaultParameterCheck),
newBackwardCompatibilityRule(NewOptionalRequestDefaultParameterToExistingPathId, INFO, true, NewRequestNonPathDefaultParameterCheck),
Expand Down

0 comments on commit e62904c

Please sign in to comment.