swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[Csharp]Can't set BasePath in Configuration because Timeout side effects forces ApiClient creation

Open Euynac opened this issue 5 years ago • 2 comments

version: export tool from https://app.swaggerhub.com/ Description Originally I supposed I found such awesome convenient Tools which may help me quickly finish RESTful API Client, but I just followed with the README automatically generated by Codegen, I couldn't easily use the API without doing any change before generating the .dll. The example code also couldn't run properly, and I didn't know anywhere to find more documents but the README. I knew I need to set the api server host url but no matter how I attempt to do it, it just throws the exception: System.UriFormatException: Invalid URI: The format of the URI could not be determined. I had to come back to find out why it couldn’t fetch the Baseurl I gave. After debugging I finally found the problem that "Setting Timeout has side effects (forces ApiClient creation).". But it almost have been specified as annotation... When new a Configuration Instance it will force ApiClient creation with the basepath = "/" before setting the Basepath property manually. and I also find the related issues: #10005 why not fixing this side effect, or just to specify in auto generated README? or there are any best practices? Thank you.

Euynac avatar Jul 20 '20 09:07 Euynac

Finally I simply override the property BasePath and add a personal static property ApiHost into GlobalConfiguration, and go back to its parent class Configuration constructor and annotate BasePath = "/"; , and just at first define the GlobalConfiguration.ApiHost, then it work for all api without any configure.

Euynac avatar Jul 20 '20 12:07 Euynac

+1

Prikalel avatar Oct 04 '23 14:10 Prikalel