0

发生错误:

回调错误!折腾到全局错误处理程序。TypeError:无法在 /home/ 处读取 SwaggerRunner.create (/home/feel/cfeel-core/node_modules/feel-framework/src/modules/http_api/init_steps/bootstrap_swagger.js:318:33) 处未定义的属性“expressMiddleware”感觉/cfeel-core/node_modules/swagger-node-runner/index.js:237:7

代码如下

/home/feel/cfeel-core/node_modules/feel-framework/src/modules/http_api/init_steps/bootstrap_swagger.js:318:33)

    // Swagger express middleware
    SwaggerRunner.create(swaggerConfig, (errors, runner) => {
        if (errors) {
            // Ignore unused definition warning
            errors.validationWarnings = _.filter(
                errors.validationWarnings,
                error => error.code !== 'UNUSED_DEFINITION',
            );

            // Some error occurred in configuring the swagger
            if (!_.isEmpty(errors.validationErrors)) {
                logger.error('Swagger Validation Errors:');
                logger.error(errors.validationErrors);
            }

            if (!_.isEmpty(errors.validationWarnings)) {
                logger.error('Swagger Validation Warnings:');
                logger.error(errors.validationWarnings);
            }

            if (
                !_.isEmpty(errors.validationErrors) ||
                !_.isEmpty(errors.validationWarnings)
            ) {
                cb(errors);
                return;
            }
        }

        // Swagger express middleware
        const swaggerExpress = runner.expressMiddleware();//318:33
        
        // Check the response and act appropriately on error
        runner.on('responseValidationError', validationResponse => {
            // TODO: Troubleshoot why default validation hook considers json response as string response
            if (validationResponse.errors[0].code !== 'INVALID_RESPONSE_BODY') {
                logger.error('Swagger Response Validation Errors:');
                logger.error(validationResponse.errors[0].errors);
            }
        });

        // Install middleware
        swaggerExpress.register(app);

        // To be used in test cases or getting configuration runtime
        app.swaggerRunner = runner;

        // Managing all the queries which were not caught by previous middlewares.
        app.use((req, res, next) => {
            // We need to check if the response is already handled by some other middlewares/fittings/controllers
            // In case not, we consider it as 404 and send default response
            // res.headersSent is a patch, and only works if above middlewares set some header no matter the status code
            // Another possible workaround would be res.bodySize === 0
            if (!res.headersSent) {
                res.status(404);
                res.json({ description: 'Page not found' });
            }
            next();
        });

        swaggerHelper
            .getSchemaAsJSON()
            .then(resolvedSchema => {
                // Successfully mounted the swagger runner
                cb(null, {
                    swaggerRunner: runner,
                    definitions: resolvedSchema.definitions,
                });
            })
            .catch(reason => {
                logger.error(reason.toString());
                cb(reason);
            });
    });
}

/home/feel/cfeel-core/node_modules/swagger-node-runner/index.js:237:7

    cb(null, self);
    })
    .catch(function(err) {
      cb(err);//237:7
    })
4

0 回答 0