Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"multipart/form-data": ( req, res, next ) => {
const knownUploadFields = [];
const { properties } = req.operationDoc.requestBody.content["multipart/form-data"].schema;
_.each( properties, ( schema, name ) => {
if ( schema.type === "string" && schema.format === "binary" ) {
knownUploadFields.push( name );
}
} );
const props = req.operationDoc.requestBody.content["multipart/form-data"].schema.properties;
const parameters = _.map( _.keys( props ), k => ( {
in: "formData",
name: k,
schema: req.operationDoc.requestBody.content["multipart/form-data"].schema.properties[k]
} ) );
const coercer = new openapiCoercer.default( {
extensionBase: "x-express-openapi-coercion",
loggingKey: "express-openapi-coercion",
parameters,
enableObjectCoercion: true
} );
coercer.coerce( req );
upload.fields( _.map( knownUploadFields, f => ( { name: f } ) ) )( req, res, err => {
const originalBody = _.cloneDeep( req.body );
const newBody = { };
_.each( originalBody, ( v, k ) => {
if ( _.isObject( v ) ) {
newBody[k] = { };
_.each( v, ( vv, kk ) => {
if ( vv !== "" ) {
newBody[k][kk] = vv;