microsoft / microsoft/OpenAPI.NET
OpenApiYamlReader.Read inconsistent behavior for errors
Abierto
- Lenguaje dominante
- C#
- Estrellas
- 1.6k
- Forks
- 286
- Merge medio
- 6 h 38 min
- PR fusionados (30 d)
- 35
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.