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
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ public void AddedPaths()
var output = x.GetValidationMessagesAsJson();
var raw = JToken.Parse(output);
Assert.Equal(JTokenType.Object, raw.Type);
Assert.Equal("new/added_path.json:31:15", raw["location-new"].Value<string>());
Assert.Equal("paths./api/Operations.post", raw["jsonpath-new"].Value<string>());
Assert.Equal("new/added_path.json:31:15", raw["new"]["location"].Value<string>());
Assert.Equal("paths./api/Operations.post", raw["new"]["path"].Value<string>());
Assert.Null(raw["old"]["location"]);
}

/// <summary>
Expand Down
40 changes: 25 additions & 15 deletions openapi-diff/src/modeler/AutoRest.Swagger/ComparisonMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static string Location(IJsonDocument jsonDoc, JToken jsonToken)
// up cast.
IJsonLineInfo x = jsonToken;
return x == null ?
"" :
null :
$"{ObjectPath.FileNameNorm(jsonDoc.FileName)}:{x.LineNumber}:{x.LinePosition}";
}

Expand All @@ -111,23 +111,33 @@ private static string Location(IJsonDocument jsonDoc, JToken jsonToken)

public string GetValidationMessagesAsJson()
{
var rawMessage = new Dictionary<string, string>
var rawMessage = new JsonComparisonMessage
{
["id"] = Id.ToString(),
["code"] = Code.ToString(),
["message"] = Message,
["jsonref-old"] = OldJsonRef,
["jsonpath-old"] = OldJson()?.Path,
["location-old"] = OldLocation(),
["jsonref-new"] = NewJsonRef,
["jsonpath-new"] = NewJson()?.Path,
["location-new"] = NewLocation(),
["type"] = Severity.ToString(),
["docurl"] = DocUrl.ToString(),
["mode"] = Mode.ToString()
id = Id.ToString(),
code = Code.ToString(),
message = Message,
type = Severity.ToString(),
docurl = DocUrl.ToString(),
mode = Mode.ToString(),
old = new JsonLocation
{
@ref = OldJsonRef,
path = OldJson()?.Path,
location = OldLocation(),
},
@new = new JsonLocation
{
@ref = NewJsonRef,
path = NewJson()?.Path,
location = NewLocation(),
}
};

return JsonConvert.SerializeObject(rawMessage, Formatting.Indented);
return JsonConvert.SerializeObject(
rawMessage,
Formatting.Indented,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }
);
}

public override string ToString()
Expand Down
21 changes: 21 additions & 0 deletions openapi-diff/src/modeler/AutoRest.Swagger/JsonComparisonMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace AutoRest.Swagger
{
sealed class JsonComparisonMessage
{
public string id;

public string code;

public string message;

public JsonLocation old;

public JsonLocation @new;

public string type;

public string docurl;

public string mode;
}
}
11 changes: 11 additions & 0 deletions openapi-diff/src/modeler/AutoRest.Swagger/JsonLocation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace AutoRest.Swagger
{
sealed class JsonLocation
{
public string @ref;

public string path;

public string location;
}
}