RicoSuter / NSwag

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

Bug: string.Empty is not valid JSON #4919

Open idea-lei opened 2 weeks ago

idea-lei commented 2 weeks ago

When request body (POST, PUT, PATCH) is empty, NSWag generates a string content as following:

request_.Content = new System.Net.Http.StringContent(string.Empty, System.Text.Encoding.UTF8, "application/json;odata.metadata=minimal;odata.streaming=true");

Empty string is not valid json (should be "" or {} or just without this instruction) which causes exception.

VERSION: 14.08 and below

idea-lei commented 2 weeks ago

Similar issues: https://github.com/RicoSuter/NSwag/issues/4452 https://github.com/RicoSuter/NSwag/issues/2477