OpenAPITools / OpenAPITools/openapi-generator

[BUG] [csharp-netcore] No way to pass proxy

Open
#4,236 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: C-Sharp 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)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Sorry I'm not shure if this a bug or feature request.

My client is generated with csharp-netcore.
I want to setup a proxy with the generated client. Here is mandatory not changig the generated code.

But there is actually no way to pass a proxy to the RestSharp client.
Everything is wrapped.

In Net framwork and Net core 3 its possible to setup a global proxy. But in Net core 2 its not possible.

Before using csharp-netcore i generated the client the client under targetframework net45.
Here i was able to use a proxy.

Example:

     var proxy = new WebProxy("http://localhost:3128")
      {
        Credentials = new NetworkCredential("USER", "PASS")
      };

      var config = new Configuration
      {
        BasePath = "https://my-example-api.com/api/v1",
        AccessToken = token.access_token
      };

      config.ApiClient.RestClient.Proxy = proxy;

In the same way its missed for netstandard.

openapi-generator version

4.1.3

OpenAPI declaration file content or url
Command line used for generation

java -jar "openapi-generator-cli-4.1.3.jar" generate -i api.yaml -g csharp-netcore -o Example.Client -p packageName=Example.Client

Steps to reproduce

Generate a csharp-netcore client and try to setup a proxy

Related issues/PRs
Suggest a fix

I think its needed to add api client configuration to the config in the same way like in Net framework

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 csharp-netcore client with the shown OpenAPI Generator 4.1.3 command, then inspect the generated Configuration and RestClient usage. Determine how proxy configuration differs for net45, netcoreapp3, and netstandard targets. Done means a generated client can receive and use a proxy without modifying generated code, with the relevant target frameworks still supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.