swagger-api / swagger-api/swagger-codegen

Setting Configuration.DefaultApiClient is ignored

Open
#10,005 3 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

The code below, from Configuration.cs is causing problems.

public static ApiClient DefaultApiClient = new ApiClient();

because ApiClient is defined like:

public ApiClient(String basePath="/")

When I want to set my valid url, static DefaultApiClient initialise ApiClient with "/" and complains about it.

var baseUrl = "my-valid-url";
Configuration.DefaultApiClient = new ApiClient(baseUrl);

Unhandled exception. System.TypeInitializationException: The type initializer for 'IO.Swagger.Client.Configuration' threw an exception.
---> System.UriFormatException: Invalid URI: The format of the URI could not be determined.

Possible fix, define it like this in Configuration.cs:

public static ApiClient DefaultApiClient;

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 with Configuration.cs and inspect how DefaultApiClient is initialized alongside the ApiClient constructor in the issue. Confirm that assigning a valid ApiClient no longer triggers a type-initialization failure caused by the default "/" base path, then verify the generated client initializes successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.