Skip to content

Commit f9f1a75

Browse files
committed
Address the issue when $ref is an object used in schema, instead of being a real reference.
1 parent edaf35c commit f9f1a75

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

openapi-diff/src/core/OpenApiDiff.Core/Logging/ObjectPath.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,23 @@ private static JToken FromObject(JObject o, string name)
7676
{
7777
return null;
7878
}
79+
7980
var @ref = o["$ref"];
80-
var unrefed = @ref != null ? ParseRef(@ref.Value<string>()).CompletePath(o.Root).Last().token : o;
81-
return unrefed[name];
81+
82+
// Handle $ref resolution based on its type
83+
if (@ref != null && @ref.Type == JTokenType.String)
84+
{
85+
// Case 1: $ref is a string reference (e.g., "#/definitions/FieldType")
86+
// Resolve the reference by parsing the path and following it to the target
87+
var unrefed = ParseRef(@ref.Value<string>()).CompletePath(o.Root).Last().token;
88+
return unrefed[name];
89+
}
90+
else
91+
{
92+
// Case 2: $ref is not a string (e.g., a JSON object defining a schema)
93+
// or $ref doesn't exist - use the current object directly
94+
return o[name];
95+
}
8296
}
8397

8498
private static IEnumerable<(JToken token, string name)> CompletePath(IEnumerable<Func<JToken, string>> path, JToken token)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@azure/oad",
3-
"version": "0.12.2",
3+
"version": "0.12.3",
44
"author": {
55
"name": "Microsoft Corporation",
66
"email": "azsdkteam@microsoft.com",

0 commit comments

Comments
 (0)