NSwag icon indicating copy to clipboard operation
NSwag copied to clipboard

System.Text.Json sometimes generated a client with mixed references

Open oduis opened this issue 2 years ago • 4 comments

See, screenshot. The Serializeroptions are correctly using System.Text.Json, while the Serialize itself references the old Newtonsoft. Feel free to PM me for a repro.

image

oduis avatar Aug 26 '22 13:08 oduis

Experiencing the same issue today

b-mcbride avatar Sep 09 '22 22:09 b-mcbride

@oduis Is your API specification file large? The one I am dealing with is over 4MB and I suspect that may be the issue.

b-mcbride avatar Sep 12 '22 17:09 b-mcbride

Mine is small, just 10kB.

oduis avatar Sep 12 '22 17:09 oduis

OK I think I figured it out...

If you look at https://github.com/RicoSuter/NSwag/blob/v13.15.10/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid#L208 it would appear that NSWAG always uses Newtonsoft when dealing with operations that consume "application/x-www-form-urlencoded".

Technically, NSWAG advertises System.Text.Json support as "experimental/incomplete" so this must be an example of that

b-mcbride avatar Sep 12 '22 18:09 b-mcbride

This issue is affecting me as well and took some time to track down.

This bug was caused by this PR: https://github.com/RicoSuter/NSwag/pull/3309

But there is a PR with the fix already here: https://github.com/RicoSuter/NSwag/pull/4172

@RicoSuter - Could you take a look at this PR ^^. Seems like a straightforward fix.

RandyWilkinson avatar Jan 21 '23 01:01 RandyWilkinson

It looks like it was fixed by #4402 @oduis can you test it with v13.18.3 or later?

olegd-superoffice avatar Aug 21 '23 09:08 olegd-superoffice

Just tested, looks great now, thanks!

oduis avatar Aug 23 '23 07:08 oduis