Skip to content

Commit 2ce980b

Browse files
authored
Merge pull request #28 from EVNotify/api-docs-auth
📝 Api docs auth
2 parents 77bd708 + b6c6a3a commit 2ce980b

File tree

8 files changed

+29
-16
lines changed

8 files changed

+29
-16
lines changed

src/account/account.controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
HttpCode,
1515
HttpStatus,
1616
} from '@nestjs/common';
17-
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
17+
import { ApiSecurity, ApiTags } from '@nestjs/swagger';
1818
import { Exception } from '../utils/exception';
1919
import { AuthGuard } from './account.guard';
2020
import { AccountService } from './account.service';
@@ -67,7 +67,7 @@ export class AccountController {
6767
}
6868

6969
@Get(':akey')
70-
@ApiBearerAuth()
70+
@ApiSecurity('custom-auth')
7171
async findOne(@Param('akey') akey: string) {
7272
const account = await this.accountService.findOne(akey);
7373

@@ -101,7 +101,7 @@ export class AccountController {
101101
}
102102

103103
@Patch(':akey/token')
104-
@ApiBearerAuth()
104+
@ApiSecurity('custom-auth')
105105
async changeToken(
106106
@Param('akey') akey: string,
107107
@Body() changeTokenDto: ChangeTokenDto,
@@ -125,7 +125,7 @@ export class AccountController {
125125
}
126126

127127
@Patch(':akey/password')
128-
@ApiBearerAuth()
128+
@ApiSecurity('custom-auth')
129129
async changePassword(
130130
@Param('akey') akey: string,
131131
@Body() changePasswordDto: ChangePasswordDto,

src/logs/logs.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { AuthGuard } from '../account/account.guard';
1919
import { LogsGuard } from './logs.guard';
2020
import { OwnsLog } from './decorators/owns-log.decorator';
2121
import { SyncDto } from './dto/sync.dto';
22-
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
22+
import { ApiTags, ApiSecurity } from '@nestjs/swagger';
2323
import { LogNotExistsException } from './exceptions/log-not-exists.exception';
2424
import { LogMissingSyncDataException } from './exceptions/log-missing-sync-data.exception';
2525
import { TYPE } from './entities/type.entity';
@@ -35,7 +35,7 @@ import { PremiumRequiredException } from '../premium/exceptions/premium-required
3535
@UseGuards(LogsGuard)
3636
@UseGuards(PremiumGuard)
3737
@ApiTags('Logs & Sync')
38-
@ApiBearerAuth()
38+
@ApiSecurity('custom-auth')
3939
export class LogsController {
4040
constructor(private readonly logsService: LogsService) {}
4141

src/main.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ async function bootstrap() {
2323
.setTitle('EVNotify API')
2424
.setDescription('Documentation for EVNotify API')
2525
.setVersion('3.0')
26-
.addBearerAuth()
26+
.addApiKey(
27+
{
28+
type: 'apiKey',
29+
name: 'Authorization',
30+
in: 'header',
31+
description:
32+
'Enter your authorization string in the format: <your-akey> <your-api-token>, e.g. "123456 8c6a51c82307e2b4df0c"',
33+
},
34+
'custom-auth',
35+
)
2736
.build();
2837
const document = SwaggerModule.createDocument(app, config);
2938

src/migration/migration.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Log, LogSchema } from "../logs/schemas/log.schema";
66
import { LastSync, LastSyncSchema } from "../logs/schemas/last-sync.schema";
77
import { MigrationService } from "./migration.service";
88
import { MigrationAccount, MigrationAccountSchema } from "./schemas/migration-account.schema";
9+
import { PremiumModule } from "../premium/premium.module";
910

1011
@Module({
1112
controllers: [MigrationController],
@@ -16,6 +17,7 @@ import { MigrationAccount, MigrationAccountSchema } from "./schemas/migration-ac
1617
{ name: LastSync.name, schema: LastSyncSchema },
1718
{ name: MigrationAccount.name, schema: MigrationAccountSchema },
1819
]),
20+
PremiumModule,
1921
],
2022
})
2123
export class MigrationModule { };

src/premium/premium.controller.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BadRequestException, Body, ConflictException, Controller, Get, HttpCode, HttpStatus, InternalServerErrorException, Logger, NotFoundException, Param, Post, UseGuards } from "@nestjs/common";
2-
import { ApiBearerAuth, ApiTags } from "@nestjs/swagger";
2+
import { ApiSecurity, ApiTags } from "@nestjs/swagger";
33
import { AuthGuard } from "../account/account.guard";
44
import { PremiumService } from "./premium.service";
55
import { PremiumStatusDto } from "./dto/premium-status.dto";
@@ -19,7 +19,7 @@ export class PremiumController {
1919
) { }
2020

