Skip to content

Commit c85d60e

Browse files
authored
Safer handling of multipart nested JSON body props (#878)
If a multipart request body has schema oneOf, anyOf, or allOf, then automatic parsing of JSON properties throws. An object is expected. Fix the error today and add a TODO to add support for nested JSON props in multipart requests that utilize oneOf, anyOf, or allOf.
1 parent b9880bb commit c85d60e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/middlewares/openapi.request.validator.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,16 @@ export class RequestValidator {
206206
private multipartNested(req, schemaBody) {
207207
Object.keys(req.body).forEach((key) => {
208208
const value = req.body[key];
209-
const type = schemaBody?.properties?.body?.properties[key]?.type;
209+
// TODO: Add support for oneOf, anyOf, allOf as the body schema
210+
const type = schemaBody?.properties?.body?.properties?.[key]?.type;
210211
if (['array', 'object'].includes(type)) {
211212
try {
212213
req.body[key] = JSON.parse(value);
213214
} catch (e) {
214215
// NOOP
215216
}
216217
}
217-
})
218+
});
218219
return null;
219220
}
220221

0 commit comments

Comments
 (0)