Skip to content
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

Please generate json in variable instead of StringContent constructor #4131

Closed
dlidstrom opened this issue Sep 2, 2022 · 2 comments · Fixed by #4136
Closed

Please generate json in variable instead of StringContent constructor #4131

dlidstrom opened this issue Sep 2, 2022 · 2 comments · Fixed by #4136

Comments

@dlidstrom
Copy link
Contributor

In generated clients the json serialization of posted bodies is directly passed to the StringContent constructor. This removes a possibility to inspect the json that is sent. Please use a variable to hold the json before it is passed to StringContent. That would allow to see what is ultimately sent to the server. I.e.

var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(hotels, _settings.Value);
var content_ = new System.Net.Http.StringContent(json_);
content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json");
request_.Content = content_;
request_.Method = new System.Net.Http.HttpMethod("POST");
request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("application/json"));
@lahma
Copy link
Collaborator

lahma commented Sep 2, 2022

Maybe you could create a PR to to split that separate variable?

@dlidstrom
Copy link
Contributor Author

I am giving it a shot.

RicoSuter pushed a commit that referenced this issue Sep 16, 2022
…pection (#4136)

* generate json in variable

- this makes it easy to inspect what is sent

* fix test
lahma pushed a commit to lahma/NSwag that referenced this issue Dec 25, 2022
… easy inspection (RicoSuter#4136)

* generate json in variable

- this makes it easy to inspect what is sent

* fix test
lahma pushed a commit to lahma/NSwag that referenced this issue Jan 20, 2024
… easy inspection (RicoSuter#4136)

* generate json in variable

- this makes it easy to inspect what is sent

* fix test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants