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;
I think the problem is the side effect of the Configuration.Timeout property. It forces the ApiClientcreation which forces RestClient creation with default base path which is always "/".
The above prevents creating Configuration instance from scratch because RestClient expects absolute Uri for base path.
Configuration constructor must not have such side effects.
This is a pretty nasty issue. It prevents me from using the generated code as-is, without having to fix it manually. I don't know how this passes any unit tests or even a manual smoke test. Unless you specify Servers (base path), you will get / for basePath and there is no way to get an instance of Configuration without encountering this exception.
In short, the generated C# code does not work.
I did a fix of this one in swagger-codegen-generators repo, PR https://github.com/swagger-api/swagger-codegen-generators/pull/664
Most helpful comment
I think the problem is the side effect of the
Configuration.Timeoutproperty. It forces theApiClientcreation which forcesRestClientcreation with default base path which is always "/".The above prevents creating
Configurationinstance from scratch becauseRestClientexpects absoluteUrifor base path.Configuration constructor must not have such side effects.