Skip to content

Commit

Permalink
docs(nestjs-redox): improved README
Browse files Browse the repository at this point in the history
  • Loading branch information
julianpoemp committed May 29, 2024
1 parent d296717 commit 621cc31
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 52 deletions.
64 changes: 37 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ By default NestJSRedox automatically loads the redoc bundle from a CDN. If you w
In your main.ts file, before calling app.listen() insert the module setup:

```typescript
import { NestJSRedoxOptions } from 'nestjs-dedox';

/** example swagger config **/
const swaggerConfig = new DocumentBuilder()
.setTitle('API reference')
.setDescription('Some description')
.setVersion('1.0.0')
.addBearerAuth()
.addSecurity('roles', {
type: 'http',
scheme: 'bearer',
})
.build();
.setTitle('API reference')
.setDescription('Some description')
.setVersion('1.0.0')
.addBearerAuth()
.addSecurity('roles', {
type: 'http',
scheme: 'bearer',
})
.build();

/**
* official supported options by Redoc
Expand All @@ -44,6 +46,22 @@ const redocOptions: RedocOptions = {
requiredPropsFirst: true,
};

/**
* Redox options
*/
const redoxOptions: NestJSRedoxOptions = {
useGlobalPrefix: true,
disableGoogleFont: true,
standalone: true,
auth: {
enabled: true,
users: {
user1: 'user1',
user2: 'user2',
},
},
};

/**
* create swagger document
*/
Expand All @@ -55,24 +73,7 @@ const document = SwaggerModule.createDocument(app, swaggerConfig, {
/**
* Initialize NestjsRedoxModule
*/
NestjsRedoxModule.setup(
'reference',
app as any,
document,
{
useGlobalPrefix: true,
disableGoogleFont: true,
standalone: true,
auth: {
enabled: true,
users: {
user1: 'user1',
user2: 'user2',
},
},
},
redocOptions
);
NestjsRedoxModule.setup('reference', app as any, document, redoxOptions, redocOptions);
```

If you like this package give it a star ;)
Expand All @@ -82,8 +83,17 @@ If you like this package give it a star ;)
For supported options see [Options](https://github.com/julianpoemp/nestjs-redox/blob/main/libs/nestjs-redox/src/lib/types.ts).

## Changelog

See [Changelog](https://github.com/julianpoemp/nestjs-redox/blob/main/libs/nestjs-redox/CHANGELOG.md).

## Development

Clone this repository and run `npm install`. You find the library under `libs/nestjs-redox` and the demo apps under `apps/demo-express`or `apps/demo-fastify`. Please run `npm run format` before commiting and make sure to use valid commit messages (see chapter Contributing).

## E2E Testing

Run `npm run test` to run e2e tests.

## Contributing

If you want to contribute please fork this repository and send a pull request. The commit messages must be formatted after the conventional changelog angular theme. Following scopes are allowed: "nestjs-redox", "demo-express", "demo-fastify" and "project" for changes that affect the whole project.
32 changes: 19 additions & 13 deletions apps/demo-express/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

import { NestjsRedoxModule, RedocOptions } from 'nestjs-redox';
import {
NestjsRedoxModule,
NestJSRedoxOptions,
RedocOptions,
} from 'nestjs-redox';

import { AppModule } from './app/app.module';

Expand Down Expand Up @@ -36,6 +40,19 @@ async function bootstrap() {
},
};

const redoxOptions: NestJSRedoxOptions = {
useGlobalPrefix: true,
disableGoogleFont: true,
standalone: true,
auth: {
enabled: true,
users: {
test123: 'test123',
test: 'test',
},
},
};

const document = SwaggerModule.createDocument(app, swaggerConfig, {
ignoreGlobalPrefix: false,
operationIdFactory: (controllerKey, methodKey) => methodKey,
Expand All @@ -45,18 +62,7 @@ async function bootstrap() {
'reference',
app,
document,
{
useGlobalPrefix: true,
disableGoogleFont: true,
standalone: true,
auth: {
enabled: true,
users: {
test123: 'test123',
test: 'test',
},
},
},
redoxOptions,
redocOptions
);

Expand Down
31 changes: 19 additions & 12 deletions apps/demo-fastify/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
} from '@nestjs/platform-fastify';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

import { NestjsRedoxModule, RedocOptions } from 'nestjs-redox';
import {
NestjsRedoxModule,
NestJSRedoxOptions,
RedocOptions,
} from 'nestjs-redox';

import { AppModule } from './app/app.module';

Expand Down Expand Up @@ -44,6 +48,19 @@ async function bootstrap() {
},
};

const redoxOptions: NestJSRedoxOptions = {
useGlobalPrefix: true,
disableGoogleFont: true,
standalone: true,
auth: {
enabled: true,
users: {
test123: 'test123',
test: 'test',
},
},
};

const document = SwaggerModule.createDocument(app, swaggerConfig, {
ignoreGlobalPrefix: false,
operationIdFactory: (controllerKey, methodKey) => methodKey,
Expand All @@ -53,17 +70,7 @@ async function bootstrap() {
'reference',
app,
document,
{
useGlobalPrefix: true,
disableGoogleFont: true,
standalone: true,
auth: {
enabled: true,
users: {
test: 'test',
},
},
},
redoxOptions,
redocOptions
);

Expand Down

0 comments on commit 621cc31

Please sign in to comment.