OpenAPITools / OpenAPITools/openapi-generator

[BUG] [CSharp] httpclient does not support Options, only supports obsolete HttpRequestMessage.Properties

Open
#19,804 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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)

Using openapi-generator to generate csharp clients with the HttpClient library ends up generating code that uses the obsolete HttpRequestMessage.Properties which was deprecated way back in .NET5

It should use the recommended Options instead.

Here's the warnings outputted by Visual Studio 2022:

1>C:\MyApi\Client\ApiClient.cs(418,17,418,35): warning CS0618: 'HttpRequestMessage.Properties' is obsolete: 'HttpRequestMessage.Properties has been deprecated. Use Options instead.'
1>C:\MyApi\Client\ApiClient.cs(505,39,505,53): warning CS0618: 'HttpRequestMessage.Properties' is obsolete: 'HttpRequestMessage.Properties has been deprecated. Use Options instead.'
1>C:\MyApi\Client\ApiClient.cs(505,87,505,101): warning CS0618: 'HttpRequestMessage.Properties' is obsolete: 'HttpRequestMessage.Properties has been deprecated. Use Options instead.'
Description
openapi-generator version

7.8.0

OpenAPI declaration file content or url

Here's the contents of the config file

generatorName: csharp
sourceFolder: Src
additionalProperties:
  library: httpclient
  targetFramework: net8.0
Generation Details
Steps to reproduce
  • generate a client with csharp + httpclient + .NET8.0 using the openapi generator config pasted above,
  • check the resulting code.
Related issues/PRs
  • #12691
Suggest a fix
  • Add support Options,
  • add a csharp config option to toggle between HttpRequestMessage.Properties and Options, set HttpRequestMessage.Properties as default.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by generating the C# httpclient client with the provided config and inspect the generated ApiClient.cs locations cited in the warning output. Read docs/generators/csharp.md and related issue #12691 to understand the intended configuration behavior. Done means the generated .NET 8 client uses the supported request metadata API and no longer emits the reported obsolete-property warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.