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]: String in json format as input for [FromForm] is not recognized in UI #3014

Open
KillerBoogie opened this issue Aug 8, 2024 · 7 comments

Comments

@KillerBoogie
Copy link

Describe the bug

For an endpoint that accepts a file, the title, and a description in multiple languages I use this method

public async Task<ActionResult<GuidIdResponse>> UploadImage([FromForm] string title, [FromForm] string? description, IFormFile file)

The title is entered in JSON format like:

{de":"Bildschirmfoto","en":"screen shot"}

When I enter the above string in the title field of the generated Swashbuckle UI I'm getting error 400:

{
  "type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "errors": {
    "title": [
      "The title field is required."
    ]
  },
  "traceId": "00-259db306db8ce9b0015192084dfc72f2-cd711e4da768cce5-00"
}

The code of my endpoint method is not hit. The error is produced by the framework. When I send the same request with Postman it works fine!

This only happens if the JSON string is well formed and not escaped.

This is sent correctly:
{\"de\":\"Bildschirmfoto\",\"en\":\"screen shot\"}

Those also pass through:

"de":"Bildschirmfoto","en":"screen shot"}
{"de":"Bildschirmfoto",x"en":"screen shot"}
{"de":"Bildschirmfoto",,"en":"screen shot"}

As soon as the JSON is correctly formed, but not escaped the string is not passed and treated as not entered.

Since it works fine with Postman t must be a bug in Swashbuckle.,

Expected behavior

Pass the entered string into the variable.

Actual behavior

A string in valid JSON format is treated as not provided:

{
"type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
"title": "One or more validation errors occurred.",
"status": 400,
"errors": {
"title": [
"The title field is required."
]
},
"traceId": "00-259db306db8ce9b0015192084dfc72f2-cd711e4da768cce5-00"
}

Steps to reproduce

No response

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

6.7.0

.NET Version

8.0.303

Anything else?

Swashbuckle Json
@martincostello
Copy link
Collaborator

Can you share your OpenAPI document and/or a runnable code sample in the form of a GitHub repo?

This could be either an issue with Swashbuckle (the OpenAPI document being incorrectly generated) or SwaggerUI (incorrectly interpreting the OpenAPI document).

@martincostello
Copy link
Collaborator

Sounds very similar to #2930, which is an issue in SwaggerUI.

@KillerBoogie
Copy link
Author

This is exactly the same issue as in #2930. Do you still need an OpenAPI document from me?

@martincostello
Copy link
Collaborator

If it's because of SwaggerUI, then no I don't think so.

If there isn't already an issue for this, I suggest opening one over in their repo. We can then ingest the fix when it's available.

@jgarciadelanoceda
Copy link
Contributor

jgarciadelanoceda commented Oct 2, 2024

@KillerBoogie, can you test if it's working now?
We have just fixed the Bug #3094, and it seems very similar.
Use MyGet to verify using the latest bits (It's in a PreRelease version right now)

@KillerBoogie
Copy link
Author

I'm sorry, but I don't have the time to test right now due to a few deadlines. What is MyGet?

@martincostello
Copy link
Collaborator

It's the NuGet feed containing our prerelease package versions.

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

No branches or pull requests

3 participants