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.3.1 to 0.3.2

115

index.js

@@ -11,2 +11,8 @@ 'use strict'

const routes = []
fastify.addHook('onRoute', (routeOptions) => {
routes.push(routeOptions)
})
opts = opts || {}

@@ -70,75 +76,63 @@ opts.swagger = opts.swagger || {}

swaggerObject.paths = {}
for (var route of routes) {
const url = formatParamUrl(route.url)
const method = route.method.toLowerCase()
const schema = route.schema
for (var node of fastify) {
// The node path name
const url = formatParamUrl(Object.keys(node)[0])
// object with all the methods of the node
const routes = node[Object.keys(node)[0]]
const swaggerRoute = {}
swaggerRoute[url] = {}
const swaggerRoute = swaggerObject.paths[url] || {}
// let's iterate over the methods
const methods = Object.keys(routes)
for (var i = 0, len = methods.length; i < len; i++) {
const method = methods[i]
const route = routes[method]
const schema = route.schema
if (schema && schema.hide) {
continue
}
if (schema && schema.hide) {
if (len === 1) delete swaggerRoute[url]
continue
const swaggerMethod = swaggerRoute[method] = {}
const parameters = []
// All the data the user can give us, is via the schema object
if (schema) {
// the resulting schema will be in this order
if (schema.summary) {
swaggerMethod.summary = schema.summary
}
swaggerRoute[url][method] = {}
const parameters = []
if (schema.description) {
swaggerMethod.description = schema.description
}
// All the data the user can give us, is via the schema object
if (schema) {
// the resulting schema will be in this order
if (schema.summary) {
swaggerRoute[url][method].summary = schema.summary
}
if (schema.tags) {
swaggerMethod.tags = schema.tags
}
if (schema.description) {
swaggerRoute[url][method].description = schema.description
}
if (schema.querystring) {
getQueryParams(parameters, schema.querystring)
}
if (schema.tags) {
swaggerRoute[url][method].tags = schema.tags
}
if (schema.body) {
getBodyParams(parameters, schema.body)
}
if (schema.querystring) {
getQueryParams(parameters, schema.querystring)
}
if (schema.params) {
getPathParams(parameters, schema.params)
}
if (schema.body) {
getBodyParams(parameters, schema.body)
}
if (schema.headers) {
getHeaderParams(parameters, schema.headers)
}
if (schema.params) {
getPathParams(parameters, schema.params)
}
if (parameters.length) {
swaggerMethod.parameters = parameters
}
if (schema.headers) {
getHeaderParams(parameters, schema.headers)
}
if (schema.deprecated) {
swaggerMethod.deprecated = schema.deprecated
}
if (parameters.length) {
swaggerRoute[url][method].parameters = parameters
}
if (schema.deprecated) {
swaggerRoute[url][method].deprecated = schema.deprecated
}
if (schema.security) {
swaggerRoute[url][method].security = schema.security
}
if (schema.security) {
swaggerMethod.security = schema.security
}
swaggerRoute[url][method].responses = genResponse(schema ? schema.response : null)
}
if (swaggerRoute[url]) {
swaggerObject.paths[url] = swaggerRoute[url]
swaggerMethod.responses = genResponse(schema ? schema.response : null)
if (swaggerRoute) {
swaggerObject.paths[url] = swaggerRoute
}

@@ -148,3 +142,3 @@ }

if (opts && opts.yaml) {
const swaggerString = yaml.safeDump(swaggerObject)
const swaggerString = yaml.safeDump(swaggerObject, { skipInvalid: true })
cache.swaggerString = swaggerString

@@ -270,2 +264,5 @@ return swaggerString

module.exports = fp(fastifySwagger, '>=0.14.0')
module.exports = fp(fastifySwagger, {
fastify: '>=0.39.0',
name: 'fastify-swagger'
})
{
"name": "fastify-swagger",
"version": "0.3.1",
"version": "0.3.2",
"description": "Generate Swagger files automatically for Fastify.",

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

"devDependencies": {
"fastify": "^0.39.0",
"fastify": "^0.43.0",
"standard": "^10.0.3",

@@ -27,0 +27,0 @@ "swagger-parser": "^4.0.1",

@@ -93,2 +93,15 @@ 'use strict'

const opts5 = {
schema: {
params: {
type: 'object',
properties: {
id: {
type: 'string'
}
}
}
}
}
test('/documentation/json route', t => {

@@ -137,2 +150,3 @@ t.plan(2)

fastify.get('/example1', opts4, () => {})
fastify.get('/parametersWithoutDesc/:id', opts5, () => {})

@@ -139,0 +153,0 @@ fastify.inject({

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