Model schema for multipart header
See original GitHub issueHi, is there a way to specify a model schema when using a multipart POST/PUT request? We’re sending both a file and a JSON string mapped to one of our classes and currently no model schema shows up in the generated documentation. What we’d like to add is minimally a model schema for the custom class object (in the example below a Document). I don’t see a way to do this currently, at least through the documentation and what I could find on the web.
Our methods are pretty straight forward and not sure if it’s helpful but here’s what we have:
[ValidateModel]
[HttpPost]
[ValidateMimeMultipartContent]
[Route(Name = "CreateNewDocument")]
[SwaggerResponse(HttpStatusCode.Created, null, typeof(Document))]
[SwaggerResponse(HttpStatusCode.InternalServerError)]
[SwaggerResponse(HttpStatusCode.BadRequest)]
[SwaggerResponse(HttpStatusCode.Unauthorized)]
public async Task<HttpResponseMessage> Post()
{
...
Document value = null;
...
var provider = new MultipartFormDataStreamProvider(tempPath);
// Read the form data.
var allData = await Request.Content.ReadAsMultipartAsync(provider);
string documentJson = allData.FormData["DocumentModel"].NormalizeJson();
// get document data
value = JsonConvert.DeserializeObject<Document>(documentJson);
...
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Model schema for multipart header · Issue #796
Hi, is there a way to specify a model schema when using a multipart POST/PUT request? We're sending both a file and a...
Read more >Multipart Requests
You describe individual parts of the request as properties of the schema object. As you can see, a multipart request can include various...
Read more >OpenAPI Example multipart form data - schema
I have a multipart/form-data POST in an API endpoint which takes some key/value strings, and a file upload via the key files ....
Read more >Define schema for multipart/form-data
Hi folks,. In my raml i need to define the schema for the body of a POST method. Content type of the body...
Read more >Media type object with 'multipart/form-data' has no schema ...
One or more media type objects in your API where Content-Type is set to multipart/form-data do not have schemas defined. Schema is required...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the exact same scenario. Here is the backwards engineering I made to make it work: controller action (which receives multi-part data):
The object to specify the schema for is
ReportProblem
: The code for the filter referenced above:Hope this will help you guys, I’ve search this issue through about 5 different swashbuckle issue to get it going in the right direction.
Final screenshot:
Here are some related issues: #283, #638.
HI all. Is there any way to specify acceptable content type of each part in multi-part request? For example, an API that allows user to upload one or more image files. Thanks.