diff --git a/BREAKING-CHANGES-EXAMPLES.md b/BREAKING-CHANGES-EXAMPLES.md index 2812f159..491e5440 100644 --- a/BREAKING-CHANGES-EXAMPLES.md +++ b/BREAKING-CHANGES-EXAMPLES.md @@ -204,7 +204,7 @@ These examples are automatically generated from unit tests. [changing required response property to optional](checker/check-response-property-became-optional_test.go?plain=1#L11) [changing required response property to read-only](checker/check-response-required-property-write-only-read-only_test.go?plain=1#L63) [changing required response property to write-only](checker/check-response-required-property-write-only-read-only_test.go?plain=1#L11) -[changing response body default value](checker/check-response-property-default-value-changed_test.go?plain=1#L33) +[changing response body default value](checker/check-response-property-default-value-changed_test.go?plain=1#L42) [changing response body property default value](checker/check-response-property-default-value-changed_test.go?plain=1#L11) [changing response property pattern](checker/check-response-pattern-added-or-changed_test.go?plain=1#L11) [changing schema discriminator mapping in the request body or request body property](checker/check-request-discriminator-updated_test.go?plain=1#L119) diff --git a/checker/check-response-property-default-value-changed_test.go b/checker/check-response-property-default-value-changed_test.go index 093cd87c..e0714202 100644 --- a/checker/check-response-property-default-value-changed_test.go +++ b/checker/check-response-property-default-value-changed_test.go @@ -17,8 +17,8 @@ func TestResponsePropertyDefaultValueUpdatedCheck(t *testing.T) { d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) require.NoError(t, err) errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponsePropertyDefaultValueChangedCheck), d, osm, checker.INFO) - require.Len(t, errs, 1) - require.Equal(t, checker.ApiChange{ + require.Len(t, errs, 2) + require.ElementsMatch(t, []checker.ApiChange{{ Id: "response-property-default-value-changed", Text: "the 'created' response's property default value changed from '2020-01-01T00:00:00Z' to '2020-02-01T00:00:00Z' for the status '200'", Comment: "", @@ -27,7 +27,16 @@ func TestResponsePropertyDefaultValueUpdatedCheck(t *testing.T) { Path: "/api/v1.0/groups", Source: "../data/checker/response_property_default_value_changed_revision.yaml", OperationId: "createOneGroup", - }, errs[0]) + }, { + Id: "response-property-default-value-changed", + Text: "the 'enabled' response's property default value changed from 'false' to 'true' for the status '200'", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/api/v1.0/groups", + Source: "../data/checker/response_property_default_value_changed_revision.yaml", + OperationId: "createOneGroup", + }}, errs) } // CL: changing response body default value diff --git a/checker/checks-utils.go b/checker/checks-utils.go index b7b03ba5..87f7d580 100644 --- a/checker/checks-utils.go +++ b/checker/checks-utils.go @@ -30,22 +30,23 @@ func interfaceToString(arg interface{}) string { return "undefined" } - argString, ok := arg.(string) - if ok { + if argString, ok := arg.(string); ok { return argString } - argUint64, ok := arg.(uint64) - if ok { + if argUint64, ok := arg.(uint64); ok { return fmt.Sprintf("%d", argUint64) } - argFloat64, ok := arg.(float64) - if ok { + if argFloat64, ok := arg.(float64); ok { return fmt.Sprintf("%.2f", argFloat64) } - return fmt.Sprintf("%s", arg) + if argBool, ok := arg.(bool); ok { + return fmt.Sprintf("%t", argBool) + } + + return fmt.Sprintf("%v", arg) } func CheckModifiedPropertiesDiff(schemaDiff *diff.SchemaDiff, processor func(propertyPath string, propertyName string, propertyItem *diff.SchemaDiff, propertyParentItem *diff.SchemaDiff)) { diff --git a/data/checker/response_property_default_value_changed_base.yaml b/data/checker/response_property_default_value_changed_base.yaml index 77515be2..60ad88a5 100644 --- a/data/checker/response_property_default_value_changed_base.yaml +++ b/data/checker/response_property_default_value_changed_base.yaml @@ -3,7 +3,7 @@ info: title: Tufin version: "2.0" servers: -- url: https://localhost:9080 + - url: https://localhost:9080 paths: /api/v1.0/groups: post: @@ -13,7 +13,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/GroupView' + $ref: "#/components/schemas/GroupView" description: OK "404": content: @@ -21,7 +21,7 @@ paths: schema: type: string default: "Error" - description: Error + description: Error summary: Create One Project components: parameters: @@ -49,5 +49,8 @@ components: readOnly: true name: type: string + enabled: + default: false + type: boolean required: - - name \ No newline at end of file + - name diff --git a/data/checker/response_property_default_value_changed_revision.yaml b/data/checker/response_property_default_value_changed_revision.yaml index 949ed242..3e10bf36 100644 --- a/data/checker/response_property_default_value_changed_revision.yaml +++ b/data/checker/response_property_default_value_changed_revision.yaml @@ -3,7 +3,7 @@ info: title: Tufin version: "2.0" servers: -- url: https://localhost:9080 + - url: https://localhost:9080 paths: /api/v1.0/groups: post: @@ -13,7 +13,7 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/GroupView' + $ref: "#/components/schemas/GroupView" description: OK "404": content: @@ -21,7 +21,7 @@ paths: schema: type: string default: "Error" - description: Error + description: Error summary: Create One Project components: parameters: @@ -49,5 +49,8 @@ components: readOnly: true name: type: string + enabled: + default: true + type: boolean required: - - name \ No newline at end of file + - name