Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-swagger

Package Overview
Dependencies
Maintainers
6
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-swagger - npm Package Compare versions

Comparing version 0.6.1 to 0.7.0

prepare-swagger-ui.js

2

examples/dynamic.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc