fastify-swagger
Advanced tools
Comparing version 0.6.1 to 0.7.0
@@ -5,3 +5,3 @@ 'use strict' | ||
fastify.register(require('./index'), { | ||
fastify.register(require('../index'), { | ||
swagger: { | ||
@@ -8,0 +8,0 @@ info: { |
{ | ||
"name": "fastify-swagger", | ||
"version": "0.6.1", | ||
"version": "0.7.0", | ||
"description": "Generate Swagger files automatically for Fastify.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "standard && tap test/*.js" | ||
"prepare:swagger-ui": "node prepare-swagger-ui", | ||
"test": "standard && tap test/*.js", | ||
"prepublish": "npm run prepare:swagger-ui" | ||
}, | ||
@@ -25,9 +27,12 @@ "repository": { | ||
"fastify": "^1.1.1", | ||
"fs-extra": "^5.0.0", | ||
"standard": "^11.0.0", | ||
"swagger-parser": "^4.0.2", | ||
"tap": "^11.1.0" | ||
"swagger-ui-dist": "3.13.0", | ||
"tap": "^11.1.3" | ||
}, | ||
"dependencies": { | ||
"fastify-plugin": "^0.2.2", | ||
"js-yaml": "^3.10.0" | ||
"fastify-static": "^0.8.0", | ||
"js-yaml": "^3.11.0" | ||
}, | ||
@@ -34,0 +39,0 @@ "standard": { |
# fastify-swagger | ||
[![Greenkeeper badge](https://badges.greenkeeper.io/fastify/fastify-swagger.svg)](https://greenkeeper.io/) | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/) [![Build Status](https://travis-ci.org/fastify/fastify-swagger.svg?branch=master)](https://travis-ci.org/fastify/fastify-swagger) | ||
@@ -155,2 +157,12 @@ | ||
<a name="development"></a> | ||
### Development | ||
In order to start development run: | ||
``` | ||
npm i | ||
npm run prepare:swagger-ui | ||
``` | ||
So that [swagger-ui](https://github.com/swagger-api/swagger-ui) static folder will be generated for you. | ||
<a name="anknowledgements"></a> | ||
@@ -157,0 +169,0 @@ ## Acknowledgements |
'use strict' | ||
const fp = require('fastify-plugin') | ||
const readFileSync = require('fs').readFileSync | ||
const resolve = require('path').resolve | ||
const files = { | ||
'index.html': {type: 'text/html'}, | ||
'oauth2-redirect.html': {type: 'text/html'}, | ||
'swagger-ui.css': {type: 'text/css'}, | ||
'swagger-ui.css.map': {type: 'application/json'}, | ||
'swagger-ui-bundle.js': {type: 'application/javascript'}, | ||
'swagger-ui-bundle.js.map': {type: 'application/json'}, | ||
'swagger-ui-standalone-preset.js': {type: 'application/javascript'}, | ||
'swagger-ui-standalone-preset.js.map': {type: 'application/json'} | ||
} | ||
Object.keys(files).forEach(filename => { | ||
files[filename].contents = readFileSync(resolve(__dirname, 'static', filename), 'utf8') | ||
}) | ||
function fastifySwagger (fastify, opts, next) { | ||
@@ -46,24 +31,11 @@ fastify.route({ | ||
schema: { hide: true }, | ||
handler: (request, reply) => reply.redirect(request.raw.url + '/') | ||
handler: (request, reply) => reply.redirect('./documentation/') | ||
}) | ||
fastify.route({ | ||
url: '/documentation/:file', | ||
method: 'GET', | ||
schema: { hide: true }, | ||
handler: sendStaticFiles | ||
// serve swagger-ui with the help of fastify-static | ||
fastify.register(require('fastify-static'), { | ||
root: resolve('./static'), | ||
prefix: `/documentation/` | ||
}) | ||
function sendStaticFiles (req, reply) { | ||
if (!req.params.file) { | ||
const file = files['index.html'] | ||
reply.type(file.type).send(file.contents) | ||
} else if (files.hasOwnProperty(req.params.file)) { | ||
const file = files[req.params.file] | ||
reply.type(file.type).send(file.contents) | ||
} else { | ||
return reply.code(404).send(new Error('Not found')) | ||
} | ||
} | ||
next() | ||
@@ -70,0 +42,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
19490549
178
3
6
23
10182
+ Addedfastify-static@^0.8.0
+ Addeddebug@2.6.9(transitive)
+ Addeddepd@1.1.2(transitive)
+ Addeddestroy@1.0.4(transitive)
+ Addedee-first@1.1.1(transitive)
+ Addedencodeurl@1.0.2(transitive)
+ Addedescape-html@1.0.3(transitive)
+ Addedetag@1.8.1(transitive)
+ Addedfastify-static@0.8.0(transitive)
+ Addedfresh@0.5.2(transitive)
+ Addedhttp-errors@1.6.3(transitive)
+ Addedinherits@2.0.3(transitive)
+ Addedmime@1.4.1(transitive)
+ Addedms@2.0.0(transitive)
+ Addedon-finished@2.3.0(transitive)
+ Addedrange-parser@1.2.1(transitive)
+ Addedsend@0.16.2(transitive)
+ Addedsetprototypeof@1.1.0(transitive)
+ Addedstatuses@1.4.0(transitive)
Updatedjs-yaml@^3.11.0