exegesis-express
Advanced tools
Comparing version 0.2.0 to 0.2.1
{ | ||
"name": "exegesis-express", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Express middleware to handle OpenAPI 3.x.", | ||
@@ -55,3 +55,3 @@ "main": "dist/index.js", | ||
"hooks": { | ||
"commit-msg": "validate-commit-msg", | ||
"commit-msg": "commitlint -e $GIT_PARAMS", | ||
"pre-commit": "npm run precommit:test" | ||
@@ -62,3 +62,3 @@ } | ||
"@types/chai": "^4.1.3", | ||
"exegesis": "^0.2.0" | ||
"exegesis": "^0.3.1" | ||
}, | ||
@@ -68,19 +68,19 @@ "devDependencies": { | ||
"@types/mocha": "^5.2.0", | ||
"@types/node": "^6.0.0", | ||
"@types/node": "^6.0.109", | ||
"chai": "^4.1.2", | ||
"chai-as-promised": "^7.1.1", | ||
"coveralls": "^3.0.0", | ||
"commitlint": "^6.2.0", | ||
"coveralls": "^3.0.1", | ||
"express": "^4.16.3", | ||
"husky": "^1.0.0-rc.2", | ||
"lint-staged": "^7.0.5", | ||
"husky": "^1.0.0-rc.4", | ||
"lint-staged": "^7.1.0", | ||
"markdownlint": "^0.8.1", | ||
"markdownlint-cli": "^0.8.1", | ||
"mocha": "^5.1.1", | ||
"nyc": "^11.7.1", | ||
"semantic-release": "^15.1.7", | ||
"supertest-fetch": "^1.0.1", | ||
"ts-node": "^6.0.2", | ||
"tslint": "^5.9.1", | ||
"typescript": "^2.8.3", | ||
"validate-commit-msg": "^2.14.0" | ||
"nyc": "^11.7.2", | ||
"semantic-release": "^15.4.0", | ||
"supertest-fetch": "^1.0.4", | ||
"ts-node": "^6.0.3", | ||
"tslint": "^5.10.0", | ||
"typescript": "^2.8.3" | ||
}, | ||
@@ -91,3 +91,7 @@ "greenkeeper": { | ||
] | ||
}, | ||
"engines": { | ||
"node": ">=6.0.0", | ||
"npm": ">5.0.0" | ||
} | ||
} |
@@ -43,13 +43,14 @@ # exegesis-express | ||
const app = express(); | ||
// If you have any body parsers, this should go before them. | ||
app.use(exegesisMiddleware); | ||
app.use((err, req, res, _next) => { | ||
if(err) { | ||
res.writeHead(500); | ||
res.end(`Internal error: ${err.message}`); | ||
} else { | ||
res.writeHead(404); | ||
res.end(); | ||
} | ||
app.use((req, res) => { | ||
res.status(404).json({message: `Not found`}); | ||
}); | ||
app.use((err, req, res, next) => { | ||
res.status(500).json({message: `Internal error: ${err.message}`}); | ||
}); | ||
const server = http.createServer(app); | ||
@@ -60,2 +61,41 @@ server.listen(3000); | ||
## Where to put Exegesis-Express in your middleware stack | ||
Exegesis-express should appear near the top of your middleware stack, before | ||
any body parsers. This is because exegesis will take care of parsing the body | ||
for us, and it can't do that if the body has already been read. If you put | ||
a body parser ahead of exeges-express, exegesis will try to use `req.body` | ||
if it's there. | ||
## Servers section | ||
OpenAPI 3.x lets you specify what servers your API is available on. For example: | ||
```yaml | ||
servers: | ||
- url: '/api/v2' | ||
``` | ||
By default, exegesis will take 'servers' into account when routing requests, | ||
so if you have the above servers section, and a path in your API called | ||
"/users", then exegesis will only match the route if the incoming requests has | ||
the URL "/api/v2/users". | ||
If you have path templates in your servers, the variables will be available to | ||
your controllers via `context.params.server`. | ||
If you specify the `ignoreServers` option, however, exegesis will ignore the | ||
servers section, an route purely based on your paths. This lets you do | ||
something like: | ||
```js | ||
const exegesisMiddleware = await exegesisExpress.middleware( | ||
path.resolve(__dirname, './openapi.yaml'), | ||
{ignorePaths: true} | ||
); | ||
app.use('/api/v2', exegesisMiddleware); | ||
``` | ||
which means non-api paths will not even be sent to the exegesis middleware. | ||
## TODO | ||
@@ -62,0 +102,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8255
107
+ Addedexegesis@0.3.2(transitive)
- Removedexegesis@0.2.4(transitive)
- Removedjson-schema-traverse@0.3.1(transitive)
Updatedexegesis@^0.3.1