microsoft / microsoft/OpenAPI.NET

OpenApiYamlReader.Read inconsistent behavior for errors

未關閉
#3,056 1 則留言 1 個 reaction 已指派 2 人 在 GitHub 檢視

@baywet 已經在處理了。

開始於 2026年9月10日。

  • #3078 來自 @copilot-swe-agent —— 未關閉
主要語言
C#
星號
1.6k
分支
286
平均合併
6 小時 38 分鐘
30 天內合併 PR
35

描述

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.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。