NSwag: C# code generation with /GenerateBaseUrlProperty:false option is broken in v14.0.1
NSwag generates invalid C# code when /GenerateBaseUrlProperty:false option is used. It looks like it is a regression in v14.0.1 possibly caused by #4691
Here’s a simple project which demonstrates the regression: GenerateBaseUrlPropertyFalse.zip. It will download and use example petstore OpenAPI document. Just run dotnet build.
It works with NSwag.ApiDescription.Client 13.20.0 and 14.0.0 but fails with 14.0.1
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 3
- Comments: 19 (9 by maintainers)
Commits related to this issue
- Avoid generating unused _baseUrl (C# gen) — committed to RicoSuter/NSwag by RicoSuter 3 years ago
- Fix CSharp client BaseUrl usage When `UseBaseUrl` is set, the methods need to use the `BaseUrl` property instead of the backing field, otherwise the base class, if it exists, cannot pass the URL to a... — committed to MaximBalaganskiy/NSwag by MaximBalaganskiy 2 years ago
When will this issue be fixed? The code should use the BaseUrl from the ClientBase instead of hardcoding the original URL in the _baseUrl. Please also revert the logic to trim a trailing ‘/’. As mentioned above, this potentially introduces bugs.
I can confirm the impact on my project as well.
My use case is: useBaseUrl=true generateBaseUrlProperty=false
I have a base class that implements BaseURL and return the urlto be used in urlBuilder but now it’s ignored. The proxy is using directly _baseUrl instead of BaseURL
@RicoSuter The 14.0.3 generated code is getting compiled without errors now but the logic of how
/GenerateBaseUrlProperty:falseflag works is different now.BaseUrlproperty was not generated but still was used and it was responsibility of base class to declare and assign aBaseUrlvalue (usually from configuration)./GenerateBaseUrlProperty:falseflag didn’t compile.BaseUrlproperty is not generated and is not used at all. Insteadprivate string _baseUrlfield is assigned from ahostvalue defined in OpenAPI document. The only workaround I could find to change_baseUrlvalue is to put some weird logic into override ofPrepareRequestmethod.It looks like it is still a breaking change between 14.0.0 and 14.0.3.
Any updates on the issue?
Sorry. I was thinking of another issue.