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

[Bug]: POST multipart/form-data with the form parameter supposed to be a json breaks the request #3213

Closed
dslynko opened this issue Jan 2, 2025 · 2 comments
Labels

Comments

@dslynko
Copy link

dslynko commented Jan 2, 2025

Describe the bug

If I send a POST multipart/form-data request with the form parameter which is supposed to contain some json-formatted string, the request is broken. As the example I have created a simple ASP NET Core Web API solution from the VS 2019 template and added a single method. Here is the screen of the SwaggerUI:

image

Here is seen, that JSON string instead of request like:

curl -X 'POST' \
  'https://localhost:7263/WeatherForecast/Test' \
  -H 'accept: text/plain' \
  -H 'Content-Type: multipart/form-data' \
  -F 'someJson="{\"A\": 1, \"B\": 42}"'

becomes

curl -X 'POST' \
  'https://localhost:7263/WeatherForecast/Test' \
  -H 'accept: text/plain' \
  -H 'Content-Type: multipart/form-data' \
  -F 'A=1' \
  -F 'B=42'

As the result, ASP NET Core API method does not receive the parameter at all.

Expected behavior

JSON-formatted string is passed as string

curl -X 'POST' \
  'https://localhost:7263/WeatherForecast/Test' \
  -H 'accept: text/plain' \
  -H 'Content-Type: multipart/form-data' \
  -F 'someJson="{\"A\": 1, \"B\": 42}"'

Actual behavior

JSON-formatted string is split to separate properties and sent as separate form fields

curl -X 'POST' \
  'https://localhost:7263/WeatherForecast/Test' \
  -H 'accept: text/plain' \
  -H 'Content-Type: multipart/form-data' \
  -F 'A=1' \
  -F 'B=42'

Steps to reproduce

/~https://github.com/dslynko/swagger-post-json-issue

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

Latest

.NET Version

8

Anything else?

No response

@dslynko dslynko added the bug label Jan 2, 2025
@martincostello
Copy link
Collaborator

Might be a duplicate of #3014.

@martincostello
Copy link
Collaborator

I'm fairly sure this is a duplicate of #3014. If it's not, maybe it's similar to #3094, but that should be fixed in the latest release.

If you think it's the latter and not an issue with SwaggerUI and you're still having a problem, then we can re-open this and investigate.

@martincostello martincostello closed this as not planned Won't fix, can't repro, duplicate, stale Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants