Forum Discussion

ggfuzzy's avatar
Occasional Visitor
3 months ago

Specify both file content and body content in openapi

In my web application, when I create a form-data object that looks like the following:


let fd = new FormData();
let data = {}; = 5; // thing id, if this is an existing thing
data.thingName = 'Resource Test'; // actual value from modal form
data.thingType = 'Type Check'; // actual value from modal form
data.relatedThingId = 19; // actual value from modal form, if bar selected
fd.append('thing', JSON.stringify(data));
fd.append('file', values.file?.file);
const upload = await axios.put('/things', fd);

the 'thing' key along with it's corresponding stringified 'data' is loaded into request.body by axios, while the file object corresponding to the 'file' key is loaded into request.Files.file. I've found I can model the file portion of the request in my openapi document by doing the following (although I don't know if this is the correct way to do it:


description: creates or updates a thing record
required: true
type: object
description: the name of the file being stored
type: number
description: the mimetype of the file
type: string
description: the body of the file
type: string
format: binary
However, I'm having trouble figuring out (or finding examples/instructions) on how to model the part of the request that ends up in the request body. Trying to add a separate 'parameters' section where '- in: body' generates an error, saying that 'body' is not one of the 4 permitted 'in' values ("allowedValues: path, query, header, cookie"). Can anyone share how to model what I'm attempting?
No RepliesBe the first to reply