[BUG][csharp][restsharp] throwOnAnyError: oneOf/anyOf deserialization failure on 2xx escapes as InvalidDataException instead of ApiException
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 65/100
Hướng nghiên cứu
Bắt đầu tại modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache gần dòng 500 và lần theo lời gọi FromJson cùng cách xử lý throwOnAnyError hiện có. Tái hiện lỗi bằng một RestSharp client được tạo với phản hồi oneOf hoặc anyOf không khớp với biến thể nào và một phản hồi 200. Hoàn tất khi lỗi phân tích đến được bên gọi dưới dạng ApiException chứa status 200, nội dung thô, headers và InvalidDataException là ngoại lệ bên trong.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Java
- Star
- 26.8k
- Fork
- 7.7k
- Merge trung bình
- 1 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 145
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của OpenAPITools/openapi-generator
-
[BUG][RUST] chrono date-time path/query/header params are not serialized as RFC 3339Có thể đã có người làm @teovillanueva đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
OpenAPITools/openapi-generator#25297 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG][RUST] Reqwest - encoding of spaces in path parametersCó thể đã có người làm @GlenWright đã nhận 5 ngày trước. Đang mởIssue: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
OpenAPITools/openapi-generator#25257 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OpenAPITools/openapi-generator#25237 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] OpenApiEvaluator reports "default value not in enum" for numerically equal values with different scale (e.g. 1.5 and 1.50)Có thể đã có người làm @mohitduhan19 đã nhận 6 ngày trước. Đang mởIssue: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
OpenAPITools/openapi-generator#25233 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] OpenApiEvaluator emits "Unused model" warnings even when recommendations are disabledCó thể đã có người làm @mohitduhan19 đã nhận 6 ngày trước. Đang mởIssue: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
OpenAPITools/openapi-generator#25232 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của OpenAPITools/openapi-generator
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] dubbo.protocol.triple.max-message-size is only read from OS environment variablesCó thể đã có người làm @CCCLL đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
youngyangyang04/leetcode-master#3026 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
hierynomus/sshj#1070 ·
-
Typo in ExecutorTemplate.cacelAllFuturesCó thể đã có người làm @xgx2025 đã nhận hôm nay. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100