NSwag
NSwag copied to clipboard
FileParameter tries to do JsonConvert.SerializeObject on the Stream
When using a generated client for an API where the input type is a stream, this generates a FileParameter body
input parameter in NSwag. This looks good.
When you look at the generated code by NSwag, it tries to put the stream into a Json Serialized Object, this shouldn't happen. It's not Json! It's a stream where the type is application/octet-stream, so there is no point in serializing. It should put the body.Data
(the actual steam). directly on the http request stream instead, no reading at all.
var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value));
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/octet-stream");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
The latest version where it did work seems to be NSwag.ApiDescription.Client 13.7.0, however, it used a regular IO Stream instead of a FileParameter.
I'm also having this issue
Same here. As result of Json serialization receive Timeouts are not supported on this stream exception.
@RicoSuter Any chance that you will pay attention to this issue in near future?
I'm still encountering this issue in version 14.0.3. @erwinkramer did you find a workaround for this problem?
@rbnpst i'm not working with that tech right now, but my workaround at the time was going back to version 13.7. If you would ask me what i would do if i encounter it today, i'd try out other tooling, like Kiota from Microsoft. Let me know when u try it.
13.7 works for me. Not sure if we want to use an older version for long, but it's good for now. I'll take a look at Kiota. Thanks!