RicoSuter / NSwag

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

Nswag 14 openApiToCSharpClient parameters generation issue #4825

Open lucianaparaschivei opened 6 months ago

lucianaparaschivei commented 6 months ago

with nswag 14 it looks like it is generating query string parameter append instead of replace leading to wrong url generation.

in screenshot on the left is generated with nswag 14 and on right (correct one) is with nswag 13.x same settings and open api spec was used for the generation image

RicoSuter commented 6 months ago

Is this still an issue with v14.0.7?

/cc @paulomorgado

scottsanzo commented 6 months ago

I am seeing this issue present in v14.0.7

edit. Disregard. It looks like in my case it was a stale template

Soulfire86 commented 3 weeks ago

I'm having this issue. What do you mean by stale template? How can I check if this is my problem?

scottsanzo commented 3 weeks ago

I'm having this issue. What do you mean by stale template? How can I check if this is my problem?

In my case I have custom liquid templates (to return a wrapped exception instead of throwing them). Changes in the repo required me to merge those into my custom templates. It's an edge case and probably not what you're experiencing.

Soulfire86 commented 3 weeks ago

I'm having this issue. What do you mean by stale template? How can I check if this is my problem?

In my case I have custom liquid templates (to return a wrapped exception instead of throwing them). Changes in the repo required me to merge those into my custom templates. It's an edge case and probably not what you're experiencing.

Urg, okay. Thanks for the answer regardless! I don't think I'm using any custom templates, but once I went from NSwag v13 to v14, it's generating with an extra Append of the parameter NAME after it appends the actual VALUE of the parameter :(

paulomorgado commented 3 weeks ago

@Soulfire86,

I'm having this issue. What do you mean by stale template? How can I check if this is my problem?

In my case I have custom liquid templates (to return a wrapped exception instead of throwing them). Changes in the repo required me to merge those into my custom templates. It's an edge case and probably not what you're experiencing.

Urg, okay. Thanks for the answer regardless! I don't think I'm using any custom templates, but once I went from NSwag v13 to v14, it's generating with an extra Append of the parameter NAME after it appends the actual VALUE of the parameter :(

Can you provide an example?

Soulfire86 commented 3 weeks ago

@paulomorgado Much to my day-long frustration, I realized I had no Parameter filter to set all route parameters to Required. Once they were required, the code generation turned out alright. So, I don't have screenshots, but that would be my example:

With optional parameters (which should not be the case for route parameters I know) the c# client was building methods where it'd append the parameter value where it should go, but then append "{parameterName}" right after it, thus making invalid URLs to my API.

Certainly my fault I suppose, but what a weird thing to happen. Clearly v13 didn't care that the parameters weren't required, it was generating appropriate code just fine.

paulomorgado commented 3 weeks ago

@Soulfire86, can you provide a sample Swagger/OpenAPI doc for that?

Soulfire86 commented 3 weeks ago

@paulomorgado Sorry, bit crunched now to be thorough, but I actually did just come across another example, even with parameter set to required. relevant path from swagger.json: image

Generated C# client method code, up until offending Append issue: image

paulomorgado commented 3 weeks ago

@Soulfire86, can you post the actual swagger?