- Create file a file named
swagger-helper.config.ts
with this code below and then add toapp.module.ts
file
// APP_PREFIX is optional, if your application doesn't have this one you can skip
export const swaggerConfig = SwaggerHelperModule.forRoot(APP_PREFIX);
- Initialize SwaggerHelper: Import the
SwaggerHelper
and pass these params to initialize it
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();
}
The library has 2 decorators that you can import to your project
- @ApiPublic (mark which APIS are for public)
- @ApiSetValue (usually add to login/signin API to automatically add jwt-token to swagger when requesting successfully)