Skip to content

Commit

Permalink
Compare inline schemas under AllOf/AnyOf/OneOf by title (#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
reuvenharrison authored Apr 24, 2024
1 parent aa8fcea commit 341d77d
Show file tree
Hide file tree
Showing 32 changed files with 1,396 additions and 361 deletions.
1 change: 1 addition & 0 deletions BREAKING-CHANGES-EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ These examples are automatically generated from unit tests.
[changing optional response property to write-only](checker/check-response-optional-property-write-only-read-only_test.go?plain=1#L12)
[changing optional response write-only property to required](checker/check-response-property-became-required_test.go?plain=1#L33)
[changing pattern of request parameters](checker/check-request-parameter-pattern-added-or-changed_test.go?plain=1#L12)
[changing properties of subschemas under allOf](checker/check-response-property-type-changed_test.go?plain=1#L82)
[changing request body and property types from array to object](checker/check-request-property-type-changed_test.go?plain=1#L85)
[changing request body and property types from object to array](checker/check-request-property-type-changed_test.go?plain=1#L117)
[changing request body default value](checker/check-request-property-default-value-changed_test.go?plain=1#L12)
Expand Down
8 changes: 4 additions & 4 deletions checker/check-request-property-all-of-updated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestRequestPropertyAllOfAdded(t *testing.T) {
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.RequestBodyAllOfAddedId,
Args: []any{"Rabbit"},
Args: []any{"#/components/schemas/Rabbit"},
Level: checker.ERR,
Operation: "POST",
Path: "/pets",
Expand All @@ -34,7 +34,7 @@ func TestRequestPropertyAllOfAdded(t *testing.T) {
},
{
Id: checker.RequestPropertyAllOfAddedId,
Args: []any{"Breed3", "/allOf[#/components/schemas/Dog]/breed"},
Args: []any{"#/components/schemas/Breed3", "/allOf[#/components/schemas/Dog]/breed"},
Level: checker.ERR,
Operation: "POST",
Path: "/pets",
Expand All @@ -59,7 +59,7 @@ func TestRequestPropertyAllOfRemoved(t *testing.T) {
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.RequestBodyAllOfRemovedId,
Args: []any{"Rabbit"},
Args: []any{"#/components/schemas/Rabbit"},
Level: checker.WARN,
Operation: "POST",
Path: "/pets",
Expand All @@ -68,7 +68,7 @@ func TestRequestPropertyAllOfRemoved(t *testing.T) {
},
{
Id: checker.RequestPropertyAllOfRemovedId,
Args: []any{"Breed3", "/allOf[#/components/schemas/Dog]/breed"},
Args: []any{"#/components/schemas/Breed3", "/allOf[#/components/schemas/Dog]/breed"},
Level: checker.WARN,
Operation: "POST",
Path: "/pets",
Expand Down
8 changes: 4 additions & 4 deletions checker/check-request-property-any-of-updated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestRequestPropertyAnyOfAdded(t *testing.T) {
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.RequestBodyAnyOfAddedId,
Args: []any{"Rabbit"},
Args: []any{"#/components/schemas/Rabbit"},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Expand All @@ -34,7 +34,7 @@ func TestRequestPropertyAnyOfAdded(t *testing.T) {
},
{
Id: checker.RequestPropertyAnyOfAddedId,
Args: []any{"Breed3", "/anyOf[#/components/schemas/Dog]/breed"},
Args: []any{"#/components/schemas/Breed3", "/anyOf[#/components/schemas/Dog]/breed"},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Expand All @@ -59,7 +59,7 @@ func TestRequestPropertyAnyOfRemoved(t *testing.T) {
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.RequestBodyAnyOfRemovedId,
Args: []any{"Rabbit"},
Args: []any{"#/components/schemas/Rabbit"},
Level: checker.ERR,
Operation: "POST",
Path: "/pets",
Expand All @@ -68,7 +68,7 @@ func TestRequestPropertyAnyOfRemoved(t *testing.T) {
},
{
Id: checker.RequestPropertyAnyOfRemovedId,
Args: []any{"Breed3", "/anyOf[#/components/schemas/Dog]/breed"},
Args: []any{"#/components/schemas/Breed3", "/anyOf[#/components/schemas/Dog]/breed"},
Level: checker.ERR,
Operation: "POST",
Path: "/pets",
Expand Down
8 changes: 4 additions & 4 deletions checker/check-request-property-one-of-updated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestRequestPropertyOneOfAdded(t *testing.T) {
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.RequestBodyOneOfAddedId,
Args: []any{"Rabbit"},
Args: []any{"#/components/schemas/Rabbit"},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Expand All @@ -34,7 +34,7 @@ func TestRequestPropertyOneOfAdded(t *testing.T) {
},
{
Id: checker.RequestPropertyOneOfAddedId,
Args: []any{"Breed3", "/oneOf[#/components/schemas/Dog]/breed"},
Args: []any{"#/components/schemas/Breed3", "/oneOf[#/components/schemas/Dog]/breed"},
Level: checker.INFO,
Operation: "POST",
Path: "/pets",
Expand All @@ -59,7 +59,7 @@ func TestRequestPropertyOneOfRemoved(t *testing.T) {
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.RequestBodyOneOfRemovedId,
Args: []any{"Rabbit"},
Args: []any{"#/components/schemas/Rabbit"},
Level: checker.ERR,
Operation: "POST",
Path: "/pets",
Expand All @@ -68,7 +68,7 @@ func TestRequestPropertyOneOfRemoved(t *testing.T) {
},
{
Id: checker.RequestPropertyOneOfRemovedId,
Args: []any{"Breed3", "/oneOf[#/components/schemas/Dog]/breed"},
Args: []any{"#/components/schemas/Breed3", "/oneOf[#/components/schemas/Dog]/breed"},
Level: checker.ERR,
Operation: "POST",
Path: "/pets",
Expand Down
8 changes: 4 additions & 4 deletions checker/check-response-property-all-of-updated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestResponsePropertyAllOfAdded(t *testing.T) {
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.ResponseBodyAllOfAddedId,
Args: []any{"Rabbit", "200"},
Args: []any{"#/components/schemas/Rabbit", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand All @@ -34,7 +34,7 @@ func TestResponsePropertyAllOfAdded(t *testing.T) {
},
{
Id: checker.ResponsePropertyAllOfAddedId,
Args: []any{"Breed3", "/allOf[#/components/schemas/Dog]/breed", "200"},
Args: []any{"#/components/schemas/Breed3", "/allOf[#/components/schemas/Dog]/breed", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand All @@ -59,7 +59,7 @@ func TestResponsePropertyAllOfRemoved(t *testing.T) {
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.ResponseBodyAllOfRemovedId,
Args: []any{"Rabbit", "200"},
Args: []any{"#/components/schemas/Rabbit", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand All @@ -68,7 +68,7 @@ func TestResponsePropertyAllOfRemoved(t *testing.T) {
},
{
Id: checker.ResponsePropertyAllOfRemovedId,
Args: []any{"Breed3", "/allOf[#/components/schemas/Dog]/breed", "200"},
Args: []any{"#/components/schemas/Breed3", "/allOf[#/components/schemas/Dog]/breed", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand Down
8 changes: 4 additions & 4 deletions checker/check-response-property-any-of-updated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestResponsePropertyAnyOfAdded(t *testing.T) {
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.ResponseBodyAnyOfAddedId,
Args: []any{"Rabbit", "200"},
Args: []any{"#/components/schemas/Rabbit", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand All @@ -34,7 +34,7 @@ func TestResponsePropertyAnyOfAdded(t *testing.T) {
},
{
Id: checker.ResponsePropertyAnyOfAddedId,
Args: []any{"Breed3", "/anyOf[#/components/schemas/Dog]/breed", "200"},
Args: []any{"#/components/schemas/Breed3", "/anyOf[#/components/schemas/Dog]/breed", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand All @@ -59,7 +59,7 @@ func TestResponsePropertyAnyOfRemoved(t *testing.T) {
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.ResponseBodyAnyOfRemovedId,
Args: []any{"Rabbit", "200"},
Args: []any{"#/components/schemas/Rabbit", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand All @@ -68,7 +68,7 @@ func TestResponsePropertyAnyOfRemoved(t *testing.T) {
},
{
Id: checker.ResponsePropertyAnyOfRemovedId,
Args: []any{"Breed3", "/anyOf[#/components/schemas/Dog]/breed", "200"},
Args: []any{"#/components/schemas/Breed3", "/anyOf[#/components/schemas/Dog]/breed", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand Down
12 changes: 6 additions & 6 deletions checker/check-response-property-one-of-updated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestResponsePropertyOneOfAdded(t *testing.T) {
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.ResponseBodyOneOfAddedId,
Args: []any{"Rabbit", "200"},
Args: []any{"#/components/schemas/Rabbit", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand All @@ -34,7 +34,7 @@ func TestResponsePropertyOneOfAdded(t *testing.T) {
},
{
Id: checker.ResponsePropertyOneOfAddedId,
Args: []any{"Breed3", "/oneOf[#/components/schemas/Dog]/breed", "200"},
Args: []any{"#/components/schemas/Breed3", "/oneOf[#/components/schemas/Dog]/breed", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand All @@ -43,7 +43,7 @@ func TestResponsePropertyOneOfAdded(t *testing.T) {
},
{
Id: checker.ResponsePropertyOneOfAddedId,
Args: []any{"RevisionSchema[1]:Dark brown types", "/oneOf[#/components/schemas/Fox]/breed", "200"},
Args: []any{"subschema #2: Dark brown types", "/oneOf[#/components/schemas/Fox]/breed", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand All @@ -68,7 +68,7 @@ func TestResponsePropertyOneOfRemoved(t *testing.T) {
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.ResponseBodyOneOfRemovedId,
Args: []any{"Rabbit", "200"},
Args: []any{"#/components/schemas/Rabbit", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand All @@ -77,7 +77,7 @@ func TestResponsePropertyOneOfRemoved(t *testing.T) {
},
{
Id: checker.ResponsePropertyOneOfRemovedId,
Args: []any{"Breed3", "/oneOf[#/components/schemas/Dog]/breed", "200"},
Args: []any{"#/components/schemas/Breed3", "/oneOf[#/components/schemas/Dog]/breed", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand All @@ -86,7 +86,7 @@ func TestResponsePropertyOneOfRemoved(t *testing.T) {
},
{
Id: checker.ResponsePropertyOneOfRemovedId,
Args: []any{"BaseSchema[1]:Dark brown types", "/oneOf[#/components/schemas/Fox]/breed", "200"},
Args: []any{"subschema #2: Dark brown types", "/oneOf[#/components/schemas/Fox]/breed", "200"},
Level: checker.INFO,
Operation: "GET",
Path: "/pets",
Expand Down
42 changes: 42 additions & 0 deletions checker/check-response-property-type-changed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,45 @@ func TestResponsePropertyFormatChangedCheck(t *testing.T) {
OperationId: "createOneGroup",
}, errs[0])
}

// CL: changing properties of subschemas under allOf
func TestResponsePropertyAnyOfModified(t *testing.T) {
s1, err := open("../data/checker/response_property_any_of_complex_base.yaml")
require.NoError(t, err)
s2, err := open("../data/checker/response_property_any_of_complex_revision.yaml")
require.NoError(t, err)

d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2)
require.NoError(t, err)
errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyTypeChangedCheck), d, osm, checker.INFO)

require.Len(t, errs, 3)
require.ElementsMatch(t, []checker.ApiChange{
{
Id: checker.ResponsePropertyTypeChangedId,
Args: []any{"/anyOf[#/components/schemas/Dog]/breed/anyOf[#/components/schemas/Breed2]/name", "string", "", "number", "", "200"},
Level: checker.ERR,
Operation: "GET",
Path: "/pets",
Source: load.NewSource("../data/checker/response_property_any_of_complex_revision.yaml"),
OperationId: "listPets",
},
{
Id: checker.ResponsePropertyTypeChangedId,
Args: []any{"/anyOf[subschema #3: Rabbit]/", "string", "", "number", "", "200"},
Level: checker.ERR,
Operation: "GET",
Path: "/pets",
Source: load.NewSource("../data/checker/response_property_any_of_complex_revision.yaml"),
OperationId: "listPets",
},
{
Id: checker.ResponsePropertyTypeChangedId,
Args: []any{"/anyOf[subschema #4 -> subschema #5]/", "string", "", "number", "", "200"},
Level: checker.ERR,
Operation: "GET",
Path: "/pets",
Source: load.NewSource("../data/checker/response_property_any_of_complex_revision.yaml"),
OperationId: "listPets",
}}, errs)
}
16 changes: 8 additions & 8 deletions checker/checker_breaking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,11 +682,11 @@ func TestBreaking_RequestPropertyAnyOfRemoved(t *testing.T) {

require.Equal(t, checker.RequestBodyAnyOfRemovedId, errs[0].GetId())
require.Equal(t, checker.ERR, errs[0].GetLevel())
require.Equal(t, "removed 'Rabbit' from the request body 'anyOf' list", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed '#/components/schemas/Rabbit' from the request body 'anyOf' list", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))

require.Equal(t, checker.RequestPropertyAnyOfRemovedId, errs[1].GetId())
require.Equal(t, checker.ERR, errs[1].GetLevel())
require.Equal(t, "removed 'Breed3' from the '/anyOf[#/components/schemas/Dog]/breed' request property 'anyOf' list", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed '#/components/schemas/Breed3' from the '/anyOf[#/components/schemas/Dog]/breed' request property 'anyOf' list", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// BC: removing 'oneOf' schema from the request body or request body property is breaking
Expand All @@ -703,11 +703,11 @@ func TestBreaking_RequestPropertyOneOfRemoved(t *testing.T) {
require.Len(t, errs, 2)
require.Equal(t, checker.RequestBodyOneOfRemovedId, errs[0].GetId())
require.Equal(t, checker.ERR, errs[0].GetLevel())
require.Equal(t, "removed 'Rabbit' from the request body 'oneOf' list", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed '#/components/schemas/Rabbit' from the request body 'oneOf' list", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))

require.Equal(t, checker.RequestPropertyOneOfRemovedId, errs[1].GetId())
require.Equal(t, checker.ERR, errs[1].GetLevel())
require.Equal(t, "removed 'Breed3' from the '/oneOf[#/components/schemas/Dog]/breed' request property 'oneOf' list", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed '#/components/schemas/Breed3' from the '/oneOf[#/components/schemas/Dog]/breed' request property 'oneOf' list", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// BC: adding 'allOf' subschema to the request body or request body property is breaking
Expand All @@ -725,11 +725,11 @@ func TestBreaking_RequestPropertyAllOfAdded(t *testing.T) {

require.Equal(t, checker.RequestBodyAllOfAddedId, errs[0].GetId())
require.Equal(t, checker.ERR, errs[0].GetLevel())
require.Equal(t, "added 'Rabbit' to the request body 'allOf' list", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "added '#/components/schemas/Rabbit' to the request body 'allOf' list", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))

require.Equal(t, checker.RequestPropertyAllOfAddedId, errs[1].GetId())
require.Equal(t, checker.ERR, errs[1].GetLevel())
require.Equal(t, "added 'Breed3' to the '/allOf[#/components/schemas/Dog]/breed' request property 'allOf' list", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "added '#/components/schemas/Breed3' to the '/allOf[#/components/schemas/Dog]/breed' request property 'allOf' list", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer()))
}

// BC: removing 'allOf' subschema from the request body or request body property is breaking with warn
Expand All @@ -747,9 +747,9 @@ func TestBreaking_RequestPropertyAllOfRemoved(t *testing.T) {

require.Equal(t, checker.RequestBodyAllOfRemovedId, errs[0].GetId())
require.Equal(t, checker.WARN, errs[0].GetLevel())
require.Equal(t, "removed 'Rabbit' from the request body 'allOf' list", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed '#/components/schemas/Rabbit' from the request body 'allOf' list", errs[0].GetUncolorizedText(checker.NewDefaultLocalizer()))

require.Equal(t, checker.RequestPropertyAllOfRemovedId, errs[1].GetId())
require.Equal(t, checker.WARN, errs[1].GetLevel())
require.Equal(t, "removed 'Breed3' from the '/allOf[#/components/schemas/Dog]/breed' request property 'allOf' list", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer()))
require.Equal(t, "removed '#/components/schemas/Breed3' from the '/allOf[#/components/schemas/Dog]/breed' request property 'allOf' list", errs[1].GetUncolorizedText(checker.NewDefaultLocalizer()))
}
Loading

0 comments on commit 341d77d

Please sign in to comment.