[BUG][csharp][restsharp] throwOnAnyError: oneOf/anyOf deserialization failure on 2xx escapes as InvalidDataException instead of ApiException
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache 第 500 行附近开始,追踪 FromJson 调用以及现有的 throwOnAnyError 处理逻辑。使用生成的 RestSharp 客户端进行复现:响应为无法匹配任何变体的 oneOf 或 anyOf,且状态为 200。完成标准是解析失败以 ApiException 的形式传递到调用方,其中包含状态 200、原始响应正文、响应头,以及作为内部异常的 InvalidDataException。
由索引模型根据 Issue 内容生成。
描述
Description
With throwOnAnyError=true the generated ApiClient promises that every failure surfaces as ApiException. For a 2xx response whose body matches none of the oneOf/anyOf variants, FromJson throws InvalidDataException after the ErrorException guard has already passed, so the raw exception reaches the caller without status code, body or headers.
openapi-generator version
master (after #25217)
Steps to reproduce
- Generate a csharp client with
--library restsharp --additional-properties throwOnAnyError=truefrom a spec where an operation returns aoneOfmodel. - Call that operation against a server that returns 200 with a body matching no variant.
- Observe
InvalidDataExceptioninstead ofApiException.
Expected behaviour
ApiException with ErrorCode = 200, ErrorContent = raw body, Headers populated, and the InvalidDataException as InnerException.
Original findings
P2: The
FromJsoncall below can throwInvalidDataExceptionfor a 2xx body that matches no oneOf/anyOf schema, after this check has passed; the raw exception escapes instead of the promisedApiException. Wrap that parse failure with the response status, content, and headers.Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache, line 500: <comment>The `FromJson` call below can throw `InvalidDataException` for a 2xx body that matches no oneOf/anyOf schema, after this check has passed; the raw exception escapes instead of the promised `ApiException`. Wrap that parse failure with the response status, content, and headers.</comment> <file context> @@ -495,6 +494,14 @@ namespace {{packageName}}.Client + {{#throwOnAnyError}} + + // 4xx/5xx also carry ErrorException; those go through ExceptionFactory so the body is kept + if (response.ErrorException != null && (int)response.StatusCode < 400) + { + throw new ApiException((int)response.StatusCode, string.Format("Error calling {0}: {1}", request.Resource, response.ErrorMessage), response.Content, ToApiResponse(response).Headers); </file context>
Originally posted by @cubic-dev-ai[bot] in #25217
- 主要语言
- Java
- 星标
- 26.8k
- 派生
- 7.7k
- 平均合并
- 1 天 12 小时
- 30 天内合并 PR
- 141
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
OpenAPITools/openapi-generator 的其他 Issue
-
[BUG] ExampleGenerator returns the string "{}" (or null) for `type: object` schemas without `properties`可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
OpenAPITools/openapi-generator#25237 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
OpenAPITools/openapi-generator#25236 ·
维护者通常 1 天内回复
-
[BUG] OpenApiEvaluator reports "default value not in enum" for numerically equal values with different scale (e.g. 1.5 and 1.50)可能已有人在做 @mohitduhan19 于 1 天前认领。 未关闭Issue: Bug
难度 2/5 1-3 小时 新手友好度 78/100
OpenAPITools/openapi-generator#25233 ·
维护者通常 1 天内回复
-
[BUG] OpenApiEvaluator emits "Unused model" warnings even when recommendations are disabled可能已有人在做 @mohitduhan19 于 1 天前认领。 未关闭Issue: Bug
难度 2/5 1-3 小时 新手友好度 82/100
OpenAPITools/openapi-generator#25232 ·
维护者通常 1 天内回复
-
[BUG][KOTLIN] multiplatform/jvm-ktor: `DELETE` without `requestBody` sends `"Content-Type: application/json"` with an empty body可能已有人在做 @mohitduhan19 于 1 天前认领。 未关闭Issue: Bug
难度 2/5 1-3 小时 新手友好度 78/100
OpenAPITools/openapi-generator#25223 ·
维护者通常 1 天内回复
查看 OpenAPITools/openapi-generator 的全部 Issue
相似的 Issue
-
RRateLimiter acquire methods accept negative permits and raise available permits above the rate.可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 4 天内回复
-
难度 1/5 1 小时以内 新手友好度 75/100
krahets/hello-algo#1993 ·
-
难度 2/5 1-3 小时 新手友好度 62/100
NationalSecurityAgency/ghidra#9884 ·
维护者通常 2 天内回复
-
Status: Pending Review Type: Feature Request
难度 1/5 1 小时以内 新手友好度 82/100
OpenRefine/OpenRefine#8019 ·
维护者通常 1 天内回复
-
[TEMP] pin maven version to 3.9.x可能已有人在做 @petrenyi-mark 今天认领。 未关闭
难度 2/5 1 小时以内 新手友好度 62/100