diff --git a/BREAKING-CHANGES-EXAMPLES.md b/BREAKING-CHANGES-EXAMPLES.md index 9e3dbdf4..bbb644a5 100644 --- a/BREAKING-CHANGES-EXAMPLES.md +++ b/BREAKING-CHANGES-EXAMPLES.md @@ -168,6 +168,8 @@ These examples are automatically generated from unit tests. [adding an enum value to a response write-only property](checker/check-response-property-enum-value-added_test.go?plain=1#L36) [adding an enum value to request parameter](checker/check-request-parameter-enum-value-updated_test.go?plain=1#L34) [adding an optional write-only property to a response](checker/check-response-optional-property-updated_test.go?plain=1#L34) +[adding discriminator to the request body or request body property](checker/check-request-discriminator-updated_test.go?plain=1#L11) +[adding discriminator to the response body or response property](checker/check-response-discriminator-updated_test.go?plain=1#L11) [adding pattern to request parameters](checker/check-request-parameter-pattern-added-or-changed_test.go?plain=1#L35) [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) @@ -178,6 +180,10 @@ These examples are automatically generated from unit tests. [changing an existing header param from required to optional](checker/checker_request_parameter_required_value_updated_test.go?plain=1#L35) [changing an existing header param to optional](checker/checker_not_breaking_test.go?plain=1#L133) [changing an existing request body from required to optional](checker/checker_not_breaking_test.go?plain=1#L53) +[changing discriminator mapping in the request body or request body property](checker/check-request-discriminator-updated_test.go?plain=1#L119) +[changing discriminator mapping in the response body or response property](checker/check-response-discriminator-updated_test.go?plain=1#L119) +[changing discriminator propertyName in the request body or request body property](checker/check-request-discriminator-updated_test.go?plain=1#L83) +[changing discriminator propertyName in the response body or response property](checker/check-response-discriminator-updated_test.go?plain=1#L83) [changing optional request property to not read-only](checker/check-request-property-write-only-read-only_test.go?plain=1#L86) [changing optional request property to not write-only](checker/check-request-property-write-only-read-only_test.go?plain=1#L36) [changing optional request property to read-only](checker/check-request-property-write-only-read-only_test.go?plain=1#L61) @@ -220,7 +226,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 security component oauth's url](checker/check-components-security-updated_test.go?plain=1#L11) @@ -280,6 +286,8 @@ These examples are automatically generated from unit tests. [removing an existing operation id](checker/check-api-operation-id-updated_test.go?plain=1#L11) [removing an existing tag](checker/check-api-tag-updated_test.go?plain=1#L36) [removing an optional write-only property from a response](checker/check-response-optional-property-updated_test.go?plain=1#L11) +[removing discriminator from the request body or request body property](checker/check-request-discriminator-updated_test.go?plain=1#L47) +[removing discriminator from the response body or response property](checker/check-response-discriminator-updated_test.go?plain=1#L47) [removing media type from request body](checker/check-request-body-mediatype-updated_test.go?plain=1#L34) [removing pattern from request parameters](checker/check-request-parameter-pattern-added-or-changed_test.go?plain=1#L58) [removing request property enum values](checker/check-request-property-enum-value-updated_test.go?plain=1#L11) diff --git a/checker/check-request-discriminator-updated.go b/checker/check-request-discriminator-updated.go new file mode 100644 index 00000000..18ef0133 --- /dev/null +++ b/checker/check-request-discriminator-updated.go @@ -0,0 +1,148 @@ +package checker + +import ( + "fmt" + + "github.com/tufin/oasdiff/diff" +) + +func RequestDiscriminatorUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config Config) Changes { + result := make(Changes, 0) + if diffReport.PathsDiff == nil { + return result + } + + for path, pathItem := range diffReport.PathsDiff.Modified { + if pathItem.OperationsDiff == nil { + continue + } + + for operation, operationItem := range pathItem.OperationsDiff.Modified { + if operationItem.RequestBodyDiff == nil || + operationItem.RequestBodyDiff.ContentDiff == nil || + operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified == nil { + continue + } + source := (*operationsSources)[operationItem.Revision] + + appendResultItem := func(messageId string, a ...any) { + result = append(result, ApiChange{ + Id: messageId, + Level: INFO, + Text: fmt.Sprintf(config.i18n(messageId), a...), + Operation: operation, + OperationId: operationItem.Revision.OperationID, + Path: path, + Source: source, + }) + } + + for _, mediaTypeDiff := range operationItem.RequestBodyDiff.ContentDiff.MediaTypeModified { + if mediaTypeDiff.SchemaDiff == nil { + continue + } + + processDiscriminatorDiffForRequest( + mediaTypeDiff.SchemaDiff.DiscriminatorDiff, + "", + appendResultItem) + + CheckModifiedPropertiesDiff( + mediaTypeDiff.SchemaDiff, + func(propertyPath string, propertyName string, propertyDiff *diff.SchemaDiff, parent *diff.SchemaDiff) { + processDiscriminatorDiffForRequest( + propertyDiff.DiscriminatorDiff, + propertyFullName(propertyPath, propertyName), + appendResultItem) + }) + + } + } + } + return result +} + +func processDiscriminatorDiffForRequest( + discriminatorDiff *diff.DiscriminatorDiff, + propertyName string, + appendResultItem func(messageId string, a ...any)) { + + if discriminatorDiff == nil { + return + } + + messageIdPrefix := "request-body-discriminator" + if propertyName != "" { + messageIdPrefix = "request-property-discriminator" + } + + if discriminatorDiff.Added { + if propertyName == "" { + appendResultItem(messageIdPrefix + "-added") + } else { + appendResultItem(messageIdPrefix+"-added", ColorizedValue(propertyName)) + } + return + } + if discriminatorDiff.Deleted { + if propertyName == "" { + appendResultItem(messageIdPrefix + "-removed") + } else { + appendResultItem(messageIdPrefix+"-removed", ColorizedValue(propertyName)) + } + return + } + + if discriminatorDiff.PropertyNameDiff != nil { + if propertyName == "" { + appendResultItem(messageIdPrefix+"-property-name-changed", + ColorizedValue(discriminatorDiff.PropertyNameDiff.From), + ColorizedValue(discriminatorDiff.PropertyNameDiff.To)) + } else { + appendResultItem(messageIdPrefix+"-property-name-changed", + ColorizedValue(propertyName), + ColorizedValue(discriminatorDiff.PropertyNameDiff.From), + ColorizedValue(discriminatorDiff.PropertyNameDiff.To)) + } + } + + if discriminatorDiff.MappingDiff != nil { + if len(discriminatorDiff.MappingDiff.Added) > 0 { + if propertyName == "" { + appendResultItem(messageIdPrefix+"-mapping-added", + ColorizedValue(discriminatorDiff.MappingDiff.Added)) + } else { + appendResultItem(messageIdPrefix+"-mapping-added", + ColorizedValue(discriminatorDiff.MappingDiff.Added), + ColorizedValue(propertyName)) + } + } + + if len(discriminatorDiff.MappingDiff.Deleted) > 0 { + if propertyName == "" { + appendResultItem(messageIdPrefix+"-mapping-deleted", + ColorizedValue(discriminatorDiff.MappingDiff.Deleted)) + } else { + appendResultItem(messageIdPrefix+"-mapping-deleted", + ColorizedValue(discriminatorDiff.MappingDiff.Deleted), + ColorizedValue(propertyName)) + } + } + + for k, v := range discriminatorDiff.MappingDiff.Modified { + if propertyName == "" { + appendResultItem(messageIdPrefix+"-mapping-changed", + ColorizedValue(k), + ColorizedValue(v.From), + ColorizedValue(v.To)) + } else { + appendResultItem(messageIdPrefix+"-mapping-changed", + ColorizedValue(k), + ColorizedValue(v.From), + ColorizedValue(v.To), + ColorizedValue(propertyName)) + + } + } + } +} diff --git a/checker/check-request-discriminator-updated_test.go b/checker/check-request-discriminator-updated_test.go new file mode 100644 index 00000000..d6f8a9b4 --- /dev/null +++ b/checker/check-request-discriminator-updated_test.go @@ -0,0 +1,183 @@ +package checker_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/tufin/oasdiff/checker" + "github.com/tufin/oasdiff/diff" +) + +// CL: adding discriminator to the request body or request body property +func TestRequestDiscriminatorUpdatedCheckAdded(t *testing.T) { + s1, err := open("../data/checker/request_property_discriminator_added_base.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/request_property_discriminator_added_revision.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestDiscriminatorUpdatedCheck), d, osm, checker.INFO) + + require.Len(t, errs, 2) + + require.ElementsMatch(t, []checker.ApiChange{ + { + Id: "request-body-discriminator-added", + Text: "added request discriminator", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/request_property_discriminator_added_revision.yaml", + OperationId: "updatePets", + }, + { + Id: "request-property-discriminator-added", + Text: "added discriminator to '/oneOf[#/components/schemas/Dog]/breed' request property", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/request_property_discriminator_added_revision.yaml", + OperationId: "updatePets", + }}, errs) +} + +// CL: removing discriminator from the request body or request body property +func TestRequestDiscriminatorUpdatedCheckRemoved(t *testing.T) { + s1, err := open("../data/checker/request_property_discriminator_added_revision.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/request_property_discriminator_added_base.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestDiscriminatorUpdatedCheck), d, osm, checker.INFO) + + require.Len(t, errs, 2) + + require.ElementsMatch(t, []checker.ApiChange{ + { + Id: "request-body-discriminator-removed", + Text: "removed request discriminator", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/request_property_discriminator_added_base.yaml", + OperationId: "updatePets", + }, + { + Id: "request-property-discriminator-removed", + Text: "removed discriminator from '/oneOf[#/components/schemas/Dog]/breed' request property", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/request_property_discriminator_added_base.yaml", + OperationId: "updatePets", + }}, errs) +} + +// CL: changing discriminator propertyName in the request body or request body property +func TestRequestDiscriminatorUpdatedCheckPropertyNameChanging(t *testing.T) { + s1, err := open("../data/checker/request_property_discriminator_added_revision.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/request_property_discriminator_added_property_name_changed.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestDiscriminatorUpdatedCheck), d, osm, checker.INFO) + + require.Len(t, errs, 2) + + require.ElementsMatch(t, []checker.ApiChange{ + { + Id: "request-body-discriminator-property-name-changed", + Text: "request discriminator property name changed from 'petType' to 'petType2'", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/request_property_discriminator_added_property_name_changed.yaml", + OperationId: "updatePets", + }, + { + Id: "request-property-discriminator-property-name-changed", + Text: "request discriminator property name changed for '/oneOf[#/components/schemas/Dog]/breed' request property from 'name' to 'name2'", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/request_property_discriminator_added_property_name_changed.yaml", + OperationId: "updatePets", + }}, errs) +} + +// CL: changing discriminator mapping in the request body or request body property +func TestRequestDiscriminatorUpdatedCheckMappingChanging(t *testing.T) { + s1, err := open("../data/checker/request_property_discriminator_added_revision.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/request_property_discriminator_mapping_changed.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.RequestDiscriminatorUpdatedCheck), d, osm, checker.INFO) + + require.Len(t, errs, 5) + + require.ElementsMatch(t, []checker.ApiChange{ + { + Id: "request-body-discriminator-mapping-added", + Text: "added '[cats]' mapping keys to the request discriminator", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/request_property_discriminator_mapping_changed.yaml", + OperationId: "updatePets", + }, + { + Id: "request-body-discriminator-mapping-deleted", + Text: "removed '[cat]' mapping keys from the request discriminator", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/request_property_discriminator_mapping_changed.yaml", + OperationId: "updatePets", + }, + { + Id: "request-property-discriminator-mapping-added", + Text: "added '[breed1Code]' discriminator mapping keys to the '/oneOf[#/components/schemas/Dog]/breed' request property", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/request_property_discriminator_mapping_changed.yaml", + OperationId: "updatePets", + }, + { + Id: "request-property-discriminator-mapping-changed", + Text: "mapped value for discriminator key 'breed2' changed from '#/components/schemas/Breed2' to '#/components/schemas/Breed3' for '/oneOf[#/components/schemas/Dog]/breed' request property", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/request_property_discriminator_mapping_changed.yaml", + OperationId: "updatePets", + }, + { + Id: "request-property-discriminator-mapping-deleted", + Text: "removed '[breed1]' discriminator mapping keys from the '/oneOf[#/components/schemas/Dog]/breed' request property", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/request_property_discriminator_mapping_changed.yaml", + OperationId: "updatePets", + }}, errs) +} diff --git a/checker/check-response-discriminator-updated.go b/checker/check-response-discriminator-updated.go new file mode 100644 index 00000000..6a3650e9 --- /dev/null +++ b/checker/check-response-discriminator-updated.go @@ -0,0 +1,163 @@ +package checker + +import ( + "fmt" + + "github.com/tufin/oasdiff/diff" +) + +func ResponseDiscriminatorUpdatedCheck(diffReport *diff.Diff, operationsSources *diff.OperationsSourcesMap, config Config) Changes { + result := make(Changes, 0) + if diffReport.PathsDiff == nil { + return result + } + + for path, pathItem := range diffReport.PathsDiff.Modified { + if pathItem.OperationsDiff == nil { + continue + } + + for operation, operationItem := range pathItem.OperationsDiff.Modified { + if operationItem.ResponsesDiff == nil || operationItem.ResponsesDiff.Modified == nil { + continue + } + source := (*operationsSources)[operationItem.Revision] + + appendResultItem := func(messageId string, a ...any) { + result = append(result, ApiChange{ + Id: messageId, + Level: INFO, + Text: fmt.Sprintf(config.i18n(messageId), a...), + Operation: operation, + OperationId: operationItem.Revision.OperationID, + Path: path, + Source: source, + }) + } + + for responseStatus, responsesDiff := range operationItem.ResponsesDiff.Modified { + if responsesDiff.ContentDiff == nil || responsesDiff.ContentDiff.MediaTypeModified == nil { + continue + } + + modifiedMediaTypes := responsesDiff.ContentDiff.MediaTypeModified + for _, mediaTypeDiff := range modifiedMediaTypes { + if mediaTypeDiff.SchemaDiff == nil { + continue + } + + processDiscriminatorDiff( + mediaTypeDiff.SchemaDiff.DiscriminatorDiff, + responseStatus, + "", + appendResultItem) + + CheckModifiedPropertiesDiff( + mediaTypeDiff.SchemaDiff, + func(propertyPath string, propertyName string, propertyDiff *diff.SchemaDiff, parent *diff.SchemaDiff) { + processDiscriminatorDiff( + propertyDiff.DiscriminatorDiff, + responseStatus, + propertyFullName(propertyPath, propertyName), + appendResultItem) + }) + } + } + } + } + return result +} + +func processDiscriminatorDiff( + discriminatorDiff *diff.DiscriminatorDiff, + responseStatus string, + propertyName string, + appendResultItem func(messageId string, a ...any)) { + + if discriminatorDiff == nil { + return + } + + messageIdPrefix := "response-body-discriminator" + if propertyName != "" { + messageIdPrefix = "response-property-discriminator" + } + + if discriminatorDiff.Added { + if propertyName == "" { + appendResultItem(messageIdPrefix+"-added", responseStatus) + } else { + appendResultItem(messageIdPrefix+"-added", ColorizedValue(propertyName), responseStatus) + } + return + } + if discriminatorDiff.Deleted { + if propertyName == "" { + appendResultItem(messageIdPrefix+"-removed", responseStatus) + } else { + appendResultItem(messageIdPrefix+"-removed", ColorizedValue(propertyName), responseStatus) + } + return + } + + if discriminatorDiff.PropertyNameDiff != nil { + if propertyName == "" { + appendResultItem(messageIdPrefix+"-property-name-changed", + ColorizedValue(discriminatorDiff.PropertyNameDiff.From), + ColorizedValue(discriminatorDiff.PropertyNameDiff.To), + responseStatus) + } else { + appendResultItem(messageIdPrefix+"-property-name-changed", + ColorizedValue(propertyName), + ColorizedValue(discriminatorDiff.PropertyNameDiff.From), + ColorizedValue(discriminatorDiff.PropertyNameDiff.To), + responseStatus) + } + } + + if discriminatorDiff.MappingDiff != nil { + if len(discriminatorDiff.MappingDiff.Added) > 0 { + if propertyName == "" { + appendResultItem(messageIdPrefix+"-mapping-added", + ColorizedValue(discriminatorDiff.MappingDiff.Added), + responseStatus) + } else { + appendResultItem(messageIdPrefix+"-mapping-added", + ColorizedValue(discriminatorDiff.MappingDiff.Added), + ColorizedValue(propertyName), + responseStatus) + } + } + + if len(discriminatorDiff.MappingDiff.Deleted) > 0 { + if propertyName == "" { + appendResultItem(messageIdPrefix+"-mapping-deleted", + ColorizedValue(discriminatorDiff.MappingDiff.Deleted), + responseStatus) + } else { + appendResultItem(messageIdPrefix+"-mapping-deleted", + ColorizedValue(discriminatorDiff.MappingDiff.Deleted), + ColorizedValue(propertyName), + responseStatus) + } + } + + for k, v := range discriminatorDiff.MappingDiff.Modified { + if propertyName == "" { + appendResultItem(messageIdPrefix+"-mapping-changed", + ColorizedValue(k), + ColorizedValue(v.From), + ColorizedValue(v.To), + responseStatus) + } else { + appendResultItem(messageIdPrefix+"-mapping-changed", + ColorizedValue(k), + ColorizedValue(v.From), + ColorizedValue(v.To), + ColorizedValue(propertyName), + responseStatus) + + } + } + } +} diff --git a/checker/check-response-discriminator-updated_test.go b/checker/check-response-discriminator-updated_test.go new file mode 100644 index 00000000..4010eba5 --- /dev/null +++ b/checker/check-response-discriminator-updated_test.go @@ -0,0 +1,183 @@ +package checker_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + "github.com/tufin/oasdiff/checker" + "github.com/tufin/oasdiff/diff" +) + +// CL: adding discriminator to the response body or response property +func TestResponseDiscriminatorUpdatedCheckAdded(t *testing.T) { + s1, err := open("../data/checker/response_property_discriminator_added_base.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/response_property_discriminator_added_revision.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseDiscriminatorUpdatedCheck), d, osm, checker.INFO) + + require.Len(t, errs, 2) + + require.ElementsMatch(t, []checker.ApiChange{ + { + Id: "response-body-discriminator-added", + Text: "added response discriminator for the response status 200", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/response_property_discriminator_added_revision.yaml", + OperationId: "updatePets", + }, + { + Id: "response-property-discriminator-added", + Text: "added discriminator to '/oneOf[#/components/schemas/Dog]/breed' response property for the response status 200", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/response_property_discriminator_added_revision.yaml", + OperationId: "updatePets", + }}, errs) +} + +// CL: removing discriminator from the response body or response property +func TestResponseDiscriminatorUpdatedCheckRemoved(t *testing.T) { + s1, err := open("../data/checker/response_property_discriminator_added_revision.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/response_property_discriminator_added_base.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseDiscriminatorUpdatedCheck), d, osm, checker.INFO) + + require.Len(t, errs, 2) + + require.ElementsMatch(t, []checker.ApiChange{ + { + Id: "response-body-discriminator-removed", + Text: "removed response discriminator for the response status 200", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/response_property_discriminator_added_base.yaml", + OperationId: "updatePets", + }, + { + Id: "response-property-discriminator-removed", + Text: "removed discriminator from '/oneOf[#/components/schemas/Dog]/breed' response property for the response status 200", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/response_property_discriminator_added_base.yaml", + OperationId: "updatePets", + }}, errs) +} + +// CL: changing discriminator propertyName in the response body or response property +func TestResponseDiscriminatorUpdatedCheckPropertyNameChanging(t *testing.T) { + s1, err := open("../data/checker/response_property_discriminator_added_revision.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/response_property_discriminator_added_property_name_changed.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseDiscriminatorUpdatedCheck), d, osm, checker.INFO) + + require.Len(t, errs, 2) + + require.ElementsMatch(t, []checker.ApiChange{ + { + Id: "response-body-discriminator-property-name-changed", + Text: "response discriminator property name changed from 'petType' to 'petType2' for the response status 200", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/response_property_discriminator_added_property_name_changed.yaml", + OperationId: "updatePets", + }, + { + Id: "response-property-discriminator-property-name-changed", + Text: "response discriminator property name changed for '/oneOf[#/components/schemas/Dog]/breed' response property from 'name' to 'name2' for the response status 200", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/response_property_discriminator_added_property_name_changed.yaml", + OperationId: "updatePets", + }}, errs) +} + +// CL: changing discriminator mapping in the response body or response property +func TestResponseDiscriminatorUpdatedCheckMappingChanging(t *testing.T) { + s1, err := open("../data/checker/response_property_discriminator_added_revision.yaml") + require.NoError(t, err) + s2, err := open("../data/checker/response_property_discriminator_mapping_changed.yaml") + require.NoError(t, err) + + d, osm, err := diff.GetWithOperationsSourcesMap(getConfig(), s1, s2) + require.NoError(t, err) + errs := checker.CheckBackwardCompatibilityUntilLevel(singleCheckConfig(checker.ResponseDiscriminatorUpdatedCheck), d, osm, checker.INFO) + + require.Len(t, errs, 5) + + require.ElementsMatch(t, []checker.ApiChange{ + { + Id: "response-body-discriminator-mapping-added", + Text: "added '[cats]' mapping keys to the response discriminator for the response status 200", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/response_property_discriminator_mapping_changed.yaml", + OperationId: "updatePets", + }, + { + Id: "response-body-discriminator-mapping-deleted", + Text: "removed '[cat]' mapping keys from the response discriminator for the response status 200", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/response_property_discriminator_mapping_changed.yaml", + OperationId: "updatePets", + }, + { + Id: "response-property-discriminator-mapping-added", + Text: "added '[breed1Code]' discriminator mapping keys to the '/oneOf[#/components/schemas/Dog]/breed' response property for the response status 200", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/response_property_discriminator_mapping_changed.yaml", + OperationId: "updatePets", + }, + { + Id: "response-property-discriminator-mapping-changed", + Text: "mapped value for discriminator key 'breed2' changed from '#/components/schemas/Breed2' to '#/components/schemas/Breed3' for '/oneOf[#/components/schemas/Dog]/breed' response property for the response status 200", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/response_property_discriminator_mapping_changed.yaml", + OperationId: "updatePets", + }, + { + Id: "response-property-discriminator-mapping-deleted", + Text: "removed '[breed1]' discriminator mapping keys from the '/oneOf[#/components/schemas/Dog]/breed' response property for the response status 200", + Comment: "", + Level: checker.INFO, + Operation: "POST", + Path: "/pets", + Source: "../data/checker/response_property_discriminator_mapping_changed.yaml", + OperationId: "updatePets", + }}, errs) +} 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/checker/default_checks.go b/checker/default_checks.go index f0e42ebb..4923ed30 100644 --- a/checker/default_checks.go +++ b/checker/default_checks.go @@ -137,6 +137,8 @@ func defaultChecks() []BackwardCompatibilityCheck { RequestPropertyAllOfUpdated, ResponsePropertyAllOfUpdated, RequestPropertyWriteOnlyReadOnlyCheck, + RequestDiscriminatorUpdatedCheck, + ResponseDiscriminatorUpdatedCheck, } } diff --git a/checker/localizations/localizations.go b/checker/localizations/localizations.go index 7d6cb22b..644a2d0e 100644 --- a/checker/localizations/localizations.go +++ b/checker/localizations/localizations.go @@ -1,6 +1,6 @@ // Code generated by go-localize; DO NOT EDIT. // This file was generated by robots at -// 2023-07-31 22:54:08.00252 +0100 IST m=+0.005108876 +// 2023-08-03 13:39:56.106803 +0100 IST m=+0.005883043 package localizations @@ -66,6 +66,12 @@ var localizations = map[string]string{ "en.messages.request-body-became-optional": "request body became optional", "en.messages.request-body-became-required": "request body became required", "en.messages.request-body-default-value-changed": "the request body %s default value changed from %s to %s", + "en.messages.request-body-discriminator-added": "added request discriminator", + "en.messages.request-body-discriminator-mapping-added": "added %s mapping keys to the request discriminator", + "en.messages.request-body-discriminator-mapping-changed": "mapped value for key %s changed from %s to %s from the request discriminator", + "en.messages.request-body-discriminator-mapping-deleted": "removed %s mapping keys from the request discriminator", + "en.messages.request-body-discriminator-property-name-changed": "request discriminator property name changed from %s to %s", + "en.messages.request-body-discriminator-removed": "removed request discriminator", "en.messages.request-body-enum-value-removed": "request body enum value removed %s", "en.messages.request-body-max-decreased": "the request's body max was decreased to %s", "en.messages.request-body-max-increased": "the request's body max was increased from %s to %s", @@ -138,6 +144,12 @@ var localizations = map[string]string{ "en.messages.request-property-became-optional": "the request property %s became optional", "en.messages.request-property-became-required": "the request property %s became required", "en.messages.request-property-default-value-changed": "the %s request property default value changed from %s to %s", + "en.messages.request-property-discriminator-added": "added discriminator to %s request property", + "en.messages.request-property-discriminator-mapping-added": "added %s discriminator mapping keys to the %s request property", + "en.messages.request-property-discriminator-mapping-changed": "mapped value for discriminator key %s changed from %s to %s for %s request property", + "en.messages.request-property-discriminator-mapping-deleted": "removed %s discriminator mapping keys from the %s request property", + "en.messages.request-property-discriminator-property-name-changed": "request discriminator property name changed for %s request property from %s to %s", + "en.messages.request-property-discriminator-removed": "removed discriminator from %s request property", "en.messages.request-property-enum-value-added": "added the new %s enum value to the request property %s", "en.messages.request-property-enum-value-removed": "removed the enum value %s of the request property %s", "en.messages.request-property-max-decreased": "the %s request property's max was decreased to %s", @@ -177,6 +189,12 @@ var localizations = map[string]string{ "en.messages.response-body-any-of-removed": "removed %s from the response body 'anyOf' list for the response status %s", "en.messages.response-body-became-nullable": "the response's body became nullable", "en.messages.response-body-default-value-changed": "the response body %s default value changed from %s to %s for the status %s", + "en.messages.response-body-discriminator-added": "added response discriminator for the response status %s", + "en.messages.response-body-discriminator-mapping-added": "added %s mapping keys to the response discriminator for the response status %s", + "en.messages.response-body-discriminator-mapping-changed": "mapped value for key %s changed from %s to %s from the response discriminator for the response status %s", + "en.messages.response-body-discriminator-mapping-deleted": "removed %s mapping keys from the response discriminator for the response status %s", + "en.messages.response-body-discriminator-property-name-changed": "response discriminator property name changed from %s to %s for the response status %s", + "en.messages.response-body-discriminator-removed": "removed response discriminator for the response status %s", "en.messages.response-body-max-increased": "the response's body max was increased from %s to %s", "en.messages.response-body-max-length-increased": "the response's body maxLength was increased from %s to %s", "en.messages.response-body-max-length-unset": "the response's body maxLength was unset from %s", @@ -209,6 +227,12 @@ var localizations = map[string]string{ "en.messages.response-property-became-optional": "the response property %s became optional for the status %s", "en.messages.response-property-became-required": "the response property %s became required for the status %s", "en.messages.response-property-default-value-changed": "the %s response's property default value changed from %s to %s for the status %s", + "en.messages.response-property-discriminator-added": "added discriminator to %s response property for the response status %s", + "en.messages.response-property-discriminator-mapping-added": "added %s discriminator mapping keys to the %s response property for the response status %s", + "en.messages.response-property-discriminator-mapping-changed": "mapped value for discriminator key %s changed from %s to %s for %s response property for the response status %s", + "en.messages.response-property-discriminator-mapping-deleted": "removed %s discriminator mapping keys from the %s response property for the response status %s", + "en.messages.response-property-discriminator-property-name-changed": "response discriminator property name changed for %s response property from %s to %s for the response status %s", + "en.messages.response-property-discriminator-removed": "removed discriminator from %s response property for the response status %s", "en.messages.response-property-enum-value-added": "added the new '%s' enum value to the %s response property for the response status %s", "en.messages.response-property-enum-value-added-comment": "Adding new enum values to response could be unexpected for clients, use x-extensible-enum instead.", "en.messages.response-property-enum-value-removed": "removed the '%s' enum value from the %s response property for the response status %s", @@ -296,6 +320,12 @@ var localizations = map[string]string{ "ru.messages.request-body-became-optional": "тело запроса стало необязательным", "ru.messages.request-body-became-required": "тело запроса стало обязательным", "ru.messages.request-body-default-value-changed": "значение по умолчанию для тела запроса было изменено с %s на %s", + "ru.messages.request-body-discriminator-added": "добавлен дискриминатор запроса", + "ru.messages.request-body-discriminator-mapping-added": "добавлены ключи сопоставления %s для дискриминатора запроса", + "ru.messages.request-body-discriminator-mapping-changed": "значение для ключа %s изменено с %s на %s в дискриминаторе запроса", + "ru.messages.request-body-discriminator-mapping-deleted": "удалены ключи сопоставления %s из дискриминатора запроса", + "ru.messages.request-body-discriminator-property-name-changed": "имя свойства дискриминатора запроса изменено с %s на %s", + "ru.messages.request-body-discriminator-removed": "удален дискриминатор запроса", "ru.messages.request-body-enum-value-removed": "значение перечисления тела запроса удалено %s", "ru.messages.request-body-max-decreased": "значение max у тела запроса уменьшено до %s", "ru.messages.request-body-max-increased": "максимум тела запроса был увеличен с %s до %s", @@ -368,6 +398,12 @@ var localizations = map[string]string{ "ru.messages.request-property-became-optional": "поле запроса %s стало необязательным", "ru.messages.request-property-became-required": "поле запроса %s стало обязательным", "ru.messages.request-property-default-value-changed": "значение по умолчанию для свойства %s в запросе было изменено с %s на %s", + "ru.messages.request-property-discriminator-added": "добавлен дискриминатор к свойству запроса %s", + "ru.messages.request-property-discriminator-mapping-added": "добавлены ключи сопоставления дискриминатора %s для свойства запроса %s", + "ru.messages.request-property-discriminator-mapping-changed": "значение для ключа дискриминатора %s изменено с %s на %s для свойства запроса %s", + "ru.messages.request-property-discriminator-mapping-deleted": "удалены ключи сопоставления дискриминатора %s из свойства запроса %s", + "ru.messages.request-property-discriminator-property-name-changed": "имя свойства дискриминатора запроса изменено для свойства запроса %s с %s на %s", + "ru.messages.request-property-discriminator-removed": "удален дискриминатор из свойства запроса %s", "ru.messages.request-property-enum-value-added": "добавлено enum значение %s у поля запроса %s", "ru.messages.request-property-enum-value-removed": "удалено enum значение %s у поля запроса %s", "ru.messages.request-property-max-decreased": "значение max у поля запроса %s уменьшено до %s", @@ -407,6 +443,12 @@ var localizations = map[string]string{ "ru.messages.response-body-any-of-removed": "удалён %s из списка 'anyOf' тела ответа для статуса ответа %s", "ru.messages.response-body-became-nullable": "у тела ответа стало обнуляемым", "ru.messages.response-body-default-value-changed": "значение по умолчанию для тела ответа со статусом %s было изменено с %s на %s", + "ru.messages.response-body-discriminator-added": "добавлен дискриминатор ответа для статуса ответа %s", + "ru.messages.response-body-discriminator-mapping-added": "добавлены ключи сопоставления %s для дискриминатора ответа для статуса ответа %s", + "ru.messages.response-body-discriminator-mapping-changed": "значение для ключа %s изменено с %s на %s в дискриминаторе ответа для статуса ответа %s", + "ru.messages.response-body-discriminator-mapping-deleted": "удалены ключи сопоставления %s из дискриминатора ответа для статуса ответа %s", + "ru.messages.response-body-discriminator-property-name-changed": "имя свойства дискриминатора ответа изменено с %s на %s для статуса ответа %s", + "ru.messages.response-body-discriminator-removed": "удален дискриминатор ответа для статуса ответа %s", "ru.messages.response-body-max-increased": "у тела ответа max увеличен с %s до %s", "ru.messages.response-body-max-length-increased": "у тела ответа maxLength увеличен с %s до %s", "ru.messages.response-body-max-length-unset": "у тела ответа maxLength был удалён, предыдущее значение - %s", @@ -440,6 +482,12 @@ var localizations = map[string]string{ "ru.messages.response-property-became-required": "свойство %s перестало быть необязательным для ответа со статусом %s", "ru.messages.response-property-became-write-only": "свойство %s перестало быть только для записи для ответа со статусом %s", "ru.messages.response-property-default-value-changed": "значение по умолчанию для свойства %s в ответе со статусом %s было изменено с %s на %s", + "ru.messages.response-property-discriminator-added": "добавлен дискриминатор к свойству ответа %s для статуса ответа %s", + "ru.messages.response-property-discriminator-mapping-added": "добавлены ключи сопоставления дискриминатора %s для свойства ответа %s для статуса ответа %s", + "ru.messages.response-property-discriminator-mapping-changed": "значение для ключа дискриминатора %s изменено с %s на %s для свойства ответа %s для статуса ответа %s", + "ru.messages.response-property-discriminator-mapping-deleted": "удалены ключи сопоставления дискриминатора %s из свойства ответа %s для статуса ответа %s", + "ru.messages.response-property-discriminator-property-name-changed": "имя свойства дискриминатора ответа изменено для свойства ответа %s с %s на %s для статуса ответа %s", + "ru.messages.response-property-discriminator-removed": "удален дискриминатор из свойства ответа %s для статуса ответа %s", "ru.messages.response-property-enum-value-added": "добавлено новое enum значение %s в поле ответа %s для ответа со статусом %s", "ru.messages.response-property-enum-value-added-comment": "Добавление новых значений перечисления в ответ может быть неожиданным для клиентов, вместо этого используйте x-extensible-enum.", "ru.messages.response-property-enum-value-removed": "удалено значение перечисления '%s' из свойства ответа %s для статуса ответа %s.", diff --git a/checker/localizations_src/en/messages.yaml b/checker/localizations_src/en/messages.yaml index 2cff6b87..8656b5bd 100644 --- a/checker/localizations_src/en/messages.yaml +++ b/checker/localizations_src/en/messages.yaml @@ -220,11 +220,35 @@ response-body-all-of-added: added %s to the response body 'allOf' list for the r response-body-all-of-removed: removed %s from the response body 'allOf' list for the response status %s response-property-all-of-added: added %s to the %s response property 'allOf' list for the response status %s response-property-all-of-removed: removed %s from the %s response property 'allOf' list for the response status %s -request-required-property-became-read-only: the request required property %s became read-only +response-body-discriminator-added: added response discriminator for the response status %s +response-property-discriminator-added: added discriminator to %s response property for the response status %s +response-body-discriminator-removed: removed response discriminator for the response status %s +response-property-discriminator-removed: removed discriminator from %s response property for the response status %s +response-body-discriminator-property-name-changed: response discriminator property name changed from %s to %s for the response status %s +response-property-discriminator-property-name-changed: response discriminator property name changed for %s response property from %s to %s for the response status %s +response-body-discriminator-mapping-added: added %s mapping keys to the response discriminator for the response status %s +response-property-discriminator-mapping-added: added %s discriminator mapping keys to the %s response property for the response status %s +response-body-discriminator-mapping-deleted: removed %s mapping keys from the response discriminator for the response status %s +response-property-discriminator-mapping-deleted: removed %s discriminator mapping keys from the %s response property for the response status %s +response-body-discriminator-mapping-changed: mapped value for key %s changed from %s to %s from the response discriminator for the response status %s +response-property-discriminator-mapping-changed: mapped value for discriminator key %s changed from %s to %s for %s response property for the response status %s +request-body-discriminator-added: added request discriminator +request-property-discriminator-added: added discriminator to %s request property +request-body-discriminator-removed: removed request discriminator +request-property-discriminator-removed: removed discriminator from %s request property +request-body-discriminator-property-name-changed: request discriminator property name changed from %s to %s +request-property-discriminator-property-name-changed: request discriminator property name changed for %s request property from %s to %s +request-body-discriminator-mapping-added: added %s mapping keys to the request discriminator +request-property-discriminator-mapping-added: added %s discriminator mapping keys to the %s request property +request-body-discriminator-mapping-deleted: removed %s mapping keys from the request discriminator +request-property-discriminator-mapping-deleted: removed %s discriminator mapping keys from the %s request property +request-body-discriminator-mapping-changed: mapped value for key %s changed from %s to %s from the request discriminator +request-property-discriminator-mapping-changed: mapped value for discriminator key %s changed from %s to %s for %s request property +request-required-property-became-read-only: the request required property %s became read-only request-required-property-became-not-read-only: the request required property %s became not read-only request-optional-property-became-write-only: the request optional property %s became write-only request-optional-property-became-read-only: the request optional property %s became read-only request-optional-property-became-not-write-only: the request optional property %s became not write-only request-optional-property-became-not-read-only: the request optional property %s became not read-only request-required-property-became-write-only: the request required property %s became write-only -request-required-property-became-not-write-only: the request required property %s became not write-only \ No newline at end of file +request-required-property-became-not-write-only: the request required property %s became not write-only diff --git a/checker/localizations_src/ru/messages.yaml b/checker/localizations_src/ru/messages.yaml index 815ef349..fc08ebae 100644 --- a/checker/localizations_src/ru/messages.yaml +++ b/checker/localizations_src/ru/messages.yaml @@ -218,6 +218,30 @@ response-body-all-of-added: добавлено %s в список 'allOf' тел response-body-all-of-removed: удалён %s из списка 'allOf' тела ответа для статуса ответа %s response-property-all-of-added: добавлено %s в список 'allOf' свойства ответа %s для статуса ответа %s response-property-all-of-removed: удалён %s из списка 'allOf' свойства ответа %s для статуса ответа %s +response-body-discriminator-added: добавлен дискриминатор ответа для статуса ответа %s +response-property-discriminator-added: добавлен дискриминатор к свойству ответа %s для статуса ответа %s +response-body-discriminator-removed: удален дискриминатор ответа для статуса ответа %s +response-property-discriminator-removed: удален дискриминатор из свойства ответа %s для статуса ответа %s +response-body-discriminator-property-name-changed: имя свойства дискриминатора ответа изменено с %s на %s для статуса ответа %s +response-property-discriminator-property-name-changed: имя свойства дискриминатора ответа изменено для свойства ответа %s с %s на %s для статуса ответа %s +response-body-discriminator-mapping-added: добавлены ключи сопоставления %s для дискриминатора ответа для статуса ответа %s +response-property-discriminator-mapping-added: добавлены ключи сопоставления дискриминатора %s для свойства ответа %s для статуса ответа %s +response-body-discriminator-mapping-deleted: удалены ключи сопоставления %s из дискриминатора ответа для статуса ответа %s +response-property-discriminator-mapping-deleted: удалены ключи сопоставления дискриминатора %s из свойства ответа %s для статуса ответа %s +response-body-discriminator-mapping-changed: значение для ключа %s изменено с %s на %s в дискриминаторе ответа для статуса ответа %s +response-property-discriminator-mapping-changed: значение для ключа дискриминатора %s изменено с %s на %s для свойства ответа %s для статуса ответа %s +request-body-discriminator-added: добавлен дискриминатор запроса +request-property-discriminator-added: добавлен дискриминатор к свойству запроса %s +request-body-discriminator-removed: удален дискриминатор запроса +request-property-discriminator-removed: удален дискриминатор из свойства запроса %s +request-body-discriminator-property-name-changed: имя свойства дискриминатора запроса изменено с %s на %s +request-property-discriminator-property-name-changed: имя свойства дискриминатора запроса изменено для свойства запроса %s с %s на %s +request-body-discriminator-mapping-added: добавлены ключи сопоставления %s для дискриминатора запроса +request-property-discriminator-mapping-added: добавлены ключи сопоставления дискриминатора %s для свойства запроса %s +request-body-discriminator-mapping-deleted: удалены ключи сопоставления %s из дискриминатора запроса +request-property-discriminator-mapping-deleted: удалены ключи сопоставления дискриминатора %s из свойства запроса %s +request-body-discriminator-mapping-changed: значение для ключа %s изменено с %s на %s в дискриминаторе запроса +request-property-discriminator-mapping-changed: значение для ключа дискриминатора %s изменено с %s на %s для свойства запроса %s request-property-default-value-changed: значение по умолчанию для свойства %s в запросе было изменено с %s на %s request-body-default-value-changed: значение по умолчанию для тела запроса было изменено с %s на %s request-required-property-became-read-only: обязательное поле запроса %s стало только для чтения @@ -227,4 +251,4 @@ request-optional-property-became-read-only: необязательное пол request-optional-property-became-not-write-only: необязательное поле запроса %s перестало быть только для записи request-optional-property-became-not-read-only: необязательное поле запроса %s перестало быть только для чтения request-required-property-became-write-only: обязательное поле запроса %s стало только для записи -request-required-property-became-not-write-only: обязательное поле запроса %s перестало быть только для записи \ No newline at end of file +request-required-property-became-not-write-only: обязательное поле запроса %s перестало быть только для записи diff --git a/data/checker/request_property_discriminator_added_base.yaml b/data/checker/request_property_discriminator_added_base.yaml new file mode 100644 index 00000000..8a880a8e --- /dev/null +++ b/data/checker/request_property_discriminator_added_base.yaml @@ -0,0 +1,51 @@ +openapi: 3.0.0 +info: + title: ACME + version: 1.0.0 + +paths: + /pets: + post: + operationId: updatePets + requestBody: + content: + application/json: + schema: + oneOf: + - $ref: "#/components/schemas/Dog" + - $ref: "#/components/schemas/Cat" + +components: + schemas: + Dog: + type: object + properties: + petType: + type: string + name: + type: string + breed: + type: object + oneOf: + - $ref: "#/components/schemas/Breed1" + - $ref: "#/components/schemas/Breed2" + + Breed1: + type: object + properties: + name: + type: string + + Breed2: + type: object + properties: + name: + type: string + + Cat: + type: object + properties: + petType: + type: string + name: + type: string diff --git a/data/checker/request_property_discriminator_added_property_name_changed.yaml b/data/checker/request_property_discriminator_added_property_name_changed.yaml new file mode 100644 index 00000000..c342174e --- /dev/null +++ b/data/checker/request_property_discriminator_added_property_name_changed.yaml @@ -0,0 +1,61 @@ +openapi: 3.0.0 +info: + title: ACME + version: 1.0.0 + +paths: + /pets: + post: + operationId: updatePets + requestBody: + content: + application/json: + schema: + oneOf: + - $ref: "#/components/schemas/Dog" + - $ref: "#/components/schemas/Cat" + discriminator: + propertyName: petType2 + mapping: + cat: "#/components/schemas/Cat" + dog: "#/components/schemas/Dog" + +components: + schemas: + Dog: + type: object + properties: + petType2: + type: string + name: + type: string + breed: + type: object + oneOf: + - $ref: "#/components/schemas/Breed1" + - $ref: "#/components/schemas/Breed2" + discriminator: + propertyName: name2 + mapping: + breed1: "#/components/schemas/Breed1" + breed2: "#/components/schemas/Breed2" + + Breed1: + type: object + properties: + name2: + type: string + + Breed2: + type: object + properties: + name2: + type: string + + Cat: + type: object + properties: + petType2: + type: string + name: + type: string diff --git a/data/checker/request_property_discriminator_added_revision.yaml b/data/checker/request_property_discriminator_added_revision.yaml new file mode 100644 index 00000000..674d0c9e --- /dev/null +++ b/data/checker/request_property_discriminator_added_revision.yaml @@ -0,0 +1,61 @@ +openapi: 3.0.0 +info: + title: ACME + version: 1.0.0 + +paths: + /pets: + post: + operationId: updatePets + requestBody: + content: + application/json: + schema: + oneOf: + - $ref: "#/components/schemas/Dog" + - $ref: "#/components/schemas/Cat" + discriminator: + propertyName: petType + mapping: + cat: "#/components/schemas/Cat" + dog: "#/components/schemas/Dog" + +components: + schemas: + Dog: + type: object + properties: + petType: + type: string + name: + type: string + breed: + type: object + oneOf: + - $ref: "#/components/schemas/Breed1" + - $ref: "#/components/schemas/Breed2" + discriminator: + propertyName: name + mapping: + breed1: "#/components/schemas/Breed1" + breed2: "#/components/schemas/Breed2" + + Breed1: + type: object + properties: + name: + type: string + + Breed2: + type: object + properties: + name: + type: string + + Cat: + type: object + properties: + petType: + type: string + name: + type: string diff --git a/data/checker/request_property_discriminator_mapping_changed.yaml b/data/checker/request_property_discriminator_mapping_changed.yaml new file mode 100644 index 00000000..cb5051a3 --- /dev/null +++ b/data/checker/request_property_discriminator_mapping_changed.yaml @@ -0,0 +1,67 @@ +openapi: 3.0.0 +info: + title: ACME + version: 1.0.0 + +paths: + /pets: + post: + operationId: updatePets + requestBody: + content: + application/json: + schema: + oneOf: + - $ref: "#/components/schemas/Dog" + - $ref: "#/components/schemas/Cat" + discriminator: + propertyName: petType + mapping: + cats: "#/components/schemas/Cat" + dog: "#/components/schemas/Dog" + +components: + schemas: + Dog: + type: object + properties: + petType: + type: string + name: + type: string + breed: + type: object + oneOf: + - $ref: "#/components/schemas/Breed1" + - $ref: "#/components/schemas/Breed2" + discriminator: + propertyName: name + mapping: + breed1Code: "#/components/schemas/Breed1" + breed2: "#/components/schemas/Breed3" + + Breed1: + type: object + properties: + name: + type: string + + Breed2: + type: object + properties: + name: + type: string + + Breed3: + type: object + properties: + name: + type: string + + Cat: + type: object + properties: + petType: + type: string + name: + type: string 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 diff --git a/data/checker/response_property_discriminator_added_base.yaml b/data/checker/response_property_discriminator_added_base.yaml new file mode 100644 index 00000000..8fcc380b --- /dev/null +++ b/data/checker/response_property_discriminator_added_base.yaml @@ -0,0 +1,52 @@ +openapi: 3.0.0 +info: + title: ACME + version: 1.0.0 + +paths: + /pets: + post: + operationId: updatePets + responses: + "200": + content: + application/json: + schema: + oneOf: + - $ref: "#/components/schemas/Dog" + - $ref: "#/components/schemas/Cat" + +components: + schemas: + Dog: + type: object + properties: + petType: + type: string + name: + type: string + breed: + type: object + oneOf: + - $ref: "#/components/schemas/Breed1" + - $ref: "#/components/schemas/Breed2" + + Breed1: + type: object + properties: + name: + type: string + + Breed2: + type: object + properties: + name: + type: string + + Cat: + type: object + properties: + petType: + type: string + name: + type: string diff --git a/data/checker/response_property_discriminator_added_property_name_changed.yaml b/data/checker/response_property_discriminator_added_property_name_changed.yaml new file mode 100644 index 00000000..3794c87f --- /dev/null +++ b/data/checker/response_property_discriminator_added_property_name_changed.yaml @@ -0,0 +1,62 @@ +openapi: 3.0.0 +info: + title: ACME + version: 1.0.0 + +paths: + /pets: + post: + operationId: updatePets + responses: + "200": + content: + application/json: + schema: + oneOf: + - $ref: "#/components/schemas/Dog" + - $ref: "#/components/schemas/Cat" + discriminator: + propertyName: petType2 + mapping: + cat: "#/components/schemas/Cat" + dog: "#/components/schemas/Dog" + +components: + schemas: + Dog: + type: object + properties: + petType2: + type: string + name: + type: string + breed: + type: object + oneOf: + - $ref: "#/components/schemas/Breed1" + - $ref: "#/components/schemas/Breed2" + discriminator: + propertyName: name2 + mapping: + breed1: "#/components/schemas/Breed1" + breed2: "#/components/schemas/Breed2" + + Breed1: + type: object + properties: + name2: + type: string + + Breed2: + type: object + properties: + name2: + type: string + + Cat: + type: object + properties: + petType2: + type: string + name: + type: string diff --git a/data/checker/response_property_discriminator_added_revision.yaml b/data/checker/response_property_discriminator_added_revision.yaml new file mode 100644 index 00000000..b40b50ab --- /dev/null +++ b/data/checker/response_property_discriminator_added_revision.yaml @@ -0,0 +1,62 @@ +openapi: 3.0.0 +info: + title: ACME + version: 1.0.0 + +paths: + /pets: + post: + operationId: updatePets + responses: + "200": + content: + application/json: + schema: + oneOf: + - $ref: "#/components/schemas/Dog" + - $ref: "#/components/schemas/Cat" + discriminator: + propertyName: petType + mapping: + cat: "#/components/schemas/Cat" + dog: "#/components/schemas/Dog" + +components: + schemas: + Dog: + type: object + properties: + petType: + type: string + name: + type: string + breed: + type: object + oneOf: + - $ref: "#/components/schemas/Breed1" + - $ref: "#/components/schemas/Breed2" + discriminator: + propertyName: name + mapping: + breed1: "#/components/schemas/Breed1" + breed2: "#/components/schemas/Breed2" + + Breed1: + type: object + properties: + name: + type: string + + Breed2: + type: object + properties: + name: + type: string + + Cat: + type: object + properties: + petType: + type: string + name: + type: string diff --git a/data/checker/response_property_discriminator_mapping_changed.yaml b/data/checker/response_property_discriminator_mapping_changed.yaml new file mode 100644 index 00000000..c3883217 --- /dev/null +++ b/data/checker/response_property_discriminator_mapping_changed.yaml @@ -0,0 +1,68 @@ +openapi: 3.0.0 +info: + title: ACME + version: 1.0.0 + +paths: + /pets: + post: + operationId: updatePets + responses: + "200": + content: + application/json: + schema: + oneOf: + - $ref: "#/components/schemas/Dog" + - $ref: "#/components/schemas/Cat" + discriminator: + propertyName: petType + mapping: + cats: "#/components/schemas/Cat" + dog: "#/components/schemas/Dog" + +components: + schemas: + Dog: + type: object + properties: + petType: + type: string + name: + type: string + breed: + type: object + oneOf: + - $ref: "#/components/schemas/Breed1" + - $ref: "#/components/schemas/Breed2" + discriminator: + propertyName: name + mapping: + breed1Code: "#/components/schemas/Breed1" + breed2: "#/components/schemas/Breed3" + + Breed1: + type: object + properties: + name: + type: string + + Breed2: + type: object + properties: + name: + type: string + + Breed3: + type: object + properties: + name: + type: string + + Cat: + type: object + properties: + petType: + type: string + name: + type: string