Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove duplicate call #358

Merged
merged 2 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions BREAKING-CHANGES-EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ These examples are automatically generated from unit tests.
[adding a new media type to response](checker/check-response-mediatype-updated_test.go?plain=1#L11)
[adding a new oauth security scope](checker/check-components-security-updated_test.go?plain=1#L95)
[adding a new operation id](checker/check-api-operation-id-updated_test.go?plain=1#L61)
[adding a new optional request property](checker/check-request-property-updated_test.go?plain=1#L33)
[adding a new optional request property](checker/check-request-property-updated_test.go?plain=1#L64)
[adding a new required request property](checker/check-request-property-updated_test.go?plain=1#L11)
[adding a new security component](checker/check-components-security-updated_test.go?plain=1#L55)
[adding a new security to the API endpoint](checker/check-api-security-updated_test.go?plain=1#L93)
Expand All @@ -174,6 +174,7 @@ These examples are automatically generated from unit tests.
[adding request property enum values](checker/check-request-property-enum-value-updated_test.go?plain=1#L37)
[adding request property pattern](checker/check-request-property-pattern-added-or-changed_test.go?plain=1#L36)
[adding response property pattern](checker/check-response-pattern-added-or-changed_test.go?plain=1#L37)
[adding two new request properties, one required, one optional](checker/check-request-property-updated_test.go?plain=1#L33)
[changing a response property schema format](checker/check-response-property-type-changed_test.go?plain=1#L59)
[changing a response property schema type](checker/check-response-property-type-changed_test.go?plain=1#L34)
[changing a response schema type](checker/check-response-property-type-changed_test.go?plain=1#L11)
Expand Down Expand Up @@ -275,7 +276,7 @@ These examples are automatically generated from unit tests.
[removing a new security component](checker/check-components-security-updated_test.go?plain=1#L75)
[removing a new security to the API endpoint](checker/check-api-security-updated_test.go?plain=1#L116)
[removing a non-success response status](checker/check-response-status-updated_test.go?plain=1#L63)
[removing a required request property](checker/check-request-property-updated_test.go?plain=1#L56)
[removing a required request property](checker/check-request-property-updated_test.go?plain=1#L87)
[removing a required write-only property that was required in response body is detected](checker/check-response-required-property-updated_test.go?plain=1#L85)
[removing a security scope from an API endpoint security](checker/check-api-security-updated_test.go?plain=1#L139)
[removing a security scope from an API global security](checker/check-api-security-updated_test.go?plain=1#L51)
Expand Down
52 changes: 24 additions & 28 deletions checker/check-request-property-updated.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,31 @@ func RequestPropertyUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.
CheckAddedPropertiesDiff(
mediaTypeDiff.SchemaDiff,
func(propertyPath string, propertyName string, propertyItem *openapi3.Schema, parent *diff.SchemaDiff) {
CheckAddedPropertiesDiff(
mediaTypeDiff.SchemaDiff,
func(propertyPath string, propertyName string, propertyItem *openapi3.Schema, parent *diff.SchemaDiff) {
source := (*operationsSources)[operationItem.Revision]
if propertyItem.ReadOnly {
return
}
if slices.Contains(parent.Revision.Value.Required, propertyName) {
result = append(result, ApiChange{
Id: "new-required-request-property",
Level: ERR,
Text: fmt.Sprintf(config.i18n("new-required-request-property"), ColorizedValue(propertyFullName(propertyPath, propertyName))),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: source,
})
} else {
result = append(result, ApiChange{
Id: "new-optional-request-property",
Level: INFO,
Text: fmt.Sprintf(config.i18n("new-optional-request-property"), ColorizedValue(propertyFullName(propertyPath, propertyName))),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: source,
})
}
source := (*operationsSources)[operationItem.Revision]
if propertyItem.ReadOnly {
return
}
if slices.Contains(parent.Revision.Value.Required, propertyName) {
result = append(result, ApiChange{
Id: "new-required-request-property",
Level: ERR,
Text: fmt.Sprintf(config.i18n("new-required-request-property"), ColorizedValue(propertyFullName(propertyPath, propertyName))),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: source,
})
} else {
result = append(result, ApiChange{
Id: "new-optional-request-property",
Level: INFO,
Text: fmt.Sprintf(config.i18n("new-optional-request-property"), ColorizedValue(propertyFullName(propertyPath, propertyName))),
Operation: operation,
OperationId: operationItem.Revision.OperationID,
Path: path,
Source: source,
})
}
})
}
}
Expand Down
31 changes: 31 additions & 0 deletions checker/check-request-property-updated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,37 @@ func TestRequiredRequestPropertyAdded(t *testing.T) {
}, errs[0])
}

// CL: adding two new request properties, one required, one optional
func TestRequiredRequestPropertiesAdded(t *testing.T) {
s1, err := open("../data/checker/request_property_added_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/request_property_added_revision2.yaml")
require.NoError(t, err)

d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestPropertyUpdatedCheck), d, osm, checker.INFO)
require.ElementsMatch(t, []checker.ApiChange{
{
Id: "new-required-request-property",
Text: "added the new required request property 'description'",
Level: checker.ERR,
Operation: "POST",
Path: "/products",
Source: "../data/checker/request_property_added_revision2.yaml",
OperationId: "addProduct",
},
{
Id: "new-optional-request-property",
Text: "added the new optional request property 'info'",
Level: checker.INFO,
Operation: "POST",
Path: "/products",
Source: "../data/checker/request_property_added_revision2.yaml",
OperationId: "addProduct",
}}, errs)
}

// CL: adding a new optional request property
func TestRequiredOptionalPropertyAdded(t *testing.T) {
s1, err := open("../data/checker/request_property_added_base.yaml")
Expand Down
26 changes: 26 additions & 0 deletions data/checker/request_property_added_revision2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
openapi: 3.0.0
info:
title: Sample API
version: 1.0.0
paths:
/products:
post:
operationId: addProduct
requestBody:
content:
application/json:
schema:
type: object
properties:
name:
type: string
description:
type: string
info:
type: string
required:
- name
- description
responses:
'200':
description: OK