How to use the openapi-request-coercer.default function in openapi-request-coercer

To help you get started, we’ve selected a few openapi-request-coercer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github inaturalist / iNaturalistAPI / openapi_app.js View on Github external
"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;

openapi-request-coercer

Coerce request properties according to an openapi parameter list.

MIT
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis

Popular openapi-request-coercer functions