Skip to content

Commit 5e49051

Browse files
Merge branch 'master' of https://github.com/nestjs/docs.nestjs.com; branch 'feat/lazy-swagger' of https://github.com/h4ad-forks/docs.nestjs.com into h4ad-forks-feat/lazy-swagger
2 parents c6a6c99 + 941126b commit 5e49051

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

content/openapi/introduction.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ async function bootstrap() {
2929
.setVersion('1.0')
3030
.addTag('cats')
3131
.build();
32-
const document = SwaggerModule.createDocument(app, config);
33-
SwaggerModule.setup('api', app, document);
32+
const documentFactory = () => SwaggerModule.createDocument(app, config);
33+
SwaggerModule.setup('api', app, documentFactory);
3434

3535
await app.listen(process.env.PORT ?? 3000);
3636
}
3737
bootstrap();
3838
```
3939

40-
> info **Hint** `document` (returned by the `SwaggerModule#createDocument()` method) is a serializable object conforming to [OpenAPI Document](https://swagger.io/specification/#openapi-document). Instead of hosting it via HTTP, you could also save it as a JSON/YAML file, and consume it in different ways.
40+
> info **Hint** The factory around `SwaggerModule#createDocument()` is only used to create the document when you actually request Swagger, saving some initialization time and is a serializable object conforming to [OpenAPI Document](https://swagger.io/specification/#openapi-document). Instead of hosting it via HTTP, you could also save it as a JSON/YAML file, and consume it in different ways.
4141
4242
The `DocumentBuilder` helps to structure a base document that conforms to the OpenAPI Specification. It provides several methods that allow setting such properties as title, description, version, etc. In order to create a full document (with all HTTP routes defined) we use the `createDocument()` method of the `SwaggerModule` class. This method takes two arguments, an application instance and a Swagger options object. Alternatively, we can provide a third argument, which should be of type `SwaggerDocumentOptions`. More on this in the [Document options section](/openapi/introduction#document-options).
4343

@@ -135,7 +135,7 @@ const options: SwaggerDocumentOptions = {
135135
methodKey: string
136136
) => methodKey
137137
};
138-
const document = SwaggerModule.createDocument(app, config, options);
138+
const documentFactory = () => SwaggerModule.createDocument(app, config, options);
139139
```
140140
141141
#### Setup options

content/openapi/other-features.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ async function bootstrap() {
5858
.addTag('cats')
5959
.build();
6060

61-
const catDocument = SwaggerModule.createDocument(app, options, {
61+
const catDocumentFactory = () => SwaggerModule.createDocument(app, options, {
6262
include: [CatsModule],
6363
});
64-
SwaggerModule.setup('api/cats', app, catDocument);
64+
SwaggerModule.setup('api/cats', app, catDocumentFactory);
6565

6666
const secondOptions = new DocumentBuilder()
6767
.setTitle('Dogs example')
@@ -70,10 +70,10 @@ async function bootstrap() {
7070
.addTag('dogs')
7171
.build();
7272

73-
const dogDocument = SwaggerModule.createDocument(app, secondOptions, {
73+
const dogDocumentFactory = () => SwaggerModule.createDocument(app, secondOptions, {
7474
include: [DogsModule],
7575
});
76-
SwaggerModule.setup('api/dogs', app, dogDocument);
76+
SwaggerModule.setup('api/dogs', app, dogDocumentFactory);
7777

7878
await app.listen(process.env.PORT ?? 3000);
7979
}

content/openapi/types-and-parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export class CreateCatDto {}
251251
Alternatively, you can pass an options object with the `extraModels` property specified to the `SwaggerModule#createDocument()` method, as follows:
252252

253253
```typescript
254-
const document = SwaggerModule.createDocument(app, options, {
254+
const documentFactory = () => SwaggerModule.createDocument(app, options, {
255255
extraModels: [ExtraModel],
256256
});
257257
```

0 commit comments

Comments
 (0)