You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Fastify plugin for serving [Swagger (OpenAPI v2)](https://swagger.io/specification/v2/) or [OpenAPI v3](https://swagger.io/specification) schemas, which are automatically generated from your route schemas, or from an existing Swagger/OpenAPI schema.
7
+
A Fastify plugin for serving [Swagger (OpenAPI v2)](https://swagger.io/specification/v2/) or [OpenAPI v3](https://swagger.io/specification) schemas, which are automatically generated from your route schemas, or an existing Swagger/OpenAPI schema.
8
8
9
9
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).
10
10
11
-
Following plugins serve Swagger/OpenAPI front-ends based on the swagger definitions generated by this plugin:
11
+
The following plugins serve Swagger/OpenAPI front-ends based on the swagger definitions generated by this plugin:
See also [the migration guide](MIGRATION.md) for migrating from `@fastify/swagger` version <= `<=7.x` to version `>=8.x`.
16
+
See [the migration guide](MIGRATION.md) for migrating from `@fastify/swagger` version <= `<=7.x` to version `>=8.x`.
17
17
18
18
<aname="install"></a>
19
19
## Install
@@ -43,7 +43,7 @@ See [Fastify's LTS policy](https://github.com/fastify/fastify/blob/main/docs/Ref
43
43
<aname="usage"></a>
44
44
## Usage
45
45
46
-
Add it to your project with `register`, pass it some options, call the `swagger` API, and you are done! Below an example of how to configure the OpenAPI v3 specification with Fastify Swagger:
46
+
Add it to your project with `register`, pass it some options, call the `swagger` API, and you are done! Below is an example of how to configure the OpenAPI v3 specification with Fastify Swagger:
47
47
48
48
```js
49
49
constfastify=require('fastify')()
@@ -135,7 +135,7 @@ fastify.swagger()
135
135
<aname="usage.fastify.autoload"></a>
136
136
### With `@fastify/autoload`
137
137
138
-
You need to register `@fastify/swagger` before registering routes.
138
+
You need to register `@fastify/swagger` before registering routes:
139
139
140
140
```js
141
141
constfastify=require('fastify')()
@@ -205,7 +205,7 @@ Examples of using `@fastify/swagger` in `dynamic` mode:
205
205
206
206
<aname="register.options.mode.static"></a>
207
207
##### Static
208
-
`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`:
208
+
`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`:
209
209
210
210
```js
211
211
{
@@ -224,7 +224,7 @@ The `specification.postProcessor` parameter is optional. It allows you to change
224
224
It accepts `swaggerObject` - a JavaScript object that was parsed from your `yaml` or `json` file and should return a Swagger schema object.
225
225
226
226
`specification.baseDir` allows specifying the directory where all spec files that are included in the main one using `$ref` will be located.
227
-
By default, this is the directory where the main spec file is located. Provided value should be an absolute path **without** trailing slash.
227
+
By default, this is the directory where the main spec file is located. The provided value should be an absolute path **without** a trailing slash.
228
228
229
229
An example of using `@fastify/swagger` with `static` mode enabled can be found [here](examples/static-json-file.js).
230
230
@@ -246,14 +246,14 @@ An example of using `@fastify/swagger` with `static` mode enabled can be found [
246
246
<aname="register.options.transform"></a>
247
247
#### Transform
248
248
249
-
By passing a synchronous `transform` function you can modify the route's url and schema.
249
+
By passing a synchronous `transform` function you can modify the route's URL and schema.
250
250
251
251
You may also access the `openapiObject` and `swaggerObject`
252
252
253
253
Some possible uses of this are:
254
254
255
-
- add the `hide` flag on schema according to your own logic based on url & schema
256
-
- altering the route url into something that's more suitable for the api spec
255
+
- add the `hide` flag on schema according to your own logic based on URL & schema
256
+
- altering the route URL into something that is more suitable for the API spec
257
257
- using different schemas such as [Joi](https://github.com/hapijs/joi) and transforming them to standard JSON schemas expected by this plugin
258
258
- hiding routes based on version constraints
259
259
@@ -315,7 +315,7 @@ If both a global and a local transform function is available for an endpoint, th
315
315
The local transform function can be useful if you:
316
316
317
317
- want to add additional information to a specific endpoint
318
-
- have an endpoint which requires different transformation from other endpoints
318
+
- have an endpoint that requires a different transformation from other endpoints
319
319
- want to entirely ignore the global transform function for one endpoint
320
320
321
321
The endpoint-specific transform can be used to "disable" the global transform function by passing in `false` instead of a function.
When this plugin is configured as `dynamic` mode, it will resolve all `$ref`s in your application's schemas.
343
-
This process will create an new in-line schema that is going to reference itself.
343
+
This process will create a new in-line schema that is going to reference itself.
344
344
345
345
This logic step is done to make sure that the generated documentation is valid, otherwise the Swagger UI will try to fetch the schemas from the server or the network and fail.
To deep down the `buildLocalReference` arguments, you may read the [documentation](https://github.com/Eomm/json-schema-resolver#usage-resolve-one-schema-against-external-schemas).
363
+
For a deep dive into the `buildLocalReference` arguments, you may read the [documentation](https://github.com/Eomm/json-schema-resolver#usage-resolve-one-schema-against-external-schemas).
364
364
365
365
<a name="register.options.decorator"></a>
366
366
#### Decorator
@@ -642,7 +642,7 @@ As far as arrays are concerned, the default query string parser conforms to the
642
642
If you were to select `collectionFormat:"csv"`, you would have to replace the default query string parser with one that parses CSV parameter values into arrays.
643
643
The same applies to the other parts of a request that OpenAPI calls "parameters" and which are not encoded as JSON in a request.
644
644
645
-
You can also apply different serialization `style` and `explode` as specified [here](https://swagger.io/docs/specification/serialization/#query).
645
+
You can also apply a different serialization `style` and `explode` as specified [here](https://swagger.io/docs/specification/serialization/#query).
646
646
647
647
`@fastify/swagger` supports these options as shown in this example:
648
648
@@ -846,7 +846,7 @@ Will generate this in the OpenAPI v3 schema's `paths`:
846
846
}
847
847
```
848
848
849
-
Whether`params` is not present in the schema, or a schema is not provided, parameters are automatically generated, for example:
849
+
When`params` is not present in the schema, or a schema is not provided, parameters are automatically generated, for example:
850
850
851
851
```js
852
852
fastify.route({
@@ -1150,7 +1150,7 @@ fastify.route({
1150
1150
1151
1151
1152
1152
## Development
1153
-
In order to start development run:
1153
+
To start development run:
1154
1154
```
1155
1155
npm i
1156
1156
npm run prepare
@@ -1164,9 +1164,9 @@ So that [swagger-ui](https://github.com/swagger-api/swagger-ui) static folder wi
1164
1164
1165
1165
#### How to work with $refs
1166
1166
1167
-
The `/docs/json` endpoint in dynamic mode produces a single `swagger.json` file resolving all your
1167
+
The `/docs/json` endpoint in dynamic mode produces a single `swagger.json` file resolving all your references.
0 commit comments