microsoft / microsoft/OpenAPI.NET
OpenApiYamlReader.Read inconsistent behavior for errors
Offen
- Vorherrschende Sprache
- C#
- Sterne
- 1.6k
- Forks
- 286
- Ø Merge
- 6 Std. 38 Min.
- Gemergte PRs (30 T.)
- 35
Beschreibung
Describe the bug
OpenApiYamlReader.Read throws and exception in some error cases and returns a ReadResult in others. I expect it to always return a ReadResult. A ReadResult is already something that can describe a failure.
For instance, given an empty document:
using var stream = new MemoryStream();
new OpenApiYamlReader().Read(stream, new Uri("https://example.com/"), new OpenApiReaderSettings());
It throws:
System.InvalidOperationException : No documents found in the YAML stream.
at Microsoft.OpenApi.YamlReader.OpenApiYamlReader.LoadJsonNodesFromYamlDocument(TextReader input)
at Microsoft.OpenApi.YamlReader.OpenApiYamlReader.Read(MemoryStream input, Uri location, OpenApiReaderSettings settings)
I expected it it return a ReadResult describing the error.
OpenApi File To Reproduce
An empty file.
Expected behavior
It returns a ReadResult with Document = null and a Diagnostic describing the problem.
Alternatively, when the choice between throwing an exception or returning a ReadResult is by design, this should be documented.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Bewertung
Dieses Issue wurde noch nicht bewertet.