Skip to content

Commit

Permalink
Safer handling of multipart nested JSON body props (#878)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mdmower committed Nov 30, 2023
1 parent a4e62ac commit 807e09c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/middlewares/openapi.request.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,16 @@ export class RequestValidator {
private multipartNested(req, schemaBody) {
Object.keys(req.body).forEach((key) => {
const value = req.body[key];
const type = schemaBody?.properties?.body?.properties[key]?.type;
// TODO: Add support for oneOf, anyOf, allOf as the body schema
const type = schemaBody?.properties?.body?.properties?.[key]?.type;
if (['array', 'object'].includes(type)) {
try {
req.body[key] = JSON.parse(value);
} catch (e) {
// NOOP
}
}
})
});
return null;
}

Expand Down

0 comments on commit 807e09c

Please sign in to comment.