-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update docs for nestjs-swagger-helper: Merge pull request #9 from hod…
…fords-solutions/chore/refactor-lib chore: upgrade dependencies and refactor type params, method
- Loading branch information
1 parent
8980b1c
commit d59faaf
Showing
1 changed file
with
64 additions
and
1 deletion.
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,3 +1,66 @@ | ||
--- | ||
displayed_sidebar: docs | ||
--- | ||
title: "@hodfords/nestjs-swagger-helper" | ||
--- | ||
<p align="center"> | ||
<a href="http://opensource.hodfords.uk" target="blank"><img src="https://opensource.hodfords.uk/img/logo.svg" width="320" alt="Hodfords Logo" /></a> | ||
</p> | ||
|
||
<p align="center"> <b>nestjs-swagger-helper</b> streamlines the integration of Swagger documentation in NestJS applications. It provides utilities and decorators to simplify the creation and management of API documentation, making it easier to keep your API specs up-to-date and accessible.</p> | ||
|
||
## Installation 🤖 | ||
|
||
Install the `nestjs-swagger-helper` package with: | ||
|
||
``` | ||
npm install @hodfords/nestjs-swagger-helper --save | ||
``` | ||
|
||
Next, create a file named `swagger-helper.config.ts` and add the following code. Then, include it in your `app.module.ts` file: | ||
|
||
```typescript | ||
// APP_PREFIX is optional, if your application doesn't have this one you can skip | ||
export const swaggerConfig = SwaggerHelperModule.forRoot(APP_PREFIX); | ||
``` | ||
|
||
Import the `SwaggerHelper` and use it to initialize Swagger | ||
|
||
```typescript | ||
import { SwaggerHelper } from '@hodfords/nestjs-swagger-helper'; | ||
|
||
type SwaggerInitialization = { | ||
app: NestExpressApplication; | ||
appEnv: string; | ||
path: string; | ||
title: string; | ||
description: string; | ||
version: string; | ||
disablePrivateDocument: boolean; | ||
}; | ||
|
||
buildSwagger() { | ||
new SwaggerHelper({ | ||
app: this.app, | ||
appEnv: env.APP_ENV, | ||
path: `${env.APP_PREFIX}/documents`, | ||
title: 'Document for usdol', | ||
description: 'The usdol API description', | ||
version: '1.0', | ||
disablePrivateDocument: env.APP_ENV === 'production', | ||
}).buildDocuments(); | ||
} | ||
``` | ||
|
||
## Usage 🚀 | ||
|
||
### Decorators | ||
|
||
The library provides two decorators you can use: | ||
|
||
- `@ApiPublic`: Marks APIs as public. | ||
- `@ApiSetValue`: Typically used for login/signin APIs to automatically add a JWT token to Swagger when the request is | ||
successful. | ||
|
||
## License 📝 | ||
|
||
This project is licensed under the MIT License |