Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.9.7 Released on 2022-08-15

- change rule 'TypeChanged' to 'Info' if adding 'type:object' to an schema with "properties".

## 0.9.6 Released on 2022-06-09

- using autorest v3.6.1'.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"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": "object",
"readOnly": true,
"properties": {
"b": {
"type": "string",
"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,53 @@
{
"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,
"properties": {
"b": {
"type": "string",
"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,21 @@ public void PropertyTypeChanged()
Assert.Equal("new/type_changed.json#/definitions/Database/properties/a", error.NewJsonRef);
}

/// <summary>
/// Verifies that if adding a 'type:object' to a schema with 'properties', it's not error.
/// </summary>
[Fact]
public void TypeObjectChanged()
{
var messages = CompareSwagger("type_changed_01.json").ToArray();
var missing = messages.Where(m => m.Id == ComparisonMessages.TypeChanged.Id);
Assert.NotEmpty(missing);
var error = missing.Where(err => err.NewJsonRef.StartsWith("new/type_changed_01.json#/definitions/")).FirstOrDefault();
Assert.NotNull(error);
Assert.Equal(Category.Info, error.Severity);
Assert.Equal("new/type_changed_01.json#/definitions/Database/properties/a", error.NewJsonRef);
}

/// <summary>
/// Verifies that if you change the type format of a schema property, it's caught.
/// </summary>
Expand Down
18 changes: 16 additions & 2 deletions openapi-diff/src/modeler/AutoRest.Swagger/Model/SwaggerObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,26 @@ T previous

// Are the types the same?

if (prior.Type.HasValue != Type.HasValue || (Type.HasValue && prior.Type.Value != Type.Value))
if ((Type.HasValue && prior.Type.HasValue && prior.Type.Value != Type.Value))
{
context.LogBreakingChange(ComparisonMessages.TypeChanged,
context.LogError(ComparisonMessages.TypeChanged,
Type.HasValue ? Type.Value.ToString().ToLower() : "",
prior.Type.HasValue ? prior.Type.Value.ToString().ToLower() : "");
}
var isObject = Type.HasValue && Type.Value == DataType.Object && (this is Schema) ? (this as Schema).Properties != null : false;
if (prior.Type.HasValue != Type.HasValue) {
if (!prior.Type.HasValue && Type.HasValue && isObject)
{
context.LogInfo(ComparisonMessages.TypeChanged,
Type.HasValue ? Type.Value.ToString().ToLower() : "",
prior.Type.HasValue ? prior.Type.Value.ToString().ToLower() : "");
}
else {
context.LogError(ComparisonMessages.TypeChanged,
Type.HasValue ? Type.Value.ToString().ToLower() : "",
prior.Type.HasValue ? prior.Type.Value.ToString().ToLower() : "");
}
}

// What about the formats?

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure/oad",
"version": "0.9.6",
"version": "0.9.7",
"author": {
"name": "Microsoft Corporation",
"email": "azsdkteam@microsoft.com",
Expand Down