-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question, C# generated client: Is there a way to stream large json's? #4236
Comments
I have the same question, since I migrated one of our clients to a swagger definition and generating the client with NSwag - actually, one API even has a bulk-insert endpoint (there could be additional optimization done on providing the stream in chunks). I've actually found an interesting part here ( NSwag/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid Lines 197 to 204 in 13de8d0
The default branch is this here: NSwag/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid Lines 216 to 219 in 13de8d0
But could also be this here ( NSwag/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid Lines 213 to 215 in 13de8d0
Some idea how to declare the operation body binary somehow? Best |
I managed to do this by using a custom Client.Class.liquid template (setting templateDirectory in the .nswag) and using a custom content that writes to the request stream directly. Obviously this is not idea using a custom template. System.Net.Http.Json looks like it takes this same approach but I'm not sure if there are any issues with this. |
I want to send a large json through a nswag generated csharp client.
My problem is with the generated code:
var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(model, _settings.Value);
var content_ = new System.Net.Http.StringContent(json_);
Serializing model into a json string essentialy doubles the memory consumption.
I would like to serialze the json into a stream and use StreamContent instead of StringContent.
Like it is explained here: https://johnthiriet.com/efficient-post-calls/
Is there a way to generate a client that way?
By looking at the source code it does not seem possible. But maybe is missed something.
The text was updated successfully, but these errors were encountered: