OpenAPITools / OpenAPITools/openapi-generator
[BUG][csharp-netcore] HttpClient always uses "application/json" as Content-Type even other type is specified.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
This is a bit of a poor bug report, I'll fill it out later if required, and if this change is acceptable I'll make a quick PR. Since it will be a mayor behaviour change to fix it.
Bug Report Checklist
- 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?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
We have some Patch endpoint which only accept application/json-patch+json Content-Type.
Should probably be:
{
contentType = contentType ?? "application/json";
var serializer = new CustomJsonCodec(SerializerSettings, configuration);
request.Content = new StringContent(serializer.Serialize(options.Data), new UTF8Encoding(),
contentType);
}
openapi-generator version
6.0.0-SNAPSHOT (:latest docker tag)
OpenAPI declaration file content or url
requestBody:
content:
application/json-patch+json:
schema:
$ref: '#/components/schemas/JsonPatchDocument'
Generation Details
This is for the csharp-netcore generator with the library: httpclient config option. Using the :latest docker tag.
Steps to reproduce
- Do request to server
- Check Content-Type that the server receives. (It's application/json instead of application/json-patch+json)
Related issues/PRs
Suggest a fix
Should probably be:
{
contentType = contentType ?? "application/json";
var serializer = new CustomJsonCodec(SerializerSettings, configuration);
request.Content = new StringContent(serializer.Serialize(options.Data), new UTF8Encoding(),
contentType);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with modules/openapi-generator/src/main/resources/csharp-netcore/libraries/httpclient/ApiClient.mustache around lines 379-383 and inspect how the request content type is selected. Generate a csharp-netcore client with the httpclient library for an application/json-patch+json request body, then confirm the generated request preserves that media type instead of always using application/json.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100