NSwag
NSwag copied to clipboard
Generated client file creates methods with DollarSign ($) in the method name $metadataAsync(...)
@RicoSuter
Issue: When generating a client source file from my swagger json file the generated code contains methods with invalid characters for the naming convention. This appears to be related to Odata.
NSwag Information
[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.20.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v11.0.0.0))")]
Compiler Error:
Severity Code Description
Error CS1519 Invalid token '$' in class, record, struct, or interface member declaration
<redacted>.WebUI.vs2022.net8\Services\Clients\Rest\SecRestClient.cs
Generated Code:
System.Threading.Tasks.Task<IEdmModel> $metadataAsync(string authorization);
My solution: My solution was to replace all "$metadataAsync" with "_metadataAsync" to create a valid method name thereby removing this compiler error.
I am unsure of the impact yet as I have other compiler errors to document before I get a clean compile.
Regards, Howard Shank
And the versions of NSwag/NJsonSchema you are using?
Sorry about that...
[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.20.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v11.0.0.0))")]
Can you try the latest 14 preview, I think it has some new escaping..
I can try RC1. I don't have Wix setup to do a build of NSwag. That good enough to try?
There's v14 preview on NuGet, I'm not sure how you are consuming
I used the MSI to install NSwag Studio
FYI, it's picking up the $ from the Odata endpoint and using it when it creates the method name.
I temporarily removed Odata from my endpoint configurations and the issue went away.
I have the same issue. I'm currently using this version:
[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.0.2.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))")]