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

[C# Client] multiple 'consumes' types are ignored. #5069

Open
rima1098 opened this issue Dec 18, 2024 · 0 comments
Open

[C# Client] multiple 'consumes' types are ignored. #5069

rima1098 opened this issue Dec 18, 2024 · 0 comments

Comments

@rima1098
Copy link

Describe the bug

If a endpoint is able to consume different content types e.g. like:
"application/json",
"text/json",
"application/xml",
"text/xml",
"application/x-www-form-urlencoded"

then in general Nswag tries to use "application/json" if available. (see here and below lines)

However, if the endpoint supports also FormUrlEncoded content, this is used rather than "application/json" in the Client:

{% elsif operation.ConsumesFormUrlEncoded -%}

Additionally to that, the content type in the header is not set to "application/x-www-form-urlencoded" but to "application/json" as it is the default value for "operation.Consumes" when available.

content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("{{ operation.Consumes }}");

The content is only serialized as "application/json" if no other content type is supported (see this line and following)

Version used

v14.2.0

Expected behavior

I like that "application/json" is used as default and it should stay like that, but then the client has to check this at first and don't do this at the end if no other supported content type was used.
Additionally, if other content types are used and "application/json" is supported, the content type should be set to the actual used value.

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

No branches or pull requests

1 participant