-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C# code generation with /GenerateBaseUrlProperty:false option is broken in v14.0.1 #4705
Comments
@olegd-superoffice, please, explain in what way it doesn't work. |
I think I'm getting something wrong here. Is the
The difference between 14.0.1 and 14.0.0 and 13.20.0 is that 14.0.1 assigns the My reasoning how this should be is:
Is that how it should be? |
Seems like the change is to never initialize the And there's a breaking change for implementers of the |
But why force implementers to provide a If the |
I changed it as a performance optimization, but I'm rethinking it. |
Should be fixed with this commit: Sorry for all the inconveniences... |
@RicoSuter The 14.0.3 generated code is getting compiled without errors now but the logic of how
It looks like it is still a breaking change between 14.0.0 and 14.0.3. |
I think I was addressing all issues with paulomorgado@744940b, but it's now failing this recently added test: [Fact]
public async Task WhenUsingBaseUrl_ButNoProperty_ThenPropertyIsNotUsedAndFieldIsGenerated()
{
// Arrange
var swaggerGenerator = new WebApiOpenApiDocumentGenerator(new WebApiOpenApiDocumentGeneratorSettings
{
SchemaSettings = new NewtonsoftJsonSchemaGeneratorSettings()
});
var document = await swaggerGenerator.GenerateForControllerAsync<FooController>();
var generator = new CSharpClientGenerator(document, new CSharpClientGeneratorSettings
{
UseBaseUrl = true,
GenerateBaseUrlProperty = false
});
// Act
var code = generator.GenerateFile();
// Assert
Assert.DoesNotContain("BaseUrl", code);
Assert.Contains("string _baseUrl", code);
} I still don't have a full grasp of the usage of |
I can confirm the impact on my project as well. My use case is: I have a base class that implements BaseURL and return the urlto be used in urlBuilder but now it's ignored. |
I also have this problem. I cannot assign baseUrl in base class because generated classes use locally defined _baseUrl ignoring external settings. |
For me, 14.0.1 works as expected using BaseUrl from the base class I am running with UseBaseUrl = true and GenerateBaseUrlProperty = false. For my application, I need to be able to set the base Url at run time, even if a Base Path is specified in swagger.json. Is this going to be changed back so the base class can control the base Url, or do I need to find another way to do this? For now I have to stay on 14.0.1 Thanks |
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. |
Any updates on the issue? |
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 #4691Here'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
@paulomorgado
The text was updated successfully, but these errors were encountered: