Gathering detailed insights and metrics for @jozefazz/nestjs-redoc
Gathering detailed insights and metrics for @jozefazz/nestjs-redoc
Gathering detailed insights and metrics for @jozefazz/nestjs-redoc
Gathering detailed insights and metrics for @jozefazz/nestjs-redoc
📘 ReDoc frontend for you NestJS swagger API documentation
npm install @jozefazz/nestjs-redoc
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
9 Stars
86 Commits
4 Forks
1 Branches
1 Contributors
Updated on 06 Nov 2024
TypeScript (87.98%)
Handlebars (6.52%)
JavaScript (5.5%)
Cumulative downloads
Total Downloads
Last day
29.3%
150
Compared to previous day
Last week
-31.8%
638
Compared to previous week
Last month
5.3%
3,354
Compared to previous month
Last year
0%
45,095
Compared to previous year
4
28
I have tried most of the Redoc integrate NestJS solutions available on the market, but due to a lack of maintenance over a long period, many outdated packages were being used, leading to installation failures. This version has been modified and improved, allowing for perfect integration with NestJS 10.0.0
-Jozefazz
NB: Please read the ReDoc Documentation firstly.
Using npm: npm install @jozefazz/nestjs-redoc
You need to install the Swagger Module first if you want to get definitions updated with your project.
In future versions you will be able to pass a URL parameter as document, but for the moment you need this document object from the swagger module
1const options = new DocumentBuilder() 2 .setTitle('Look, i have a title') 3 .setDescription('A very nice description') 4 .setBasePath('/api/v1') 5 .build(); 6const document = SwaggerModule.createDocument(app, options);
Then add the following example code.
Note: All properties are optional, if you don't specify a title we will fallback to the one you used in your DocumentBuilder instance.
1const redocOptions: RedocOptions = { 2 title: 'Hello Nest', 3 logo: { 4 url: 'https://redocly.github.io/redoc/petstore-logo.png', 5 backgroundColor: '#F0F0F0', 6 altText: 'PetStore logo' 7 }, 8 sortPropsAlphabetically: true, 9 hideDownloadButton: false, 10 hideHostname: false, 11 auth: { 12 enabled: true, 13 user: 'admin', 14 password: '123' 15 }, 16 tagGroups: [ 17 { 18 name: 'Core resources', 19 tags: ['cats'], 20 }, 21 ], 22}; 23// Instead of using SwaggerModule.setup() you call this module 24await RedocModule.setup('/docs', app, document, redocOptions);
Create a file "setup.redoc.ts"
1import type { INestApplication } from '@nestjs/common'; 2import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; 3import { RedocModule, RedocOptions } from '@jozefazz/nestjs-redoc'; 4import * as process from 'process'; 5 6export async function setupRedoc(app: INestApplication) { 7 const documentBuilder = new DocumentBuilder() 8 .setTitle(`${process.env.DOCS_TITLE}`) 9 .setVersion('1.0') 10 .setDescription('Powered by Jozefazz') 11 .addBearerAuth( 12 { 13 description: `Please enter token in following format: Bearer <JWT>`, 14 name: 'Authorization', 15 bearerFormat: 'Bearer', 16 scheme: 'Bearer', 17 type: 'http', 18 in: 'Header', 19 }, 20 'access-token', 21 ); 22 23 if (process.env.API_VERSION) { 24 documentBuilder.setVersion(process.env.API_VERSION); 25 } 26 27 const document = SwaggerModule.createDocument(app, documentBuilder.build()); 28 const redocOptions: RedocOptions = { 29 title: `${process.env.DOCS_TITLE}`, 30 logo: { 31 url: `${process.env.DOCS_LOGO}`, 32 backgroundColor: '#d0e8c5', 33 altText: 'LOGO', 34 }, 35 theme: { 36 typography: { 37 fontSize: '16px', 38 fontWeightBold: '900', 39 }, 40 sidebar: { 41 backgroundColor: '#d0e8c5', 42 }, 43 rightPanel: { 44 backgroundColor: '#01312b', 45 }, 46 }, 47 sortPropsAlphabetically: true, 48 hideDownloadButton: false, 49 hideHostname: false, 50 noAutoAuth: true, 51 pathInMiddlePanel: true, 52 auth: { 53 enabled: true, 54 user: 'admin', 55 password: `${process.env.DOCS_PASSWORD}`, 56 }, 57 tagGroups: [ 58 { 59 name: 'Core resources', 60 tags: ['authentication', 'user'], 61 }, 62 ], 63 }; 64 await RedocModule.setup('docs', app, document, redocOptions); 65 console.info( 66 `Redoc Documentation: http://localhost:${process.env.PORT}/docs`, 67 ); 68} 69
In your main.ts, add this line before "await app.listen(3000);"
await setupRedoc(app);
Option | Description | Type | Note |
---|---|---|---|
title | Web site title (e.g: ReDoc documentation) | string | |
favicon | Web site favicon URL | string | Fallbacks to the document title if not set |
logo | Logo options | LogoOptions | See LogoOptions table |
theme | Theme options | ThemeOptions | See ThemeOptions info |
untrustedSpec | If set, the spec is considered untrusted and all HTML/markdown is sanitized to prevent XSS, by default is false | boolean | |
supressWarnings | If set, warnings are not rendered at the top of documentation (they are still logged to the console) | boolean | |
hideHostname | If set, the protocol and hostname won't be shown in the operation definition | boolean | |
expandResponses | Specify which responses to expand by default by response codes, values should be passed as comma-separated list without spaces (e.g: 200, 201, "all") | string | |
requiredPropsFirst | If set, show required properties first ordered in the same order as in required array | boolean | |
sortPropsAlphabetically | If set, propeties will be sorted alphabetically | boolean | |
showExtensions | If set the fields starting with "x-" will be shown, can be a boolean or a string with names of extensions to display | boolean | |
noAutoAuth | If set, redoc won't inject authentication section automatically | boolean | |
pathInMiddlePanel | If set, path link and HTTP verb will be shown in the middle panel instead of the right one | boolean | |
hideLoading | If set, loading spinner animation won't be shown | boolean | |
nativeScrollbars | If set, a native scrollbar will be used instead of perfect-scroll, this can improve performance of the frontend for big specs | boolean | |
hideDownloadButton | This will hide the "Download spec" button, it only hides the button | boolean | |
disableSearch | If set, the search bar will be disabled | boolean | |
onlyRequiredInSamples | Shows only required fileds in request samples | boolean | |
auth | Auth options | AuthOptions | See AuthOptions info |
AuthOptions info | |||
enabled | If enabled, a prompt will pop out asking for authentication details, default: false | boolean | |
user | User name, default: admin | string | |
password | User password, default: 123 | string | |
tagGroups | Tag groups options | TagGroupOptions[] | See Tag Group options |
Tag Group options info | |||
name | Tag name | string | |
tags | Tag collection | string[] | |
redocVersion | Set an specific redoc version | string,number | By default it's "latest" |
Note: If you want to change your ReDoc theme settings, take a look at the official ReDoc documentation: https://github.com/Redocly/redoc/blob/master/src/theme.ts
Apply the properties defined in ResolvedThemeInterface to the key called "theme" in the redoc options
Option | Description | Type | Example |
---|---|---|---|
url | The URL pointing to the spec Logo, must be in the format of a URL and an absolute URL | string | |
backgroundColor | Background color to be used, must be RGB color in hexadecimal format (e.g: #008080) | string | #F0F0F0 |
altText | Alt tag for Logo | string | PetStore |
href | href tag for Logo, it defaults to the host used for your API spec | string |
Forked from https://github.com/ojoanalogo/nestjs-redoc
No vulnerabilities found.
No security vulnerabilities found.