swagger-api / swagger-api/swagger-codegen
Generated C# Configuration should allow setter for the ApiClient
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The configuration object that is generated for csharp code only contains a getter for the ApiClient. I want to be able to set the my own ApiClient because I am using other code I have written that generates a RestClient and handles various authentication scenarios that I need to cover.
Suggest a fix/enhancement
I was able to get the generated code to work they way I wanted by modifying the generated Configuration.cs file to add a setter for ApiClient like this
private ApiClient _apiClient = null;
/// <summary>
/// Gets an instance of an ApiClient for this configuration
/// </summary>
public virtual ApiClient ApiClient
{
get
{
if (_apiClient == null) _apiClient = CreateApiClient();
return _apiClient;
}
set { _apiClient = value; } //<-- *****I added this ****
}
I am then using the code like this
//Creating the corporations api
CorporationsApi _corpApi = new CorporationsApi();
//Setting up the configuration with correct authentication
//Creating the api client and passing it a session
ApiClient corpApiClient = new ApiClient(GetParameters.getUri());
corpApiClient.RestClient = Client.createSession(); //<--***this method is where I use my own
//code to create an authenticated RestClient ****
//Creating a configuration and passing it the api client and setting the base path
Configuration corpApiConfig = new Configuration();
corpApiConfig.BasePath = GetParameters.getUri();
corpApiConfig.ApiClient = corpApiClient; //<--***here I am using the setter I made ****
//Giving the configuration object to our instance of the corporation api
_corpApi.Configuration = corpApiConfig;
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 by locating the C# template or generator entry point that produces Configuration.cs, then compare it with the setter shown in the issue. Generate a C# client and verify that the resulting Configuration.ApiClient can be assigned to a caller-provided ApiClient.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100