Skip to content

Commit 4b91ac4

Browse files
committed
add swagger.json and swagger-ui documentation
1 parent 186bee3 commit 4b91ac4

File tree

5 files changed

+1069
-3
lines changed

5 files changed

+1069
-3
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Feel free to contribute to build a fully working [JSON API](http://jsonapi.org/)
77

88
## Installation
99

10-
1. Clone repo
10+
1. `git clone https://github.com/danivek/json-api-express.git`
1111
2. `npm install`
1212
3. `npm start`
13-
4. Browse http://localhost:8080
13+
4. Browse http://localhost:8080/docs
1414

1515
## Usage
1616

@@ -26,6 +26,8 @@ Try some endpoints :
2626
* http://localhost:8080/tags
2727
* ...
2828

29+
Or explore api endpoints with swagger-ui at : http://localhost:8080/docs
30+
2931
## Features
3032
* [Sparse Fieldsets](http://jsonapi.org/format/#fetching-sparse-fieldsets)
3133
* [Sorting](http://jsonapi.org/format/#fetching-sorting)

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"json-api-serializer": "^0.3.0",
1616
"lodash": "^4.6.1",
1717
"mongoose": "^4.4.6",
18-
"qs": "^6.1.0"
18+
"qs": "^6.1.0",
19+
"swagger-ui": "^2.1.4"
1920
}
2021
}

src/docs/docs.routes.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
var express = require('express');
2+
3+
var router = express.Router();
4+
5+
router.use('/docs', function(req, res, next) {
6+
if (!req.query.url) {
7+
return res.redirect(301, '?url=/docs/swagger.json');
8+
}
9+
next();
10+
});
11+
router.use('/docs', express.static(__dirname + '/../../node_modules/swagger-ui/dist'));
12+
router.get('/docs/swagger.json', function(req, res, next) {
13+
res.json(require('./swagger.json'));
14+
})
15+
16+
module.exports = router;

0 commit comments

Comments
 (0)