Skip to content

Commit a01f21d

Browse files
committed
feat: register schemas with an identifier
1 parent 3f8b2b9 commit a01f21d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Microsoft.OpenApi/Reader/ParseNodes/MapNode.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ public override string GetRaw()
156156
return refNode?.GetScalarValue();
157157
}
158158

159+
public string? GetJsonSchemaIdentifier()
160+
{
161+
if (!_node.TryGetPropertyValue("$id", out JsonNode? idNode))
162+
{
163+
return null;
164+
}
165+
166+
return idNode?.GetScalarValue();
167+
}
168+
159169
public string? GetSummaryValue()
160170
{
161171
if (!_node.TryGetPropertyValue("summary", out JsonNode? summaryNode))

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using Microsoft.OpenApi.Extensions;
@@ -363,6 +363,7 @@ public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocu
363363
var mapNode = node.CheckMapNode(OpenApiConstants.Schema);
364364

365365
var pointer = mapNode.GetReferencePointer();
366+
var identifier = mapNode.GetJsonSchemaIdentifier();
366367

367368
if (pointer != null)
368369
{
@@ -397,6 +398,12 @@ public static IOpenApiSchema LoadSchema(ParseNode node, OpenApiDocument hostDocu
397398
schema.Extensions.Remove(OpenApiConstants.NullableExtension);
398399
}
399400

401+
if (identifier is not null && hostDocument.Workspace is not null)
402+
{
403+
// register the schema in our registry using the identifer's URL
404+
hostDocument.Workspace.RegisterComponentForDocument(hostDocument, schema, identifier);
405+
}
406+
400407
return schema;
401408
}
402409
}

0 commit comments

Comments
 (0)