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

fastify-swagger

Package Overview
Dependencies
Maintainers
7
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.14.0 to 0.15.0

4

dynamic.js

@@ -240,8 +240,6 @@ 'use strict'

Object.keys(params).forEach(p => {
const param = {}
const param = Object.assign({}, params[p])
param.name = p
param.in = 'path'
param.required = true
param.description = params[p].description
param.type = params[p].type
parameters.push(param)

@@ -248,0 +246,0 @@ })

{
"name": "fastify-swagger",
"version": "0.14.0",
"version": "0.15.0",
"description": "Generate Swagger files automatically for Fastify.",

@@ -37,3 +37,3 @@ "main": "index.js",

"swagger-parser": "^5.0.1",
"swagger-ui-dist": "3.17.6",
"swagger-ui-dist": "3.18.1",
"tap": "^12.0.0"

@@ -43,3 +43,3 @@ },

"fastify-plugin": "^1.2.0",
"fastify-static": "^0.12.0",
"fastify-static": "^0.14.0",
"js-yaml": "^3.12.0"

@@ -46,0 +46,0 @@ },

@@ -13,29 +13,36 @@ 'use strict'

if (!opts.specification.path) return next(new Error('specification.path is missing, should be path to the file'))
if (typeof opts.specification.path !== 'string') return next(new Error('specification.path is not a string'))
if (!opts.specification.path && !opts.specification.document) {
return next(new Error('both specification.path and specification.document are missing, should be path to the file or swagger document spec'))
} else if (opts.specification.path) {
if (typeof opts.specification.path !== 'string') return next(new Error('specification.path is not a string'))
if (!fs.existsSync(path.resolve(opts.specification.path))) return next(new Error(`${opts.specification.path} does not exist`))
if (!fs.existsSync(path.resolve(opts.specification.path))) return next(new Error(`${opts.specification.path} does not exist`))
const extName = path.extname(opts.specification.path).toLowerCase()
if (['.yaml', '.json'].indexOf(extName) === -1) return next(new Error("specification.path extension name is not supported, should be one from ['.yaml', '.json']"))
const extName = path.extname(opts.specification.path).toLowerCase()
if (['.yaml', '.json'].indexOf(extName) === -1) return next(new Error("specification.path extension name is not supported, should be one from ['.yaml', '.json']"))
if (opts.specification.postProcessor && typeof opts.specification.postProcessor !== 'function') return next(new Error('specification.postProcessor should be a function'))
if (opts.specification.postProcessor && typeof opts.specification.postProcessor !== 'function') return next(new Error('specification.postProcessor should be a function'))
// read
const source = fs.readFileSync(
path.resolve(opts.specification.path),
'utf8'
)
switch (extName) {
case '.yaml':
swaggerObject = yaml.safeLoad(source)
break
case '.json':
swaggerObject = JSON.parse(source)
break
}
// read
const source = fs.readFileSync(
path.resolve(opts.specification.path),
'utf8'
)
switch (extName) {
case '.yaml':
swaggerObject = yaml.safeLoad(source)
break
case '.json':
swaggerObject = JSON.parse(source)
break
}
// apply postProcessor, if one was passed as an argument
if (opts.specification.postProcessor) {
swaggerObject = opts.specification.postProcessor(swaggerObject)
// apply postProcessor, if one was passed as an argument
if (opts.specification.postProcessor) {
swaggerObject = opts.specification.postProcessor(swaggerObject)
}
} else {
if (typeof opts.specification.document !== 'object') return next(new Error('specification.document is not an object'))
swaggerObject = opts.specification.document
}

@@ -42,0 +49,0 @@

@@ -17,3 +17,3 @@ /* IMPORTANT

exports[`test/static.js TAP specification validation check works > undefined 3`] = `
Error: specification.path is missing, should be path to the file
Error: both specification.path and specification.document are missing, should be path to the file or swagger document spec
`

@@ -121,1 +121,11 @@

`
exports[`test/static.js TAP swagger route returns explicitly passed doc > undefined 1`] = `
{
"info": {
"title": "Test swagger",
"description": "testing the fastify swagger api",
"version": "0.1.0"
}
}
`

@@ -143,1 +143,39 @@ 'use strict'

})
test('swagger route returns explicitly passed doc', t => {
t.plan(3)
const fastify = Fastify()
const document = {
info: {
title: 'Test swagger',
description: 'testing the fastify swagger api',
version: '0.1.0'
}
}
fastify.register(fastifySwagger, {
mode: 'static',
specification: {
document
},
exposeRoute: true
})
// check that json is there
fastify.inject(
{
method: 'GET',
url: '/documentation/json'
},
(err, res) => {
t.error(err)
try {
var payload = JSON.parse(res.payload)
t.matchSnapshot(JSON.stringify(payload, null, 2))
t.pass('valid explicitly passed spec document')
} catch (error) {
t.fail(error)
}
}
)
})

@@ -552,1 +552,39 @@ 'use strict'

})
test('swagger json output should not omit enum part in params config', t => {
t.plan(3)
const opts = {
schema: {
params: {
type: 'object',
properties: {
enumKey: {type: 'string', enum: ['enum1', 'enum2']}
}
}
}
}
const fastify = Fastify()
fastify.register(fastifySwagger, swaggerInfo)
fastify.get('/test/:enumKey', opts, () => {})
fastify.ready(err => {
t.error(err)
const swaggerObject = fastify.swagger()
Swagger.validate(swaggerObject)
.then((api) => {
const definedPath = api.paths['/test/{enumKey}'].get
t.ok(definedPath)
t.same(definedPath.parameters, [{
in: 'path',
name: 'enumKey',
type: 'string',
enum: ['enum1', 'enum2'],
required: true
}])
})
.catch(err => {
t.error(err)
})
})
})

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