2121
@Get(':akey')
22-
@ApiBearerAuth()
22+
@ApiSecurity('custom-auth')
2323
async status(@Param('akey') akey: string): Promise<PremiumStatusDto> {
2424
try {
2525
const expiryDate = await this.premiumService.getExpiryDate(akey);
@@ -35,7 +35,7 @@ export class PremiumController {
3535
}
3636

3737
@Post(':akey/redeem/ad')
38-
@ApiBearerAuth()
38+
@ApiSecurity('custom-auth')
3939
@HttpCode(HttpStatus.OK)
4040
async redeemAd(@Param('akey') akey: string): Promise<PremiumStatusDto> {
4141
try {
@@ -61,7 +61,7 @@ export class PremiumController {
6161
}
6262

6363
@Post(':akey/redeem/voucher/:code')
64-
@ApiBearerAuth()
64+
@ApiSecurity('custom-auth')
6565
@HttpCode(HttpStatus.OK)
6666
async redeemVoucher(@Param('akey') akey: string, @Param('code') code: string): Promise<PremiumStatusDto> {
6767
try {
@@ -82,7 +82,7 @@ export class PremiumController {
8282
}
8383

8484
@Post(':akey/redeem/subscription/:code')
85-
@ApiBearerAuth()
85+
@ApiSecurity('custom-auth')
8686
@HttpCode(HttpStatus.OK)
8787
async redeemSubscription(@Param('akey') akey: string, @Param('code') code: string) {
8888
try {

src/settings/settings.controller.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Controller, Get, Body, Patch, Param, UseGuards } from '@nestjs/common';
2-
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
2+
import { ApiSecurity, ApiTags } from '@nestjs/swagger';
33
import { AuthGuard } from '../account/account.guard';
44
import { SettingsField } from './decorators/settings-field.decorator';
55
import { SettingDto } from './dto/setting.dto';
@@ -10,7 +10,7 @@ import { SettingsService } from './settings.service';
1010
@UseGuards(AuthGuard)
1111
@UseGuards(SettingsGuard)
1212
@ApiTags('Settings')
13-
@ApiBearerAuth()
13+
@ApiSecurity('custom-auth')
1414
export class SettingsController {
1515
constructor(private readonly settingsService: SettingsService) {}
1616

src/stations/stations.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Controller, Get, HttpException, HttpStatus, InternalServerErrorException, Param, Query, UseGuards } from "@nestjs/common";
2-
import { ApiTags } from "@nestjs/swagger";
2+
import { ApiSecurity, ApiTags } from "@nestjs/swagger";
33
import { AuthGuard } from "src/account/account.guard";
44
import { StationsService } from "./stations.service";
55
import { ListStationsFilterDto } from "./dto/list-stations.dto";
@@ -14,6 +14,7 @@ import { RouteCalculatedRecentlyException } from "./exceptions/route-calculated-
1414
@Controller('stations')
1515
@UseGuards(AuthGuard)
1616
@UseGuards(PremiumGuard)
17+
@ApiSecurity('custom-auth')
1718
@ApiTags('Stations')
1819
export class StationsController {
1920
constructor(

src/tripnotify/tripnotify.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BadRequestException, Body, Controller, Delete, ForbiddenException, Get, InternalServerErrorException, NotFoundException, Param, Post, UseGuards } from "@nestjs/common";
2-
import { ApiTags } from "@nestjs/swagger";
2+
import { ApiSecurity, ApiTags } from "@nestjs/swagger";
33
import { TripNotifyService } from "./tripnotify.service";
44
import { TripDto } from "./dto/trip.dto";
55
import { AuthGuard } from "src/account/account.guard";
@@ -20,6 +20,7 @@ import { TripInformationDto } from "./dto/trip-information.dto";
2020
@Controller('trips')
2121
@UseGuards(AuthGuard)
2222
@UseGuards(PremiumGuard)
23+
@ApiSecurity('custom-auth')
2324
@ApiTags('TripNotify')
2425
export class TripNotifyController {
2526
constructor(

0 commit comments

Comments
 (0)