Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
`${this.loggingPrefix}request validator on for`,
methodName,
openapiPath
);
}
if (
allowsCoercionFeature(
this,
this.apiDoc,
pathModule,
pathDoc,
operationDoc
)
) {
const coercer = new OpenAPIRequestCoercer({
extensionBase: `x-${this.name}-coercion`,
loggingKey: `${this.name}-coercion`,
parameters: methodParameters,
enableObjectCoercion: this.enableObjectCoercion
});
operationContext.features.coercer = coercer;
}
// no point in default feature if we don't have any parameters with defaults.
if (
methodParameters.filter(byDefault).length &&
allowsDefaultsFeature(
this,
this.apiDoc,
pathModule,
if (!path) {
throw new Error('RequestCoercionMiddlewareFactory requires path')
}
if (!operation) {
throw new Error('RequestCoercionMiddlewareFactory requires operation')
}
let operationObject: OpenAPIV3.OperationObject
try {
operationObject = getOperationObject(props.openApi, path, operation)
} catch (error) {
return []
}
const coercer = new OpenApiRequestCoercer({
enableObjectCoercion: true,
parameters: operationObject.parameters || [],
})
return [
(req, _res, next) => {
coercer.coerce(req)
next()
},
]
}
}
"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;