Swashbuckle.AspNetCore
Swashbuckle.AspNetCore copied to clipboard
[Bug]: String in json format as input for [FromForm] is not recognized in UI
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