Forum Discussion

ggfuzzy's avatar
ggfuzzy
Occasional Visitor
12 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 = {};
data.id = 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:

 

put:
description: creates or updates a thing record
requestBody:
required: true
content:
multipart/form-data:
schema:
properties:
file:
type: object
properties:
name:
description: the name of the file being stored
type: number
mimetype:
description: the mimetype of the file
type: string
data:
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