Skip to content

Commit 7ad1deb

Browse files
committed
docs(openapi): prefer lazy over eager creation of the document
1 parent d2defc2 commit 7ad1deb

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(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 return of `SwaggerModule#createDocument()` 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

@@ -126,7 +126,7 @@ const options: SwaggerDocumentOptions = {
126126
methodKey: string
127127
) => methodKey
128128
};
129-
const document = SwaggerModule.createDocument(app, config, options);
129+
const documentFactory = () => SwaggerModule.createDocument(app, config, options);
130130
```
131131

132132
#### Setup options

content/openapi/other-features.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ async function bootstrap() {
4747
.addTag('cats')
4848
.build();
4949

50-
const catDocument = SwaggerModule.createDocument(app, options, {
50+
const catDocumentFactory = () => SwaggerModule.createDocument(app, options, {
5151
include: [CatsModule],
5252
});
53-
SwaggerModule.setup('api/cats', app, catDocument);
53+
SwaggerModule.setup('api/cats', app, catDocumentFactory);
5454

5555
const secondOptions = new DocumentBuilder()
5656
.setTitle('Dogs example')
@@ -59,10 +59,10 @@ async function bootstrap() {
5959
.addTag('dogs')
6060
.build();
6161

62-
const dogDocument = SwaggerModule.createDocument(app, secondOptions, {
62+
const dogDocumentFactory = () => SwaggerModule.createDocument(app, secondOptions, {
6363
include: [DogsModule],
6464
});
65-
SwaggerModule.setup('api/dogs', app, dogDocument);
65+
SwaggerModule.setup('api/dogs', app, dogDocumentFactory);
6666

6767
await app.listen(3000);
6868
}

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)