You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG][csharp] Header parameter with content: application/json is serialized via ParameterToString() instead of JSON #25082
Have you provided a full/minimal spec to reproduce the issue?
Have you validated the input using an OpenAPI validator (example)?
Have you tested with the latest master to confirm the issue still exists?
Have you searched for related issues/PRs?
Description
When a header parameter is declared with content: application/json, the generated C# client serializes it through ClientUtils.ParameterToString(...). For a model object, ParameterToString falls through to Convert.ToString(obj, CultureInfo.InvariantCulture), which calls the model's ToString() — the generated debug representation — instead of JSON.
This is the C# counterpart of the Java issue #25055 and the Python issue #25067. It affects all C# client libraries, since they share this serialization path for header parameters: restsharp (default), httpclient, generichost, and unityWebRequest.
openapi-generator version
7.25.0 and master (7.26.0-SNAPSHOT). The code path has existed for a long time.
Call the operation with new HeaderArg { Path = "/x" }.
Expected:X-Json-Arg: {"path":"/x"} Actual: the model's debug ToString() output, e.g.:
class HeaderArg {
Path: /x
}
Reproducible without making any HTTP request (the serialized value is wrong at construction time).
Root cause
DefaultCodegen already preserves the media type in CodegenParameter.contentType, and there is an existing isJsonMimeType(...) helper plus the precedent of queryIsJsonMimeType for query parameters. Header parameters have no equivalent handling, so JSON-content headers fall back to ParameterToString → Convert.ToString → ToString().
Suggested fix
Mirror the existing queryIsJsonMimeType mechanism: add a shared headerIsJsonMimeType flag (set in DefaultCodegen.fromParameter) and, in the C# templates, serialize JSON-content headers as JSON (ASCII-safe) instead of via ParameterToString, keeping existing behavior for regular headers.
Activity
[csharp] Serialize header parameters with content: application/json a…