Skip to content

Commit 23d99b9

Browse files
Copilotbaywet
andauthored
fix(reader): return diagnostics for empty factory inputs
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
1 parent a350880 commit 23d99b9

5 files changed

Lines changed: 28 additions & 69 deletions

File tree

src/Microsoft.OpenApi.YamlReader/OpenApiYamlReader.cs

Lines changed: 4 additions & 7 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;
@@ -59,9 +59,8 @@ public OpenApiYamlReader(OpenApiYamlReaderSettings settings)
5959

6060
/// <inheritdoc/>
6161
/// <remarks>
62-
/// OpenAPI semantic errors are returned in the <see cref="ReadResult.Diagnostic"/>.
62+
/// OpenAPI semantic and parser errors are returned in the <see cref="ReadResult.Diagnostic"/>.
6363
/// </remarks>
64-
/// <exception cref="OpenApiReaderException">Thrown when syntax-level YAML errors are detected before a <see cref="ReadResult"/> is created.</exception>
6564
public async Task<ReadResult> ReadAsync(Stream input,
6665
Uri location,
6766
OpenApiReaderSettings settings,
@@ -100,9 +99,8 @@ await CopyToMemoryStreamAsync(
10099

101100
/// <inheritdoc/>
102101
/// <remarks>
103-
/// OpenAPI semantic errors are returned in the <see cref="ReadResult.Diagnostic"/>.
102+
/// OpenAPI semantic and parser errors are returned in the <see cref="ReadResult.Diagnostic"/>.
104103
/// </remarks>
105-
/// <exception cref="OpenApiReaderException">Thrown when syntax-level YAML errors are detected before a <see cref="ReadResult"/> is created.</exception>
106104
public ReadResult Read(MemoryStream input,
107105
Uri location,
108106
OpenApiReaderSettings settings)
@@ -203,9 +201,8 @@ public static ReadResult Read(JsonNode jsonNode, Uri location, OpenApiReaderSett
203201

204202
/// <inheritdoc/>
205203
/// <remarks>
206-
/// OpenAPI semantic errors are returned in the <paramref name="diagnostic"/>.
204+
/// OpenAPI semantic and parser errors are returned in the <paramref name="diagnostic"/>.
207205
/// </remarks>
208-
/// <exception cref="OpenApiReaderException">Thrown when syntax-level YAML errors are detected before a fragment is created.</exception>
209206
public T? ReadFragment<T>(MemoryStream input,
210207
OpenApiSpecVersion version,
211208
OpenApiDocument openApiDocument,

src/Microsoft.OpenApi/Interfaces/IOpenApiReader.cs

Lines changed: 4 additions & 10 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;
@@ -23,10 +23,8 @@ public interface IOpenApiReader
2323
/// <param name="cancellationToken">Propagates notification that an operation should be cancelled.</param>
2424
/// <returns></returns>
2525
/// <remarks>
26-
/// OpenAPI semantic errors are returned in the <see cref="ReadResult.Diagnostic"/>.
26+
/// OpenAPI semantic and parser errors are returned in the <see cref="ReadResult.Diagnostic"/>.
2727
/// </remarks>
28-
/// <exception cref="System.Text.Json.JsonException">Thrown when syntax-level JSON errors are detected before a <see cref="ReadResult"/> is created.</exception>
29-
/// <exception cref="OpenApiReaderException">Thrown when syntax-level YAML errors are detected before a <see cref="ReadResult"/> is created.</exception>
3028
Task<ReadResult> ReadAsync(Stream input, Uri location, OpenApiReaderSettings settings, CancellationToken cancellationToken = default);
3129

3230
/// <summary>
@@ -37,10 +35,8 @@ public interface IOpenApiReader
3735
/// <param name="settings"></param>
3836
/// <returns></returns>
3937
/// <remarks>
40-
/// OpenAPI semantic errors are returned in the <see cref="ReadResult.Diagnostic"/>.
38+
/// OpenAPI semantic and parser errors are returned in the <see cref="ReadResult.Diagnostic"/>.
4139
/// </remarks>
42-
/// <exception cref="System.Text.Json.JsonException">Thrown when syntax-level JSON errors are detected before a <see cref="ReadResult"/> is created.</exception>
43-
/// <exception cref="OpenApiReaderException">Thrown when syntax-level YAML errors are detected before a <see cref="ReadResult"/> is created.</exception>
4440
ReadResult Read(MemoryStream input, Uri location, OpenApiReaderSettings settings);
4541

4642
/// <summary>
@@ -53,10 +49,8 @@ public interface IOpenApiReader
5349
/// <param name="settings">The OpenApiReader settings.</param>
5450
/// <returns>Instance of newly created IOpenApiElement.</returns>
5551
/// <remarks>
56-
/// OpenAPI semantic errors are returned in the <paramref name="diagnostic"/>.
52+
/// OpenAPI semantic and parser errors are returned in the <paramref name="diagnostic"/>.
5753
/// </remarks>
58-
/// <exception cref="System.Text.Json.JsonException">Thrown when syntax-level JSON errors are detected before a fragment is created.</exception>
59-
/// <exception cref="OpenApiReaderException">Thrown when syntax-level YAML errors are detected before a fragment is created.</exception>
6054
T? ReadFragment<T>(MemoryStream input, OpenApiSpecVersion version, OpenApiDocument openApiDocument, out OpenApiDiagnostic diagnostic, OpenApiReaderSettings? settings = null) where T : IOpenApiElement;
6155
}
6256
}

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 5 additions & 13 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;
@@ -733,10 +733,8 @@ private static bool TryGetPlainNameFragment(string reference, out string fragmen
733733
/// <param name="settings">The OpenApi reader settings.</param>
734734
/// <returns></returns>
735735
/// <remarks>
736-
/// OpenAPI semantic errors are returned in the <see cref="ReadResult.Diagnostic"/>.
736+
/// OpenAPI semantic and parser errors are returned in the <see cref="ReadResult.Diagnostic"/>.
737737
/// </remarks>
738-
/// <exception cref="System.Text.Json.JsonException">Thrown when syntax-level JSON errors are detected before a <see cref="ReadResult"/> is created.</exception>
739-
/// <exception cref="OpenApiReaderException">Thrown when syntax-level YAML errors are detected before a <see cref="ReadResult"/> is created.</exception>
740738
public static ReadResult Load(MemoryStream stream,
741739
string? format = null,
742740
OpenApiReaderSettings? settings = null)
@@ -752,10 +750,8 @@ public static ReadResult Load(MemoryStream stream,
752750
/// <param name="token">The cancellation token</param>
753751
/// <returns></returns>
754752
/// <remarks>
755-
/// OpenAPI semantic errors are returned in the <see cref="ReadResult.Diagnostic"/>.
753+
/// OpenAPI semantic and parser errors are returned in the <see cref="ReadResult.Diagnostic"/>.
756754
/// </remarks>
757-
/// <exception cref="System.Text.Json.JsonException">Thrown when syntax-level JSON errors are detected before a <see cref="ReadResult"/> is created.</exception>
758-
/// <exception cref="OpenApiReaderException">Thrown when syntax-level YAML errors are detected before a <see cref="ReadResult"/> is created.</exception>
759755
public static async Task<ReadResult> LoadAsync(string url, OpenApiReaderSettings? settings = null, CancellationToken token = default)
760756
{
761757
return await OpenApiModelFactory.LoadAsync(url, settings, token).ConfigureAwait(false);
@@ -770,10 +766,8 @@ public static async Task<ReadResult> LoadAsync(string url, OpenApiReaderSettings
770766
/// <param name="cancellationToken">Propagates information about operation cancelling.</param>
771767
/// <returns></returns>
772768
/// <remarks>
773-
/// OpenAPI semantic errors are returned in the <see cref="ReadResult.Diagnostic"/>.
769+
/// OpenAPI semantic and parser errors are returned in the <see cref="ReadResult.Diagnostic"/>.
774770
/// </remarks>
775-
/// <exception cref="System.Text.Json.JsonException">Thrown when syntax-level JSON errors are detected before a <see cref="ReadResult"/> is created.</exception>
776-
/// <exception cref="OpenApiReaderException">Thrown when syntax-level YAML errors are detected before a <see cref="ReadResult"/> is created.</exception>
777771
public static async Task<ReadResult> LoadAsync(Stream stream, string? format = null, OpenApiReaderSettings? settings = null, CancellationToken cancellationToken = default)
778772
{
779773
return await OpenApiModelFactory.LoadAsync(stream, format, settings, cancellationToken).ConfigureAwait(false);
@@ -788,10 +782,8 @@ public static async Task<ReadResult> LoadAsync(Stream stream, string? format = n
788782
/// <param name="settings"></param>
789783
/// <returns></returns>
790784
/// <remarks>
791-
/// OpenAPI semantic errors are returned in the <see cref="ReadResult.Diagnostic"/>.
785+
/// OpenAPI semantic and parser errors are returned in the <see cref="ReadResult.Diagnostic"/>.
792786
/// </remarks>
793-
/// <exception cref="System.Text.Json.JsonException">Thrown when syntax-level JSON errors are detected before a <see cref="ReadResult"/> is created.</exception>
794-
/// <exception cref="OpenApiReaderException">Thrown when syntax-level YAML errors are detected before a <see cref="ReadResult"/> is created.</exception>
795787
public static ReadResult Parse(string input,
796788
string? format = null,
797789
OpenApiReaderSettings? settings = null)

src/Microsoft.OpenApi/Reader/OpenApiJsonReader.cs

Lines changed: 4 additions & 7 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;
@@ -24,9 +24,8 @@ public class OpenApiJsonReader : IOpenApiReader
2424
/// <param name="settings">The Reader settings to be used during parsing.</param>
2525
/// <returns></returns>
2626
/// <remarks>
27-
/// OpenAPI semantic errors are returned in the <see cref="ReadResult.Diagnostic"/>.
27+
/// OpenAPI semantic and parser errors are returned in the <see cref="ReadResult.Diagnostic"/>.
2828
/// </remarks>
29-
/// <exception cref="System.Text.Json.JsonException">Thrown when syntax-level JSON errors are detected before a <see cref="ReadResult"/> is created.</exception>
3029
public ReadResult Read(MemoryStream input,
3130
Uri location,
3231
OpenApiReaderSettings settings)
@@ -128,9 +127,8 @@ public ReadResult Read(JsonNode jsonNode,
128127
/// <param name="cancellationToken">Propagates notifications that operations should be cancelled.</param>
129128
/// <returns></returns>
130129
/// <remarks>
131-
/// OpenAPI semantic errors are returned in the <see cref="ReadResult.Diagnostic"/>.
130+
/// OpenAPI semantic and parser errors are returned in the <see cref="ReadResult.Diagnostic"/>.
132131
/// </remarks>
133-
/// <exception cref="System.Text.Json.JsonException">Thrown when syntax-level JSON errors are detected before a <see cref="ReadResult"/> is created.</exception>
134132
public async Task<ReadResult> ReadAsync(Stream input,
135133
Uri location,
136134
OpenApiReaderSettings settings,
@@ -164,9 +162,8 @@ public async Task<ReadResult> ReadAsync(Stream input,
164162

165163
/// <inheritdoc/>
166164
/// <remarks>
167-
/// OpenAPI semantic errors are returned in the <paramref name="diagnostic"/>.
165+
/// OpenAPI semantic and parser errors are returned in the <paramref name="diagnostic"/>.
168166
/// </remarks>
169-
/// <exception cref="System.Text.Json.JsonException">Thrown when syntax-level JSON errors are detected before a fragment is created.</exception>
170167
public T? ReadFragment<T>(MemoryStream input,
171168
OpenApiSpecVersion version,
172169
OpenApiDocument openApiDocument,

0 commit comments

Comments
 (0)