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

Allow type addition to properties without breaking #168

Closed
Closed
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
Original file line number Diff line number Diff line change
@@ -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."
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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."
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ public void PropertyTypeChanged()
Assert.Equal("new/type_changed.json#/definitions/Database/properties/a", error.NewJsonRef);
}

/// <summary>
/// Verifies that if you add the type to a schema property, it's allowed through.
/// </summary>
[Fact]
public void PropertyTypeAdded()
{
var messages = CompareSwagger("type_added.json").ToArray();
var missing = messages.Where(m => m.Id == ComparisonMessages.TypeChanged.Id);
Assert.Empty(missing);
}

/// <summary>
/// Verifies that if you change the type format of a schema property, it's caught.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() : "",
Expand Down