-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a372ec8
commit 56561e8
Showing
3 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './lib/decorator' | ||
export * from './lib/dto' | ||
export * from './lib/util' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './with-swagger.util' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { INestApplication } from '@nestjs/common' | ||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger' | ||
import { patchNestJsSwagger } from 'nestjs-zod' | ||
|
||
/** | ||
* Adds Swagger documentation to the application. | ||
* | ||
* @param app - The INestApplication instance. | ||
* @returns The modified INestApplication instance. | ||
*/ | ||
export const withSwagger = | ||
(params: { title: string; description: string; version: string }) => | ||
(app: INestApplication): INestApplication => { | ||
// IMPORTANT: This modifies the Nest Swagger module to be compatible with | ||
// DTOs created by Zod schemas. The patch MUST be done before the | ||
// configuration process. | ||
patchNestJsSwagger() | ||
|
||
const document = SwaggerModule.createDocument( | ||
app, | ||
new DocumentBuilder().setTitle(params.title).setDescription(params.description).setVersion(params.version).build() | ||
) | ||
|
||
SwaggerModule.setup('docs', app, document, { | ||
customSiteTitle: `${params.title} API` | ||
}) | ||
|
||
return app | ||
} |