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

support additionalProperties #603

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
44 changes: 44 additions & 0 deletions checker/check_response_property_type_changed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,47 @@ func TestResponseSchemaTypeMultiCheck(t *testing.T) {
OperationId: "createOneGroup",
}, errs[0])
}

// BC: changing an additionalResponse property schema type from integer to string is breaking
func TestResponseAdditionalPropertyTypeChangedCheck(t *testing.T) {
s1, err := open("../data/additional-properties/base.yaml")
require.NoError(t, err)
s2, err := open("../data/additional-properties/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.ERR)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.ResponsePropertyTypeChangedId,
Args: []any{"/additionalProperties/property1", utils.StringList{"integer"}, "", utils.StringList{"string"}, "", "200"},
Level: checker.ERR,
Operation: "GET",
Path: "/value",
Source: load.NewSource("../data/additional-properties/revision.yaml"),
OperationId: "get_value",
}, errs[0])
}

// BC: changing an embedded additionalResponse property schema type from integer to string is breaking
func TestResponseEmbeddedAdditionalPropertyTypeChangedCheck(t *testing.T) {
s1, err := open("../data/additional-properties/embedded-base.yaml")
require.NoError(t, err)
s2, err := open("../data/additional-properties/embedded-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.ERR)
require.Len(t, errs, 1)
require.Equal(t, checker.ApiChange{
Id: checker.ResponsePropertyTypeChangedId,
Args: []any{"composite-property/additionalProperties/property1", utils.StringList{"integer"}, "", utils.StringList{"string"}, "", "200"},
Level: checker.ERR,
Operation: "GET",
Path: "/value",
Source: load.NewSource("../data/additional-properties/embedded-revision.yaml"),
OperationId: "get_value",
}, errs[0])
}
4 changes: 4 additions & 0 deletions checker/checks-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ func processModifiedPropertiesDiff(propertyPath string, propertyName string, sch
processModifiedPropertiesDiff(propertyPath, i, v, schemaDiff, processor)
}
}

if schemaDiff.AdditionalPropertiesDiff != nil {
processModifiedPropertiesDiff(fmt.Sprintf("%s/additionalProperties", propertyPath), "", schemaDiff.AdditionalPropertiesDiff, schemaDiff, processor)
}
}

func CheckAddedPropertiesDiff(schemaDiff *diff.SchemaDiff, processor func(propertyPath string, propertyName string, propertyItem *openapi3.Schema, propertyParentDiff *diff.SchemaDiff)) {
Expand Down
28 changes: 28 additions & 0 deletions data/additional-properties/base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.0.1
info:
title: Test API
version: v1
components:
schemas:
Schema1:
properties:
property1:
title: Value
type: integer
type: object
Schema2:
additionalProperties:
"$ref": "#/components/schemas/Schema1"
title: Composite
type: object
paths:
"/value":
get:
operationId: get_value
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/Schema2"
description: Successful Response
31 changes: 31 additions & 0 deletions data/additional-properties/embedded-base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
openapi: 3.0.1
info:
title: Test API
version: v1
components:
schemas:
Schema1:
properties:
property1:
title: Value
type: integer
type: object
Schema2:
properties:
composite-property:
additionalProperties:
"$ref": "#/components/schemas/Schema1"
title: Composite
type: object
type: object
paths:
"/value":
get:
operationId: get_value
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/Schema2"
description: Successful Response
31 changes: 31 additions & 0 deletions data/additional-properties/embedded-revision.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
openapi: 3.0.1
info:
title: Test API
version: v1
components:
schemas:
Schema1:
properties:
property1:
title: Value
type: string
type: object
Schema2:
properties:
composite-property:
additionalProperties:
"$ref": "#/components/schemas/Schema1"
title: Composite
type: object
type: object
paths:
"/value":
get:
operationId: get_value
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/Schema2"
description: Successful Response
28 changes: 28 additions & 0 deletions data/additional-properties/revision.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
openapi: 3.0.1
info:
title: Test API
version: v1
components:
schemas:
Schema1:
properties:
property1:
title: Value
type: string
type: object
Schema2:
additionalProperties:
"$ref": "#/components/schemas/Schema1"
title: Composite
type: object
paths:
"/value":
get:
operationId: get_value
responses:
'200':
content:
application/json:
schema:
"$ref": "#/components/schemas/Schema2"
description: Successful Response
2 changes: 2 additions & 0 deletions docs/BREAKING-CHANGES-EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ These examples are automatically generated from unit tests.
[changing a response body to nullable is breaking](../checker/check_breaking_property_test.go?plain=1#L217)
[changing a response property to nullable is breaking](../checker/check_breaking_property_test.go?plain=1#L249)
[changing a response property to optional under AllOf, AnyOf or OneOf is breaking](../checker/check_breaking_property_test.go?plain=1#L660)
[changing an additionalResponse property schema type from integer to string is breaking](../checker/check_response_property_type_changed_test.go?plain=1#L150)
[changing an embedded additionalResponse property schema type from integer to string is breaking](../checker/check_response_property_type_changed_test.go?plain=1#L172)
[changing an embedded response property to nullable is breaking](../checker/check_breaking_property_test.go?plain=1#L265)
[changing an existing header param from optional to required is breaking](../checker/check_breaking_test.go?plain=1#L190)
[changing an existing path param to enum is breaking](../checker/check_breaking_property_test.go?plain=1#L185)
Expand Down
Loading