NSwag icon indicating copy to clipboard operation
NSwag copied to clipboard

Generated client file creates methods with DollarSign ($) in the method name $metadataAsync(...)

Open HowardShank opened this issue 1 year ago • 9 comments

@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

HowardShank avatar Dec 15 '23 17:12 HowardShank

And the versions of NSwag/NJsonSchema you are using?

lahma avatar Dec 15 '23 17:12 lahma

Sorry about that...

[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.20.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v11.0.0.0))")]

HowardShank avatar Dec 15 '23 17:12 HowardShank

Can you try the latest 14 preview, I think it has some new escaping..

lahma avatar Dec 15 '23 17:12 lahma

I can try RC1. I don't have Wix setup to do a build of NSwag. That good enough to try?

HowardShank avatar Dec 15 '23 18:12 HowardShank

There's v14 preview on NuGet, I'm not sure how you are consuming

lahma avatar Dec 15 '23 18:12 lahma

I used the MSI to install NSwag Studio

HowardShank avatar Dec 15 '23 18:12 HowardShank

FYI, it's picking up the $ from the Odata endpoint and using it when it creates the method name. image

HowardShank avatar Dec 15 '23 18:12 HowardShank

I temporarily removed Odata from my endpoint configurations and the issue went away.

HowardShank avatar Dec 15 '23 18:12 HowardShank

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))")]

drepamig avatar Jan 19 '24 19:01 drepamig