Skip to content

Commit 5984798

Browse files
committed
Initialize a diagnostics object in the constructor and use it to append the exceptions caught
1 parent 40d0c97 commit 5984798

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/Microsoft.OpenApi.Readers/V2/OpenApiV2VersionService.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ namespace Microsoft.OpenApi.Readers.V2
2020
/// </summary>
2121
internal class OpenApiV2VersionService : IOpenApiVersionService
2222
{
23+
public OpenApiDiagnostic Diagnostic { get; }
24+
25+
/// <summary>
26+
/// Create Parsing Context
27+
/// </summary>
28+
/// <param name="diagnostic">Provide instance for diagnotic object for collecting and accessing information about the parsing.</param>
29+
public OpenApiV2VersionService(OpenApiDiagnostic diagnostic)
30+
{
31+
Diagnostic = diagnostic;
32+
}
33+
2334
private IDictionary<Type, Func<ParseNode, object>> _loaders = new Dictionary<Type, Func<ParseNode, object>>
2435
{
2536
[typeof(IOpenApiAny)] = OpenApiV2Deserializer.LoadAny,
@@ -154,7 +165,15 @@ public OpenApiReference ConvertToOpenApiReference(string reference, ReferenceTyp
154165
if (reference.StartsWith("#"))
155166
{
156167
// "$ref": "#/definitions/Pet"
157-
return ParseLocalReference(segments[1]);
168+
try
169+
{
170+
return ParseLocalReference(segments[1]);
171+
}
172+
catch (OpenApiException ex)
173+
{
174+
Diagnostic.Errors.Add(new OpenApiError(ex));
175+
return null;
176+
}
158177
}
159178

160179
// $ref: externalSource.yaml#/Pet

src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ namespace Microsoft.OpenApi.Readers.V3
1919
/// </summary>
2020
internal class OpenApiV3VersionService : IOpenApiVersionService
2121
{
22+
public OpenApiDiagnostic Diagnostic { get; }
23+
24+
/// <summary>
25+
/// Create Parsing Context
26+
/// </summary>
27+
/// <param name="diagnostic">Provide instance for diagnotic object for collecting and accessing information about the parsing.</param>
28+
public OpenApiV3VersionService(OpenApiDiagnostic diagnostic)
29+
{
30+
Diagnostic = diagnostic;
31+
}
32+
2233
private IDictionary<Type, Func<ParseNode, object>> _loaders = new Dictionary<Type, Func<ParseNode, object>>
2334
{
2435
[typeof(IOpenApiAny)] = OpenApiV3Deserializer.LoadAny,
@@ -92,8 +103,9 @@ public OpenApiReference ConvertToOpenApiReference(
92103
{
93104
return ParseLocalReference(segments[1]);
94105
}
95-
catch (OpenApiException)
106+
catch (OpenApiException ex)
96107
{
108+
Diagnostic.Errors.Add(new OpenApiError(ex));
97109
return null;
98110
}
99111
}

0 commit comments

Comments
 (0)