请求实体在使用OAS3-Tools软件包时,node.js中的OpenAPI 3.0太大错误
index.js文件
“使用严格”;
var path = require('path');
var http = require('http');
var cors = require('cors');
var oas3Tools = require('oas3-tools');
require("dotenv").config({ path: ".env" });
console.log(`### Running on ~~~ ${process.env.Instance} ~~~ ENV ###`);
var serverPort = 8080;
function validate(request, scopes, schema) {
// security stuff here
return true;
}
// swaggerRouter configuration
var options = {
routing: {
controllers: path.join(__dirname, './controllers')
},
logging: {
format: 'combined',
errorLimit: 400
},
};
var expressAppConfig = oas3Tools.expressAppConfig(
path.join(__dirname, "./api/openapi.yaml"),
options
);
expressAppConfig.addValidator();
var app = expressAppConfig.getApp();
app.use(cors());
var json2xls = require('json2xls');
app.use(json2xls.middleware);
// Initialize the Swagger middleware
http.createServer(app).listen(serverPort, function () {
});
// Connect to database
var mongo = require("./utils/db");
------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------
PFB我们使用的工具的版本。 “ express”:“^4.17.1”, “ oas3-tools”:“ 2.1.3”
我尝试了身体parser and app.use(express.json({limit:'25mb'}))。 但是,没有什么可以解决请求实体太大的错误。 如果有人建议我有不同的解决方案,那就太好了。
index.js file
'use strict';
var path = require('path');
var http = require('http');
var cors = require('cors');
var oas3Tools = require('oas3-tools');
require("dotenv").config({ path: ".env" });
console.log(`### Running on ~~~ ${process.env.Instance} ~~~ ENV ###`);
var serverPort = 8080;
function validate(request, scopes, schema) {
// security stuff here
return true;
}
// swaggerRouter configuration
var options = {
routing: {
controllers: path.join(__dirname, './controllers')
},
logging: {
format: 'combined',
errorLimit: 400
},
};
var expressAppConfig = oas3Tools.expressAppConfig(
path.join(__dirname, "./api/openapi.yaml"),
options
);
expressAppConfig.addValidator();
var app = expressAppConfig.getApp();
app.use(cors());
var json2xls = require('json2xls');
app.use(json2xls.middleware);
// Initialize the Swagger middleware
http.createServer(app).listen(serverPort, function () {
});
// Connect to database
var mongo = require("./utils/db");
----------------------------------------EOF----------------------------------------------
PFB the version of the tools which we've used.
"express": "^4.17.1",
"oas3-tools": "2.1.3"
I've tried body-parser and app.use(express.json({limit:'25mb'})).
But nothing resolved the request entity too large error.
It would be great if anyone suggest me any different solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有手动过滤中间件堆栈以删除默认的JSON解析器,而是能够通过在任何其他中间件之前配置Body-Parser中间件来使其起作用。这确保了使用自定义的身体偏好器配置。
这是这样的外观:
Instead of manually filtering the middleware stack to remove the default JSON parser, I was able to make it work by configuring the body-parser middleware before any other middleware. This ensured that the custom body-parser configuration was used.
Here's how that looked:
这对我有用:
您可以在expressappConfig函数(Express.app.config.js)填充的App._router.stack中看到所有中间件。
我发现当您使用BodyParser.json()时,它将在该堆栈中添加另一个中间件层 - 但是从我的观察中,Express将使用第一个。这就是为什么我在设置限制之前删除所有JSONPARSER的原因。
This works for me:
You can see all the middleware in app._router.stack which is populated by expressAppConfig function (express.app.config.js).
I found out when you use bodyParser.json(), it will add another middleware layer to that stack - but from my observation, express will use the first one. That's why I removed all jsonParser before setting the limit.