Skip to content

Commit 0d151b7

Browse files
committed
chore: add optional checkers to response and request property removal
1 parent d721a21 commit 0d151b7

7 files changed

+170
-0
lines changed

checker/check_breaking_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,3 +743,83 @@ func TestBreaking_RequestPropertyAllOfRemoved(t *testing.T) {
743743
require.Equal(t, checker.WARN, errs[1].GetLevel())
744744
require.Equal(t, "removed '#/components/schemas/Breed3' from the '/allOf[#/components/schemas/Dog]/breed' request property 'allOf' list", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer()))
745745
}
746+
747+
// BC: removing an optional field from the request body is breaking (optional)
748+
func TestBreaking_RequestPropertyRemoved(t *testing.T) {
749+
s1, err := open("../data/checker/request_property_removed_base.yaml")
750+
require.NoError(t, err)
751+
s2, err := open("../data/checker/request_property_removed_revision.yaml")
752+
require.NoError(t, err)
753+
754+
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
755+
require.NoError(t, err)
756+
checks := allChecksConfig().WithOptionalCheck(checker.RequestPropertyRemovedId)
757+
errs := checker.CheckBackwardCompatibility(checks, d, osm)
758+
759+
require.Len(t, errs, 1)
760+
761+
require.Equal(t, checker.RequestPropertyRemovedId, errs[0].GetId())
762+
require.Equal(t, checker.ERR, errs[0].GetLevel())
763+
require.Equal(t, "removed the request property 'breed'", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
764+
765+
d, osm, err = diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
766+
require.NoError(t, err)
767+
checks = allChecksConfig()
768+
errs = checker.CheckBackwardCompatibility(checks, d, osm)
769+
require.Len(t, errs, 1)
770+
require.Equal(t, checker.WARN, errs[0].GetLevel())
771+
}
772+
773+
// BC: removing an optional field from the response body is breaking (optional)
774+
func TestBreaking_ResponsePropertyRemoved(t *testing.T) {
775+
s1, err := open("../data/checker/response_property_removed_base.yaml")
776+
require.NoError(t, err)
777+
s2, err := open("../data/checker/response_property_removed_revision.yaml")
778+
require.NoError(t, err)
779+
780+
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
781+
require.NoError(t, err)
782+
783+
checks := allChecksConfig().WithOptionalCheck(checker.ResponseOptionalPropertyRemovedId)
784+
errs := checker.CheckBackwardCompatibility(checks, d, osm)
785+
786+
require.Len(t, errs, 1)
787+
788+
require.Equal(t, checker.ResponseOptionalPropertyRemovedId, errs[0].GetId())
789+
require.Equal(t, checker.ERR, errs[0].GetLevel())
790+
require.Equal(t, "removed the optional property 'breed' from the response with the '200' status", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
791+
792+
d, osm, err = diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
793+
require.NoError(t, err)
794+
checks = allChecksConfig()
795+
errs = checker.CheckBackwardCompatibility(checks, d, osm)
796+
require.Len(t, errs, 1)
797+
require.Equal(t, checker.WARN, errs[0].GetLevel())
798+
}
799+
800+
// BC: removing an optional field from the response body is breaking (optional)
801+
func TestBreaking_ResponseWriteOnlyPropertyRemoved(t *testing.T) {
802+
s1, err := open("../data/checker/response_property_removed_base.yaml")
803+
require.NoError(t, err)
804+
s2, err := open("../data/checker/response_property_removed_revision.yaml")
805+
require.NoError(t, err)
806+
807+
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
808+
require.NoError(t, err)
809+
810+
checks := allChecksConfig().WithOptionalCheck(checker.ResponseOptionalWriteOnlyPropertyRemovedId)
811+
errs := checker.CheckBackwardCompatibility(checks, d, osm)
812+
813+
require.Len(t, errs, 2)
814+
815+
require.Equal(t, checker.ResponseOptionalWriteOnlyPropertyRemovedId, errs[0].GetId())
816+
require.Equal(t, checker.ERR, errs[0].GetLevel())
817+
require.Equal(t, "removed the optional write-only property 'other' from the response with the '200' status", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
818+
819+
d, osm, err = diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
820+
require.NoError(t, err)
821+
checks = allChecksConfig()
822+
errs = checker.CheckBackwardCompatibility(checks, d, osm)
823+
require.Len(t, errs, 1)
824+
require.Equal(t, checker.WARN, errs[0].GetLevel())
825+
}

checker/rules.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ func GetOptionalRules() BackwardCompatibilityRules {
447447
newBackwardCompatibilityRule(ResponsePropertyEnumValueRemovedId, INFO, ResponseParameterEnumValueRemovedCheck, DirectionResponse, LocationProperties, ActionRemove),
448448
newBackwardCompatibilityRule(ResponseMediaTypeEnumValueRemovedId, INFO, ResponseMediaTypeEnumValueRemovedCheck, DirectionResponse, LocationBody, ActionRemove),
449449
newBackwardCompatibilityRule(RequestBodyEnumValueRemovedId, INFO, RequestBodyEnumValueRemovedCheck, DirectionRequest, LocationBody, ActionRemove),
450+
newBackwardCompatibilityRule(ResponseOptionalPropertyRemovedId, WARN, ResponseOptionalPropertyUpdatedCheck, DirectionResponse, LocationProperties, ActionRemove),
451+
newBackwardCompatibilityRule(ResponseOptionalWriteOnlyPropertyRemovedId, INFO, ResponseOptionalPropertyUpdatedCheck, DirectionResponse, LocationProperties, ActionRemove),
452+
newBackwardCompatibilityRule(RequestPropertyRemovedId, WARN, RequestPropertyUpdatedCheck, DirectionRequest, LocationProperties, ActionRemove),
450453
}
451454
}
452455

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
paths:
6+
/pets:
7+
post:
8+
requestBody:
9+
content:
10+
application/json:
11+
schema:
12+
type: object
13+
properties:
14+
name:
15+
type: string
16+
breed:
17+
type: string
18+
required:
19+
- name
20+
responses:
21+
'200':
22+
description: Success
23+
components: {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
paths:
6+
/pets:
7+
post:
8+
requestBody:
9+
content:
10+
application/json:
11+
schema:
12+
type: object
13+
properties:
14+
name:
15+
type: string
16+
required:
17+
- name
18+
responses:
19+
'200':
20+
description: Success
21+
components: {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
openapi: 3.0.0
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
paths:
6+
/pets:
7+
get:
8+
responses:
9+
'200':
10+
description: Successful response
11+
content:
12+
application/json:
13+
schema:
14+
type: object
15+
properties:
16+
name:
17+
type: string
18+
breed:
19+
type: string
20+
other:
21+
type: string
22+
writeOnly: true
23+
components: {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
penapi: 3.0.0
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
paths:
6+
/pets:
7+
get:
8+
responses:
9+
'200':
10+
description: Successful response
11+
content:
12+
application/json:
13+
schema:
14+
type: object
15+
properties:
16+
name:
17+
type: string
18+
components: {}

docs/BREAKING-CHANGES-EXAMPLES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ These examples are automatically generated from unit tests.
9999
[removing an existing required response header is breaking as error](../checker/check_breaking_test.go?plain=1#L207)
100100
[removing an existing response with non-successful status is breaking (optional)](../checker/check_breaking_test.go?plain=1#L246)
101101
[removing an existing response with successful status is breaking](../checker/check_breaking_test.go?plain=1#L227)
102+
[removing an optional field from the request body is breaking (optional)](../checker/check_breaking_test.go?plain=1#L747)
103+
[removing an optional field from the response body is breaking (optional)](../checker/check_breaking_test.go?plain=1#L773)
102104
[removing an schema object from components is breaking (optional)](../checker/check_breaking_test.go?plain=1#L619)
103105
[removing the default value of an optional request parameter is breaking](../checker/check_breaking_test.go?plain=1#L582)
104106
[removing the path without a deprecation policy and without specifying sunset date is breaking for endpoints with non draft/alpha stability level](../checker/check_api_removed_test.go?plain=1#L125)

0 commit comments

Comments
 (0)