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

fastify-swagger

Package Overview
Dependencies
Maintainers
13
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 4.6.0 to 4.7.0

39

examples/dynamic-openapi.js

@@ -25,2 +25,3 @@ 'use strict'

},
hideUntagged: true,
exposeRoute: true

@@ -68,2 +69,40 @@ })

fastify.post('/some-route/:id', {
schema: {
description: 'post some data',
summary: 'qwerty',
security: [{ apiKey: [] }],
params: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'user id'
}
}
},
body: {
type: 'object',
properties: {
hello: { type: 'string' },
obj: {
type: 'object',
properties: {
some: { type: 'string' }
}
}
}
},
response: {
201: {
description: 'Succesful response',
type: 'object',
properties: {
hello: { type: 'string' }
}
}
}
}
}, (req, reply) => { reply.send({ hello: `Hello ${req.body.hello}` }) })
fastify.listen(3000, err => {

@@ -70,0 +109,0 @@ if (err) throw err

@@ -24,2 +24,3 @@ 'use strict'

},
hideUntagged: true,
exposeRoute: true

@@ -67,2 +68,40 @@ })

fastify.post('/some-route/:id', {
schema: {
description: 'post some data',
summary: 'qwerty',
security: [{ apiKey: [] }],
params: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'user id'
}
}
},
body: {
type: 'object',
properties: {
hello: { type: 'string' },
obj: {
type: 'object',
properties: {
some: { type: 'string' }
}
}
}
},
response: {
201: {
description: 'Succesful response',
type: 'object',
properties: {
hello: { type: 'string' }
}
}
}
}
}, (req, reply) => { reply.send({ hello: `Hello ${req.body.hello}` }) })
fastify.listen(3000, err => {

@@ -69,0 +108,0 @@ if (err) throw err

1

lib/mode/dynamic.js

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

hiddenTag: 'X-HIDDEN',
hideUntagged: false,
stripBasePath: true,

@@ -13,0 +14,0 @@ openapi: null,

@@ -39,4 +39,9 @@ 'use strict'

if (shouldRouteHide(schema, defOpts.hiddenTag)) continue
const shouldRouteHideOpts = {
hiddenTag: defOpts.hiddenTag,
hideUntagged: defOpts.hideUntagged
}
if (shouldRouteHide(schema, shouldRouteHideOpts)) continue
const url = normalizeUrl(route.url, defOpts.servers, defOpts.stripBasePath)

@@ -43,0 +48,0 @@

4

lib/spec/openapi/utils.js

@@ -18,2 +18,3 @@ 'use strict'

const hiddenTag = opts.hiddenTag
const hideUntagged = opts.hideUntagged
const extensions = []

@@ -37,3 +38,4 @@

hiddenTag,
extensions
extensions,
hideUntagged
}

@@ -40,0 +42,0 @@ }

@@ -39,4 +39,9 @@ 'use strict'

if (shouldRouteHide(schema, defOpts.hiddenTag)) continue
const shouldRouteHideOpts = {
hiddenTag: defOpts.hiddenTag,
hideUntagged: defOpts.hideUntagged
}
if (shouldRouteHide(schema, shouldRouteHideOpts)) continue
const url = normalizeUrl(route.url, defOpts.basePath, defOpts.stripBasePath)

@@ -43,0 +48,0 @@

@@ -22,2 +22,3 @@ 'use strict'

const hiddenTag = opts.hiddenTag
const hideUntagged = opts.hideUntagged
const extensions = []

@@ -46,3 +47,4 @@

hiddenTag,
extensions
extensions,
hideUntagged
}

@@ -49,0 +51,0 @@ }

@@ -44,9 +44,19 @@ 'use strict'

function shouldRouteHide (schema, hiddenTag) {
function shouldRouteHide (schema, opts) {
const { hiddenTag, hideUntagged } = opts
if (schema && schema.hide) {
return true
}
if (schema && schema.tags && schema.tags.includes(hiddenTag)) {
const tags = (schema && schema.tags) || []
if (tags.length === 0 && hideUntagged) {
return true
}
if (tags.includes(hiddenTag)) {
return schema.tags.includes(hiddenTag)
}
return false

@@ -53,0 +63,0 @@ }

{
"name": "fastify-swagger",
"version": "4.6.0",
"version": "4.7.0",
"description": "Serve Swagger/OpenAPI documentation for Fastify, supporting dynamic generation",

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

"swagger-parser": "^10.0.2",
"swagger-ui-dist": "3.46.0",
"swagger-ui-dist": "3.47.1",
"tap": "^15.0.1",

@@ -51,0 +51,0 @@ "tsd": "^0.14.0"

@@ -12,3 +12,3 @@ # fastify-swagger

Supports Fastify versions `>=2.0.0`. Please refer to [this branch](https://github.com/fastify/fastify-swagger/tree/1.x) and related versions for Fastify `^1.9.0` compatibility.
Supports Fastify versions `>=3.0.0`. For `fastify@2`, please refer to [`branch@2.x`](https://github.com/fastify/fastify-swagger/tree/2.x) and for `fastify@1.9`, please refer to [`branch@1.x`](https://github.com/fastify/fastify-swagger/tree/1.x).

@@ -181,2 +181,3 @@ <a name="install"></a>

| hiddenTag | X-HIDDEN | Tag to control hiding of routes. |
| hideUntagged | false | If true remove routes without tags in schema from resulting swagger file |
| stripBasePath | true | Strips base path from routes in docs. |

@@ -183,0 +184,0 @@ | swagger | {} | Swagger configuration. |

@@ -216,2 +216,35 @@ 'use strict'

test('hide support - hidden untagged', t => {
t.plan(2)
const fastify = Fastify()
fastify.register(fastifySwagger, { ...openapiOption, hideUntagged: true })
const opts = {
schema: {
body: {
type: 'object',
properties: {
hello: { type: 'string' },
obj: {
type: 'object',
properties: {
some: { type: 'string' }
}
}
}
}
}
}
fastify.get('/', opts, () => {})
fastify.ready(err => {
t.error(err)
const openapiObject = fastify.swagger()
t.notOk(openapiObject.paths['/'])
})
})
test('basePath support', t => {

@@ -218,0 +251,0 @@ t.plan(3)

@@ -389,2 +389,35 @@ 'use strict'

test('hide support - hidden untagged', t => {
t.plan(2)
const fastify = Fastify()
fastify.register(fastifySwagger, { ...swaggerOption, hideUntagged: true })
const opts = {
schema: {
body: {
type: 'object',
properties: {
hello: { type: 'string' },
obj: {
type: 'object',
properties: {
some: { type: 'string' }
}
}
}
}
}
}
fastify.get('/', opts, () => {})
fastify.ready(err => {
t.error(err)
const swaggerObject = fastify.swagger()
t.notOk(swaggerObject.paths['/'])
})
})
test('cache - json', t => {

@@ -391,0 +424,0 @@ t.plan(3)

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

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