microsoft / microsoft/OpenAPI.NET

OpenApiYamlReader.Read inconsistent behavior for errors

Open
#3,056 1 comment 1 reaction 2 assignees View on GitHub

@baywet is already working on this.

Since Sep 10, 2026.

  • #3078 by @copilot-swe-agent — open
Dominant language
C#
Stars
1.6k
Forks
286
Avg merge
6h 38m
Merged PRs (30d)
35

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.