Skip to content

Commit

Permalink
Merge pull request #43 from Psychopoulet/develop
Browse files Browse the repository at this point in the history
improve packages & set default content-type
  • Loading branch information
Psychopoulet committed Mar 17, 2020
2 parents 702bf14 + 4758f42 commit 4e8cb55
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 77 deletions.
2 changes: 1 addition & 1 deletion lib/components/Orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module.exports = class Orchestrator extends MediatorUser {
return new Promise((resolve, reject) => {

if (null === SwaggerParser) {
SwaggerParser = require("swagger-parser");
SwaggerParser = require("@apidevtools/swagger-parser");
}

SwaggerParser.validate(this._descriptorFile, (err) => {
Expand Down
24 changes: 7 additions & 17 deletions lib/components/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ module.exports = class Server extends MediatorUser {
req.headers["content-length"] = parseInt(req.headers["content-length"], 10);
}

// set default content-typ
if ("string" !== typeof req.headers["content-length"]) {
req.headers["content-type"] = "application/json";
}

if (!req.pattern || !this._Descriptor.paths[req.pattern] || !this._Descriptor.paths[req.pattern][req.method]) {
return next();
}
Expand All @@ -99,7 +104,7 @@ module.exports = class Server extends MediatorUser {
this._log("info", "" +
"=> [" + req.validatedIp + "] " + req.url + " (" + req.method.toUpperCase() + ")" +
(operationId ? EOL + "operationId : " + operationId : "") +
(req.headers["content-type"] ? EOL + "content-type : " + req.headers["content-type"] : "") +
EOL + "content-type : " + req.headers["content-type"] +
(
"get" !== req.method && req.headers["content-length"] && 4 < req.headers["content-length"] ?
EOL + "content-length : " + req.headers["content-length"] : ""
Expand All @@ -112,7 +117,7 @@ module.exports = class Server extends MediatorUser {
new Promise((resolve, reject) => {

if (null === SwaggerParser) {
SwaggerParser = require("swagger-parser");
SwaggerParser = require("@apidevtools/swagger-parser");
}

SwaggerParser.validate(this._Descriptor, (err, api) => {
Expand Down Expand Up @@ -177,21 +182,6 @@ module.exports = class Server extends MediatorUser {

}

// no "Content-Type" header found
else if (null !== checkNonEmptyString(
"headers[\"content-type\"]", req.headers["content-type"], false
)) {

const result = {
"code": "MISSING_HEADER",
"message": "No \"Content-Type\" header found"
};

this._log("error", "<= [" + req.validatedIp + "] " + JSON.stringify(result));
send(req, res, result, 400, this._cors);

}

// no "Content-Length" header found
else if ("get" !== req.method && null !== checkInteger(
"headers[\"content-length\"]", req.headers["content-length"], false
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-pluginsmanager-plugin",
"version": "4.2.1",
"version": "4.2.2",
"description": "An abstract parent plugin for node-pluginsmanager",
"main": "lib/main.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -35,7 +35,7 @@
"url": "https://github.com/Psychopoulet/node-pluginsmanager-plugin/issues"
},
"dependencies": {
"swagger-parser": "~8.0.4",
"@apidevtools/swagger-parser": "~9.0.1",
"express-openapi-validate": "~0.5.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion test/utils/DescriptorUser/Descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.2",
"info": {
"title": "node-pluginsmanager-plugin",
"version": "4.2.1",
"version": "4.2.2",
"description": "An abstract parent plugin for node-pluginsmanager",
"contact": {
"name": "Sébastien VIDAL",
Expand Down
54 changes: 0 additions & 54 deletions test/utils/Server/checkBodyContentType.js

This file was deleted.

2 changes: 0 additions & 2 deletions test/utils/Server/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
const checkUrlHeaderParameters = require(join(__dirname, "checkUrlHeaderParameters.js"));

const checkBodyBasics = require(join(__dirname, "checkBodyBasics.js"));
const checkBodyContentType = require(join(__dirname, "checkBodyContentType.js"));
const checkBodyContentLength = require(join(__dirname, "checkBodyContentLength.js"));
const checkBodyParameters = require(join(__dirname, "checkBodyParameters.js"));

Expand All @@ -43,7 +42,6 @@ module.exports = function test (descriptor) {
describe("check body", () => {

checkBodyBasics(URL_API);
checkBodyContentType(URL_API);
checkBodyContentLength(URL_API);
checkBodyParameters(URL_API);

Expand Down

0 comments on commit 4e8cb55

Please sign in to comment.