Socket
Socket
Sign inDemoInstall

@fastify/swagger

Package Overview
Dependencies
Maintainers
19
Versions
38
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 7.4.1 to 7.5.0

test/types/swagger-ui-vendor-extensions.test.ts

11

examples/collection-format.js
'use strict'
const fastify = require('fastify')()
const fastify = require('fastify')({
// Need to add a collectionFormat keyword to ajv in fastify instance
ajv: {
customOptions: {
keywords: ['collectionFormat']
}
}
})

@@ -42,5 +49,5 @@ fastify.register(require('../index'), {

fastify.listen(0, (err, addr) => {
fastify.listen({ port: 3000 }, (err, addr) => {
if (err) throw err
console.log(`listening on ${addr}`)
})
import {FastifyPluginCallback, FastifySchema, onRequestHookHandler, preHandlerHookHandler} from 'fastify';
import { OpenAPI, OpenAPIV2, OpenAPIV3 } from 'openapi-types';
/**
* Swagger-UI Vendor Extensions
* @see https://support.smartbear.com/swaggerhub/docs/apis/vendor-extensions.html#api-docs-x-tokenname
*/
declare module 'openapi-types' {
namespace OpenAPIV3 {
interface OAuth2SecurityScheme {
'x-tokenName'?: string;
}
}
namespace OpenAPIV2 {
interface SecuritySchemeOauth2Base {
'x-tokenName'?: string;
}
}
}
declare module 'fastify' {

@@ -93,2 +110,3 @@ interface FastifyInstance {

supportedSubmitMethods: Array<'get' | 'post' | 'put' | 'delete' | 'patch' | 'options'>
persistAuthorization: boolean
}>

@@ -95,0 +113,0 @@

6

lib/mode/static.js

@@ -5,3 +5,3 @@ 'use strict'

const fs = require('fs')
const yaml = require('js-yaml')
const yaml = require('yaml')

@@ -43,3 +43,3 @@ module.exports = function (fastify, opts, done) {

case '.yaml':
swaggerObject = yaml.load(source)
swaggerObject = yaml.parse(source)
break

@@ -90,3 +90,3 @@ case '.json':

if (opts && opts.yaml) {
const swaggerString = yaml.dump(swaggerObject, { skipInvalid: true })
const swaggerString = yaml.stringify(swaggerObject, { strict: false })
cache.swaggerString = swaggerString

@@ -93,0 +93,0 @@ return swaggerString

'use strict'
const yaml = require('js-yaml')
const yaml = require('yaml')
const { shouldRouteHide } = require('../../util/common')

@@ -68,3 +68,3 @@ const { prepareDefaultOptions, prepareOpenapiObject, prepareOpenapiMethod, prepareOpenapiSchemas, normalizeUrl } = require('./utils')

if (opts && opts.yaml) {
cache.string = yaml.dump(openapiObject, { skipInvalid: true })
cache.string = yaml.stringify(openapiObject, { strict: false })
return cache.string

@@ -71,0 +71,0 @@ }

'use strict'
const yaml = require('js-yaml')
const yaml = require('yaml')
const { shouldRouteHide } = require('../../util/common')

@@ -63,3 +63,3 @@ const { prepareDefaultOptions, prepareSwaggerObject, prepareSwaggerMethod, normalizeUrl, prepareSwaggerDefinitions } = require('./utils')

if (opts && opts.yaml) {
cache.string = yaml.dump(swaggerObject, { skipInvalid: true })
cache.string = yaml.stringify(swaggerObject, { strict: false })
return cache.string

@@ -66,0 +66,0 @@ }

@@ -82,4 +82,4 @@ const fs = require('fs')

function computeCSPHashes (path) {
const scriptRegex = /<script>(.*)<\/script>/gs
const styleRegex = /<style>(.*)<\/style>/gs
const scriptRegex = /<script>(.*)<\/script>/gis
const styleRegex = /<style>(.*)<\/style>/gis
const indexSrc = fs.readFileSync(resolve(path)).toString('utf8')

@@ -86,0 +86,0 @@ let result = scriptRegex.exec(indexSrc)

{
"name": "@fastify/swagger",
"version": "7.4.1",
"version": "7.5.0",
"description": "Serve Swagger/OpenAPI documentation for Fastify, supporting dynamic generation",

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

"@fastify/helmet": "^9.0.0",
"@fastify/pre-commit": "^2.0.2",
"@types/node": "^18.0.0",

@@ -55,16 +56,15 @@ "fastify": "^4.0.0",

"joi-to-json": "^2.2.4",
"pre-commit": "^1.2.2",
"qs": "^6.10.3",
"standard": "^17.0.0",
"swagger-ui-dist": "4.12.0",
"swagger-ui-dist": "4.14.0",
"tap": "^16.2.0",
"tsd": "^0.21.0"
"tsd": "^0.23.0"
},
"dependencies": {
"@fastify/static": "^6.0.0",
"fastify-plugin": "^3.0.1",
"js-yaml": "^4.1.0",
"fastify-plugin": "^4.0.0",
"json-schema-resolver": "^1.3.0",
"openapi-types": "^11.0.0",
"rfdc": "^1.3.0"
"openapi-types": "^12.0.0",
"rfdc": "^1.3.0",
"yaml": "^2.1.1"
},

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

@@ -9,4 +9,8 @@ # @fastify/swagger

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).
Supports Fastify versions `4.x`.
- Please refer to [6.x](https://github.com/fastify/fastify-swagger/tree/6.x) for Fastify `^3.x` compatibility.
- Please refer to [3.x](https://github.com/fastify/fastify-swagger/tree/2.x) for Fastify `^2.x` compatibility.
- Please refer to [1.x](https://github.com/fastify/fastify-swagger/tree/1.x) for Fastify `^1.x` compatibility.
If you are looking for a plugin to generate routes from an existing OpenAPI schema, check out [fastify-openapi-glue](https://github.com/seriousme/fastify-openapi-glue).

@@ -17,3 +21,3 @@

```
npm i @fastify/swagger --save
npm i @fastify/swagger
```

@@ -489,2 +493,11 @@

```js
// Need to add a collectionFormat keyword to ajv in fastify instance
const fastify = Fastify({
ajv: {
customOptions: {
keywords: ['collectionFormat']
}
}
})
fastify.route({

@@ -491,0 +504,0 @@ method: 'GET',

@@ -1,1 +0,1 @@

{"script":["'sha256-g6TK8Crx7YtGVUN10j0q8wD3cvwyzlvBMzQx4UjBPg4='"],"style":[]}
{"script":["'sha256-4IiDsMH+GkJlxivIDNfi6qk0O5HPtzyvNwVT3Wt8TIw='"],"style":[]}

@@ -5,3 +5,3 @@ 'use strict'

const Fastify = require('fastify')
const yaml = require('js-yaml')
const yaml = require('yaml')

@@ -53,3 +53,3 @@ const fastifySwagger = require('../index')

try {
yaml.load(res.payload)
yaml.parse(res.payload)
t.pass('valid swagger yaml')

@@ -70,3 +70,3 @@ } catch (err) {

try {
yaml.load(res.payload)
yaml.parse(res.payload)
t.pass('valid swagger json')

@@ -73,0 +73,0 @@ } catch (err) {

@@ -8,3 +8,3 @@ 'use strict'

const fastifySwaggerDynamic = require('../../lib/mode/dynamic')
const yaml = require('js-yaml')
const yaml = require('yaml')
const Swagger = require('@apidevtools/swagger-parser')

@@ -143,3 +143,3 @@

t.equal(res.headers['content-type'], 'application/x-yaml')
yaml.load(res.payload)
yaml.parse(res.payload)
t.pass('valid swagger yaml')

@@ -169,3 +169,3 @@ })

t.equal(res.headers['content-type'], 'application/json; charset=utf-8')
yaml.load(res.payload)
yaml.parse(res.payload)
t.pass('valid swagger json')

@@ -199,3 +199,3 @@ })

t.equal(res.headers['content-type'], 'application/x-yaml')
yaml.load(res.payload)
yaml.parse(res.payload)
t.matchSnapshot(res.payload)

@@ -382,3 +382,3 @@ t.pass('valid swagger yaml')

t.equal(res.headers['content-type'], 'application/x-yaml')
yaml.load(res.payload)
yaml.parse(res.payload)
t.pass('valid swagger yaml')

@@ -395,3 +395,3 @@ }

t.equal(res.headers['content-type'], 'application/x-yaml')
yaml.load(res.payload)
yaml.parse(res.payload)
t.pass('valid swagger yaml')

@@ -457,3 +457,3 @@ }

t.equal(res.headers['content-type'], 'application/x-yaml')
yaml.load(res.payload)
yaml.parse(res.payload)
t.pass('valid swagger yaml')

@@ -470,3 +470,3 @@ }

t.equal(res.headers['content-type'], 'application/x-yaml')
yaml.load(res.payload)
yaml.parse(res.payload)
t.pass('valid swagger yaml')

@@ -473,0 +473,0 @@ }

@@ -7,3 +7,3 @@ 'use strict'

const Swagger = require('@apidevtools/swagger-parser')
const yaml = require('js-yaml')
const yaml = require('yaml')
const fastifySwagger = require('../index')

@@ -168,3 +168,3 @@ const {

t.equal(res.headers['content-type'], 'application/x-yaml')
yaml.load(res.payload)
yaml.parse(res.payload)
t.pass('valid swagger yaml')

@@ -171,0 +171,0 @@ })

@@ -6,3 +6,3 @@ 'use strict'

const Swagger = require('@apidevtools/swagger-parser')
const yaml = require('js-yaml')
const yaml = require('yaml')
const fastifySwagger = require('../../../index')

@@ -322,3 +322,3 @@ const { readPackageJson } = require('../../../lib/util/common')

t.equal(typeof swaggerYaml, 'string')
yaml.load(swaggerYaml)
yaml.parse(swaggerYaml)
t.pass('valid swagger yaml')

@@ -325,0 +325,0 @@ })

@@ -6,3 +6,3 @@ 'use strict'

const Swagger = require('@apidevtools/swagger-parser')
const yaml = require('js-yaml')
const yaml = require('yaml')
const fastifySwagger = require('../../../index')

@@ -68,3 +68,3 @@ const {

t.equal(typeof swaggerYaml, 'string')
yaml.load(swaggerYaml)
yaml.parse(swaggerYaml)
t.pass('valid swagger yaml')

@@ -71,0 +71,0 @@ })

@@ -6,3 +6,3 @@ 'use strict'

const Swagger = require('@apidevtools/swagger-parser')
const yaml = require('js-yaml')
const yaml = require('yaml')
const fastifySwagger = require('../../../index')

@@ -419,3 +419,3 @@ const { readPackageJson } = require('../../../lib/util/common')

t.equal(typeof swaggerYaml, 'string')
yaml.load(swaggerYaml)
yaml.parse(swaggerYaml)
t.pass('valid swagger yaml')

@@ -422,0 +422,0 @@ })

@@ -6,3 +6,3 @@ 'use strict'

const Swagger = require('@apidevtools/swagger-parser')
const yaml = require('js-yaml')
const yaml = require('yaml')
const fastifySwagger = require('../../../index')

@@ -64,3 +64,3 @@ const {

t.equal(typeof swaggerYaml, 'string')
yaml.load(swaggerYaml)
yaml.parse(swaggerYaml)
t.pass('valid swagger yaml')

@@ -67,0 +67,0 @@ })

@@ -18,2 +18,3 @@ import fastify from 'fastify';

supportedSubmitMethods: ['get'],
persistAuthorization: false,
};

@@ -20,0 +21,0 @@ const initOAuth: FastifySwaggerInitOAuthOptions = {

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

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