Skip to content

Commit 4666f2c

Browse files
committed
fix: don't suppress target values when sibling collections are empty
An empty $defs: {} or $vocabulary: {} sibling would assign an empty collection to the reference, blocking fallthrough to Target via the ?? coalescing getter. Only assign when the collection has entries. Ref: #2895
1 parent 4c228f7 commit 4666f2c

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/Microsoft.OpenApi/Models/JsonSchemaReference.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,18 @@ protected override void SetAdditional31MetadataFromMapNode(JsonObject jsonObject
272272

273273
if (jsonObject.TryGetPropertyValue(OpenApiConstants.Vocabulary, out var vocabNode) && vocabNode is JsonObject vocabObj)
274274
{
275-
Vocabulary = new Dictionary<string, bool>();
275+
var vocab = new Dictionary<string, bool>();
276276
foreach (var kvp in vocabObj)
277277
{
278278
if (kvp.Value is JsonValue v && v.TryGetValue<bool>(out var b))
279279
{
280-
Vocabulary[kvp.Key] = b;
280+
vocab[kvp.Key] = b;
281281
}
282282
}
283+
if (vocab.Count > 0)
284+
{
285+
Vocabulary = vocab;
286+
}
283287
}
284288
}
285289
}

src/Microsoft.OpenApi/Reader/V31/OpenApiSchemaDeserializer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,10 @@ public static IOpenApiSchema LoadSchema(JsonNode node, OpenApiDocument hostDocum
471471
context.EndObject();
472472
}
473473
}
474-
result.Reference.Definitions = defs;
474+
if (defs.Count > 0)
475+
{
476+
result.Reference.Definitions = defs;
477+
}
475478
}
476479

477480
return result;

src/Microsoft.OpenApi/Reader/V32/OpenApiSchemaDeserializer.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,10 @@ public static IOpenApiSchema LoadSchema(JsonNode node, OpenApiDocument hostDocum
471471
context.EndObject();
472472
}
473473
}
474-
result.Reference.Definitions = defs;
474+
if (defs.Count > 0)
475+
{
476+
result.Reference.Definitions = defs;
477+
}
475478
}
476479

477480
return result;

0 commit comments

Comments
 (0)