Skip to content

Commit

Permalink
Merge branch 'h4ad-forks-feat/lazy-swagger'
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Oct 17, 2024
2 parents c6a6c99 + 13da8e0 commit 48ae33d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions content/openapi/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ async function bootstrap() {
.setVersion('1.0')
.addTag('cats')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
const documentFactory = () => SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, documentFactory);

await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
```

> 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.
> info **Hint** The factory method `SwaggerModule#createDocument()` is used specifically to generate the Swagger document when you request it. This approach helps save some initialization time, and the resulting document is a serializable object that conforms to the [OpenAPI Document](https://swagger.io/specification/#openapi-document) specification. Instead of serving the document over HTTP, you can also save it as a JSON or YAML file and use it in various ways.
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).

Expand Down Expand Up @@ -135,7 +135,7 @@ const options: SwaggerDocumentOptions = {
methodKey: string
) => methodKey
};
const document = SwaggerModule.createDocument(app, config, options);
const documentFactory = () => SwaggerModule.createDocument(app, config, options);
```
#### Setup options
Expand Down
8 changes: 4 additions & 4 deletions content/openapi/other-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ async function bootstrap() {
.addTag('cats')
.build();

const catDocument = SwaggerModule.createDocument(app, options, {
const catDocumentFactory = () => SwaggerModule.createDocument(app, options, {
include: [CatsModule],
});
SwaggerModule.setup('api/cats', app, catDocument);
SwaggerModule.setup('api/cats', app, catDocumentFactory);

const secondOptions = new DocumentBuilder()
.setTitle('Dogs example')
Expand All @@ -70,10 +70,10 @@ async function bootstrap() {
.addTag('dogs')
.build();

const dogDocument = SwaggerModule.createDocument(app, secondOptions, {
const dogDocumentFactory = () => SwaggerModule.createDocument(app, secondOptions, {
include: [DogsModule],
});
SwaggerModule.setup('api/dogs', app, dogDocument);
SwaggerModule.setup('api/dogs', app, dogDocumentFactory);

await app.listen(process.env.PORT ?? 3000);
}
Expand Down
2 changes: 1 addition & 1 deletion content/openapi/types-and-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class CreateCatDto {}
Alternatively, you can pass an options object with the `extraModels` property specified to the `SwaggerModule#createDocument()` method, as follows:

```typescript
const document = SwaggerModule.createDocument(app, options, {
const documentFactory = () => SwaggerModule.createDocument(app, options, {
extraModels: [ExtraModel],
});
```
Expand Down

0 comments on commit 48ae33d

Please sign in to comment.