Socket
Socket
Sign inDemoInstall

@fastify/swagger

Package Overview
Dependencies
45
Maintainers
17
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 6.0.0 to 6.0.1

4

lib/routes.js
'use strict'
const path = require('path')
const fastifyStatic = require('fastify-static')
const fastifyStatic = require('@fastify/static')

@@ -117,3 +117,3 @@ // URI prefix to separate static assets for swagger UI

// serve swagger-ui with the help of fastify-static
// serve swagger-ui with the help of @fastify/static
fastify.register(fastifyStatic, {

@@ -120,0 +120,0 @@ root: path.join(__dirname, '..', 'static'),

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

@@ -58,7 +58,7 @@ "main": "index.js",

"tap": "^16.0.0",
"tsd": "^0.19.0"
"tsd": "^0.20.0"
},
"dependencies": {
"@fastify/static": "^5.0.0",
"fastify-plugin": "^3.0.0",
"fastify-static": "^4.0.0",
"js-yaml": "^4.0.0",

@@ -65,0 +65,0 @@ "json-schema-resolver": "^1.3.0",

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

# fastify-swagger
# @fastify/swagger
[![NPM version](https://img.shields.io/npm/v/fastify-swagger.svg?style=flat)](https://www.npmjs.com/package/fastify-swagger)
[![NPM version](https://img.shields.io/npm/v/@fastify/swagger.svg?style=flat)](https://www.npmjs.com/package/@fastify/swagger)
![CI workflow](https://github.com/fastify/fastify-swagger/workflows/CI%20workflow/badge.svg)

@@ -17,3 +17,3 @@ [![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-swagger/badge.svg)](https://snyk.io/test/github/fastify/fastify-swagger)

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

@@ -28,3 +28,3 @@

fastify.register(require('fastify-swagger'), {
fastify.register(require('@fastify/swagger'), {
routePrefix: '/documentation',

@@ -145,7 +145,7 @@ swagger: {

#### Modes
`fastify-swagger` supports two registration modes `dynamic` and `static`:
`@fastify/swagger` supports two registration modes `dynamic` and `static`:
<a name="register.options.mode.dynamic"></a>
##### Dynamic
`dynamic` is the default mode, if you use `fastify-swagger` this way API schemas will be auto-generated from route schemas:
`dynamic` is the default mode, if you use `@fastify/swagger` this way API schemas will be auto-generated from route schemas:
```js

@@ -186,6 +186,6 @@ // All of the below parameters are optional but are included for demonstration purposes

All properties detailed in the [Swagger (OpenAPI v2)](https://swagger.io/specification/v2/) and [OpenAPI v3](https://swagger.io/specification/) specifications can be used.
`fastify-swagger` will generate API schemas that adhere to the Swagger specification by default.
`@fastify/swagger` will generate API schemas that adhere to the Swagger specification by default.
If provided an `openapi` option it will generate OpenAPI compliant API schemas instead.
Examples of using `fastify-swagger` in `dynamic` mode:
Examples of using `@fastify/swagger` in `dynamic` mode:
- [Using the `swagger` option](examples/dynamic-swagger.js)

@@ -196,3 +196,3 @@ - [Using the `openapi` option](examples/dynamic-openapi.js)

##### Static
`static` mode must be configured explicitly. In this mode `fastify-swagger` serves an already existing Swagger or OpenAPI schema that is passed to it in `specification.path`:
`static` mode must be configured explicitly. In this mode `@fastify/swagger` serves an already existing Swagger or OpenAPI schema that is passed to it in `specification.path`:

@@ -218,3 +218,3 @@ ```js

An example of using `fastify-swagger` with `static` mode enabled can be found [here](examples/static-json-file.js).
An example of using `@fastify/swagger` with `static` mode enabled can be found [here](examples/static-json-file.js).

@@ -267,3 +267,3 @@ #### Options

fastify.register(require('fastify-swagger'), {
fastify.register(require('@fastify/swagger'), {
swagger: { ... },

@@ -313,3 +313,3 @@ transform: ({ schema, url }) => {

```js
fastify.register(require('fastify-swagger'), {
fastify.register(require('@fastify/swagger'), {
swagger: { ... },

@@ -413,3 +413,3 @@ ...

Fastify supports both the `2xx` and `3xx` status codes, however Swagger (OpenAPI v2) itself does not.
`fastify-swagger` transforms `2xx` status codes into `200`, but will omit it if a `200` status code has already been declared.
`@fastify/swagger` transforms `2xx` status codes into `200`, but will omit it if a `200` status code has already been declared.
OpenAPI v3 [supports the `2xx` syntax](https://swagger.io/specification/#http-codes) so is unaffected.

@@ -463,3 +463,3 @@

##### Empty Body Responses
Empty body responses are supported by `fastify-swagger`.
Empty body responses are supported by `@fastify/swagger`.
Please specify `type: 'null'` for the response otherwise Fastify itself will fail to compile the schema:

@@ -497,3 +497,3 @@

`fastify-swagger` supports these options as shown in this example:
`@fastify/swagger` supports these options as shown in this example:

@@ -692,6 +692,6 @@ ```js

You can protect your documentation by configuring an authentication hook.
Here is an example using the [`fastify-basic-auth`](https://github.com/fastify/fastify-basic-auth) plugin:
Here is an example using the [`@fastify/basic-auth`](https://github.com/fastify/fastify-basic-auth) plugin:
```js
await fastify.register(require('fastify-basic-auth'), {
await fastify.register(require('@fastify/basic-auth'), {
validate (username, password, req, reply, done) {

@@ -718,3 +718,3 @@ if (username === 'admin' && password === 'admin') {

Registering `fastify-swagger` decorates the fastify instance with `fastify.swagger()`, which returns a JSON object representing the API.
Registering `@fastify/swagger` decorates the fastify instance with `fastify.swagger()`, which returns a JSON object representing the API.
If `{ yaml: true }` is passed to `fastify.swagger()` it will return a YAML string.

@@ -724,5 +724,5 @@

### Integration
You can integration this plugin with ```fastify-helmet``` with some little work.
You can integration this plugin with ```@fastify/helmet``` with some little work.
```fastify-helmet``` options example:
```@fastify/helmet``` options example:
```javascript

@@ -761,3 +761,3 @@ .register(helmet, instance => {

`fastify-static` serves `swagger-ui` static files, then calls `/docs/json` to get the Swagger file and render it.
`@fastify/static` serves `swagger-ui` static files, then calls `/docs/json` to get the Swagger file and render it.

@@ -764,0 +764,0 @@ #### How to work with $refs

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc