diff --git a/openapi-diff/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/new/type_added.json b/openapi-diff/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/new/type_added.json new file mode 100644 index 00000000..21c14932 --- /dev/null +++ b/openapi-diff/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/new/type_added.json @@ -0,0 +1,48 @@ +{ + "swagger": 2.0, + "info": { + "title": "type_changed", + "version": "1.0" + }, + "host": "localhost:8000", + "schemes": [ "http", "https" ], + "consumes": [ "text/plain", "text/json" ], + "produces": [ "text/plain" ], + "paths": { + "/api/Parameters": { + "put": { + "tag": [ "Parameters" ], + "operationId": "Parameters_Put", + "produces": [ + "text/plain" + ], + "parameters": [ + { + "name": "database", + "in": "body", + "required": true, + "type": "object", + "schema": { "$ref": "#/definitions/Database" } + } + ] + } + } + }, + "definitions": { + "Database": { + "properties": { + "a": { + "type": "integer", + "readOnly": true, + "description": "This is a system generated property.\nThe _rid value is empty for this operation." + }, + "b": { + "type": "integer", + "readOnly": true, + "default": 0, + "description": "This property shows the number of databases returned." + } + } + } + } +} diff --git a/openapi-diff/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/old/type_added.json b/openapi-diff/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/old/type_added.json new file mode 100644 index 00000000..f41619fb --- /dev/null +++ b/openapi-diff/src/modeler/AutoRest.Swagger.Tests/Resource/Swagger/old/type_added.json @@ -0,0 +1,47 @@ +{ + "swagger": 2.0, + "info": { + "title": "type_changed", + "version": "1.0" + }, + "host": "localhost:8000", + "schemes": [ "http", "https" ], + "consumes": [ "text/plain", "text/json" ], + "produces": [ "text/plain" ], + "paths": { + "/api/Parameters": { + "put": { + "tag": [ "Parameters" ], + "operationId": "Parameters_Put", + "produces": [ + "text/plain" + ], + "parameters": [ + { + "name": "database", + "in": "body", + "required": true, + "type": "object", + "schema": { "$ref": "#/definitions/Database" } + } + ] + } + } + }, + "definitions": { + "Database": { + "properties": { + "a": { + "readOnly": true, + "description": "This is a system generated property.\nThe _rid value is empty for this operation." + }, + "b": { + "type": "integer", + "readOnly": true, + "default": 0, + "description": "This property shows the number of databases returned." + } + } + } + } +} diff --git a/openapi-diff/src/modeler/AutoRest.Swagger.Tests/SwaggerModelerCompareTests.cs b/openapi-diff/src/modeler/AutoRest.Swagger.Tests/SwaggerModelerCompareTests.cs index 46b05de7..9046d0a3 100644 --- a/openapi-diff/src/modeler/AutoRest.Swagger.Tests/SwaggerModelerCompareTests.cs +++ b/openapi-diff/src/modeler/AutoRest.Swagger.Tests/SwaggerModelerCompareTests.cs @@ -150,6 +150,17 @@ public void PropertyTypeChanged() Assert.Equal("new/type_changed.json#/definitions/Database/properties/a", error.NewJsonRef); } + /// + /// Verifies that if you add the type to a schema property, it's allowed through. + /// + [Fact] + public void PropertyTypeAdded() + { + var messages = CompareSwagger("type_added.json").ToArray(); + var missing = messages.Where(m => m.Id == ComparisonMessages.TypeChanged.Id); + Assert.Empty(missing); + } + /// /// Verifies that if you change the type format of a schema property, it's caught. /// diff --git a/openapi-diff/src/modeler/AutoRest.Swagger/Model/SwaggerObject.cs b/openapi-diff/src/modeler/AutoRest.Swagger/Model/SwaggerObject.cs index e6e5618f..7cc62cff 100644 --- a/openapi-diff/src/modeler/AutoRest.Swagger/Model/SwaggerObject.cs +++ b/openapi-diff/src/modeler/AutoRest.Swagger/Model/SwaggerObject.cs @@ -122,9 +122,9 @@ T previous } } - // Are the types the same? + // If the type field was removed or the types don't match - if (prior.Type.HasValue != Type.HasValue || (Type.HasValue && prior.Type.Value != Type.Value)) + if ((prior.Type.HasValue && !Type.HasValue) || (Type.HasValue && prior.Type.HasValue && prior.Type.Value != Type.Value)) { context.LogBreakingChange(ComparisonMessages.TypeChanged, Type.HasValue ? Type.Value.ToString().ToLower() : "",