Skip to content

Commit d4b6e8d

Browse files
committed
Split host document resolution from Json Schema ref resolution
1 parent b9d5360 commit d4b6e8d

File tree

3 files changed

+39
-22
lines changed

3 files changed

+39
-22
lines changed

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 3 additions & 5 deletions
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 System;
@@ -446,14 +446,12 @@ private static void WriteHostInfoV2(IOpenApiWriter writer, IList<OpenApiServer>
446446

447447
/// <summary>
448448
/// Walks the OpenApiDocument and sets the host document for all IOpenApiReferenceable objects
449-
/// and resolves JsonSchema references
450449
/// </summary>
451-
public IEnumerable<OpenApiError> ResolveReferences()
450+
public void ResolveHostDocument()
452451
{
453-
var resolver = new ReferenceResolver(this);
452+
var resolver = new HostDocumentResolver(this);
454453
var walker = new OpenApiWalker(resolver);
455454
walker.Walk(this);
456-
return resolver.Errors;
457455
}
458456

459457
/// <summary>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using Microsoft.OpenApi.Interfaces;
5+
using Microsoft.OpenApi.Models;
6+
7+
namespace Microsoft.OpenApi.Services
8+
{
9+
/// <summary>
10+
/// This class is used to walk an OpenApiDocument and sets the host document of OpenApiReferences.
11+
/// </summary>
12+
internal class HostDocumentResolver : OpenApiVisitorBase
13+
{
14+
private readonly OpenApiDocument _currentDocument;
15+
16+
public HostDocumentResolver(OpenApiDocument currentDocument)
17+
{
18+
_currentDocument = currentDocument;
19+
}
20+
21+
/// <summary>
22+
/// Visits the referenceable element in the host document
23+
/// </summary>
24+
/// <param name="referenceable">The referenceable element in the doc.</param>
25+
public override void Visit(IOpenApiReferenceable referenceable)
26+
{
27+
if (referenceable.Reference != null)
28+
{
29+
referenceable.Reference.HostDocument = _currentDocument;
30+
}
31+
}
32+
}
33+
}

src/Microsoft.OpenApi/Services/ReferenceResolver.cs renamed to src/Microsoft.OpenApi/Services/JsonSchemaReferenceResolver.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@
66
using Json.Schema;
77
using Microsoft.OpenApi.Exceptions;
88
using System.Linq;
9-
using Microsoft.OpenApi.Interfaces;
109
using Microsoft.OpenApi.Models;
1110
using Microsoft.OpenApi.Extensions;
1211

1312
namespace Microsoft.OpenApi.Services
1413
{
1514
/// <summary>
16-
/// This class is used to wallk an OpenApiDocument and sets the host document of OpenApiReferences
17-
/// and resolves JsonSchema references.
15+
/// This class is used to walk an OpenApiDocument and resolves JsonSchema references.
1816
/// </summary>
19-
internal class ReferenceResolver : OpenApiVisitorBase
17+
internal class JsonSchemaReferenceResolver : OpenApiVisitorBase
2018
{
2119
private readonly OpenApiDocument _currentDocument;
2220
private readonly List<OpenApiError> _errors = new();
2321

24-
public ReferenceResolver(OpenApiDocument currentDocument)
22+
public JsonSchemaReferenceResolver(OpenApiDocument currentDocument)
2523
{
2624
_currentDocument = currentDocument;
2725
}
@@ -31,18 +29,6 @@ public ReferenceResolver(OpenApiDocument currentDocument)
3129
/// </summary>
3230
public IEnumerable<OpenApiError> Errors => _errors;
3331

34-
/// <summary>
35-
/// Visits the referenceable element in the host document
36-
/// </summary>
37-
/// <param name="referenceable">The referenceable element in the doc.</param>
38-
public override void Visit(IOpenApiReferenceable referenceable)
39-
{
40-
if (referenceable.Reference != null)
41-
{
42-
referenceable.Reference.HostDocument = _currentDocument;
43-
}
44-
}
45-
4632
/// <summary>
4733
/// Resolves schemas in components
4834
/// </summary>

0 commit comments

Comments
 (0)