Skip to content

Instantly share code, notes, and snippets.

@glenpike
Created April 30, 2017 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glenpike/01b896f8fdc5819019e192d26f6b3ad5 to your computer and use it in GitHub Desktop.
Save glenpike/01b896f8fdc5819019e192d26f6b3ad5 to your computer and use it in GitHub Desktop.
Serve Swagger Doc's with Koa
/* Serve a swagger doc with Koa */
const Koa = require('koa');
const koaSwagger = require('koa2-swagger-ui');
//const yaml = require('yamljs');
//const spec = yaml.load('./music-api.yml');
const app = new Koa();
app.use(koaSwagger({
routePrefix: '/swagger', // host at /swagger instead of default /docs
swaggerOptions: {
url: 'https://raw.githubusercontent.com/glenpike/music-library-api/develop/music-api.yml'
//spec: spec
},
}));
app.listen(3000);
{
"name": "koa-swagger-ui-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"koa": "^2.2.0",
"koa2-swagger-ui": "^2.3.0",
"yamljs": "^0.2.10"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment