HM-110. Научили свагер работать с авторизацией

This commit is contained in:
vigdorov
2020-08-10 20:52:36 +03:00
parent 25c6a7357e
commit 3883ea4ad8
3 changed files with 9 additions and 2 deletions

View File

@ -1,11 +1,12 @@
import {Controller, Get, Header, Delete, Options, HttpCode, Req} from '@nestjs/common'; import {Controller, Get, Header, Delete, Options, HttpCode, Req} from '@nestjs/common';
import {ApiTags, ApiResponse} from '@nestjs/swagger'; import {ApiTags, ApiResponse, ApiSecurity} from '@nestjs/swagger';
import {LogsService} from './logs.service'; import {LogsService} from './logs.service';
import {ALLOW_ORIGIN_ALL, COLLECTION_LOGS, LOG_TYPE, ALLOW_METHOD, ALLOW_CREDENTIALS, CONTENT_LENGTH, ALLOW_HEADERS} from 'src/consts'; import {ALLOW_ORIGIN_ALL, COLLECTION_LOGS, LOG_TYPE, ALLOW_METHOD, ALLOW_CREDENTIALS, CONTENT_LENGTH, ALLOW_HEADERS} from 'src/consts';
import {ClienLogResponse, ServerLogResponse} from './logs.schema'; import {ClienLogResponse, ServerLogResponse} from './logs.schema';
import {AuthService} from 'src/services/auth.service'; import {AuthService} from 'src/services/auth.service';
import {Request} from 'express'; import {Request} from 'express';
@ApiSecurity('apiKey')
@Controller(COLLECTION_LOGS) @Controller(COLLECTION_LOGS)
@ApiTags(COLLECTION_LOGS) @ApiTags(COLLECTION_LOGS)
export class LogsController { export class LogsController {

View File

@ -9,6 +9,11 @@ async function bootstrap() {
}); });
const options = new DocumentBuilder() const options = new DocumentBuilder()
.addSecurity('apiKey', {
type: 'apiKey',
in: 'header',
name: 'Authorization',
})
.setTitle('Storage Service API') .setTitle('Storage Service API')
.setDescription('API для создания хранилищ по уникальному ключу') .setDescription('API для создания хранилищ по уникальному ключу')
.setVersion('1.0.0') .setVersion('1.0.0')

View File

@ -1,7 +1,7 @@
import {Controller, Get, Req, Post, Options, Header, Delete, HttpCode, Put, UseInterceptors} from '@nestjs/common'; import {Controller, Get, Req, Post, Options, Header, Delete, HttpCode, Put, UseInterceptors} from '@nestjs/common';
import {StoreService} from './store.service'; import {StoreService} from './store.service';
import {Store, StoreRequest} from './store.schema'; import {Store, StoreRequest} from './store.schema';
import {ApiResponse, ApiTags, ApiParam, ApiBody} from '@nestjs/swagger'; import {ApiResponse, ApiTags, ApiParam, ApiBody, ApiBearerAuth, ApiSecurity} from '@nestjs/swagger';
import {ALLOW_ORIGIN_ALL, ALLOW_METHOD, ALLOW_CREDENTIALS, CONTENT_LENGTH, ALLOW_HEADERS, COLLECTION_STORE} from 'src/consts'; import {ALLOW_ORIGIN_ALL, ALLOW_METHOD, ALLOW_CREDENTIALS, CONTENT_LENGTH, ALLOW_HEADERS, COLLECTION_STORE} from 'src/consts';
import {Request} from 'express'; import {Request} from 'express';
import {LoggingInterceptor} from 'src/logs/logging.interceptor'; import {LoggingInterceptor} from 'src/logs/logging.interceptor';
@ -31,6 +31,7 @@ const makeApiHeader = (request: Request): string => {
return typeof apiHeader === 'string' ? apiHeader : ''; return typeof apiHeader === 'string' ? apiHeader : '';
}; };
@ApiSecurity('apiKey')
@UseInterceptors(LoggingInterceptor) @UseInterceptors(LoggingInterceptor)
@Controller(COLLECTION_STORE) @Controller(COLLECTION_STORE)
@ApiTags(COLLECTION_STORE) @ApiTags(COLLECTION_STORE)