Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[BUG][csharp][restsharp] throwOnAnyError: oneOf/anyOf deserialization failure on 2xx escapes as InvalidDataException instead of ApiException

Abierto Apto para principiantes
#25,218 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
65/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp
Área
backend

Línea de trabajo

Empieza en modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache cerca de la línea 500 y sigue la llamada FromJson y el tratamiento existente de throwOnAnyError. Reproduce el problema con un cliente RestSharp generado que use una respuesta oneOf o anyOf que no coincida con ninguna variante y una respuesta 200. El objetivo se alcanza cuando el error de análisis llega a quien llama como una ApiException que contiene el estado 200, el cuerpo sin procesar, los encabezados y la InvalidDataException como excepción interna.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Issue: Bug
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
  1. Generate a csharp client with --library restsharp --additional-properties throwOnAnyError=true from a spec where an operation returns a oneOf model.
  2. Call that operation against a server that returns 200 with a body matching no variant.
  3. Observe InvalidDataException instead of ApiException.
Expected behaviour

ApiException with ErrorCode = 200, ErrorContent = raw body, Headers populated, and the InvalidDataException as InnerException.

Original findings

P2: 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.

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

Lenguaje dominante
Java
Estrellas
26.8k
Forks
7.7k
Merge medio
1 d 12 h
PR fusionados (30 d)
141

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de OpenAPITools/openapi-generator

Todos los issues de OpenAPITools/openapi-generator

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.