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

@fastify/swagger

Package Overview
Dependencies
Maintainers
19
Versions
41
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 8.3.1 to 8.4.0

32

lib/util/common.js

@@ -14,7 +14,31 @@ 'use strict'

const globalExposeHeadRoutes = fastify.initialConfig.exposeHeadRoutes
fastify.addHook('onRoute', (routeOptions) => {
// we need to skip HEAD route
// since it may automatically added by fastify
// and will conflict with the existing route
if (routeOptions.method === 'HEAD') return
// fastify will generate HEAD routes if either the global `exposeHeadRoutes`
// (default behavior since https://github.com/fastify/fastify/pull/2826) or
// `exposeHeadRoute` on route level flag is `true`. If two routes with
// operationId are added to the swagger object, it is no longer valid.
// therefore we suffix the operationId with `-head`.
const hasRouteExposeHeadRouteFlag = routeOptions.exposeHeadRoute != null
const exposesHeads = hasRouteExposeHeadRouteFlag
? routeOptions.exposeHeadRoute
: globalExposeHeadRoutes
if (
routeOptions.method === 'HEAD' &&
exposesHeads === true &&
routeOptions.schema !== undefined &&
routeOptions.schema.operationId !== undefined
) {
routes.push(
Object.assign({}, routeOptions, {
schema: Object.assign({}, routeOptions.schema, {
operationId: `${routeOptions.schema.operationId}-head`
})
})
)
return
}
routes.push(routeOptions)

@@ -21,0 +45,0 @@ })

8

package.json
{
"name": "@fastify/swagger",
"version": "8.3.1",
"version": "8.4.0",
"description": "Serve Swagger/OpenAPI documentation for Fastify, supporting dynamic generation",

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

"@fastify/pre-commit": "^2.0.2",
"@types/node": "^18.0.0",
"@types/node": "^20.1.0",
"fastify": "^4.0.0",

@@ -53,3 +53,3 @@ "fluent-json-schema": "^4.0.0",

"tap": "^16.2.0",
"tsd": "^0.25.0"
"tsd": "^0.28.0"
},

@@ -61,3 +61,3 @@ "dependencies": {

"rfdc": "^1.3.0",
"yaml": "^2.1.1"
"yaml": "^2.2.2"
},

@@ -64,0 +64,0 @@ "standard": {

@@ -484,1 +484,76 @@ 'use strict'

})
test('support "exposeHeadRoute" option', async (t) => {
const fastify = Fastify({ exposeHeadRoutes: false })
await fastify.register(fastifySwagger, {
routePrefix: '/docs',
exposeRoute: true
})
fastify.get('/with-head', {
exposeHeadRoute: true,
schema: {
operationId: 'with-head',
response: {
200: {
description: 'Expected Response',
type: 'object',
properties: {
foo: { type: 'string' }
}
}
}
}
}, () => {})
await fastify.ready()
const swaggerObject = fastify.swagger()
const api = await Swagger.validate(swaggerObject)
t.same(
api.paths['/with-head'].get.responses['200'].description,
'Expected Response'
)
t.same(
api.paths['/with-head'].head.responses['200'].description,
'Expected Response'
)
})
test('support "exposeHeadRoutes" option', async (t) => {
const fastify = Fastify({ exposeHeadRoutes: true })
await fastify.register(fastifySwagger, {
routePrefix: '/docs',
exposeRoute: true
})
fastify.get('/with-head', {
schema: {
operationId: 'with-head',
response: {
200: {
description: 'Expected Response',
type: 'object',
properties: {
foo: { type: 'string' }
}
}
}
}
}, () => {})
await fastify.ready()
const swaggerObject = fastify.swagger()
const api = await Swagger.validate(swaggerObject)
t.same(
api.paths['/with-head'].get.responses['200'].description,
'Expected Response'
)
t.same(
api.paths['/with-head'].head.responses['200'].description,
'Expected Response'
)
})

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