RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.62k stars 1.23k forks source link

Swagger parameters not porting over to valid C# parameters #4805

Open churstz opened 4 months ago

churstz commented 4 months ago

I've encountered an issue with a vendor's swagger doc where some of their parameters are notating hierarchy by using a colon as separator. Example client:firsname, client:lastname, client:favcolor. This results in C# variables being rendered as

string client:firstname, string client:lastname, string client:favcolor

none of which are valid variable names. These can't be simply replaced in code because of their valid uses and the need for them to exist when calling the swagger endpoints. They can't be refactored because they are not valid C# to begin with. I believe i've found the place in code where this is used.

Requesting the DefaultParameterNameGenerator class update the Generate method to include .Replace(":", "_") to the ConversionUtilities.ConvertToLowerCamelCase method call

churstz commented 4 months ago

This is where I'm proposing the change https://github.com/RicoSuter/NSwag/blob/0c9d87f1623e8a7f7d29ba9593108270e05f987a/src/NSwag.CodeGeneration/DefaultParameterNameGenerator.cs#L46