Feature: Added Code generation based on swagger.json #4

Merged
igorpropisnov merged 6 commits from feature/generate-api-client into main 2024-05-22 15:48:01 +02:00
4 changed files with 41 additions and 1 deletions
Showing only changes of commit 0fca8f3831 - Show all commits

View File

@ -8,7 +8,6 @@ async function setupSwagger(app) {
.setTitle('Tickets API')
.setDescription('Description of the API')
.setVersion('0.0.0')
.addTag('tickets')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);

View File

@ -10,11 +10,17 @@ import { AuthService } from '../services/auth.service';
import { TokensDto, UserCredentialsDto } from '../models/dto';
import { RefreshTokenGuard } from '../common/guards';
import { GetCurrentUser, GetCurrentUserId, Public } from '../common/decorators';
import { ApiCreatedResponse, ApiTags } from '@nestjs/swagger';
@ApiTags('Authentication')
@Controller('auth')
export class AuthController {
constructor(private readonly authService: AuthService) {}
@ApiCreatedResponse({
description: 'User signed up successfully',
type: TokensDto,
})
@Public()
@Post('signup')
@HttpCode(HttpStatus.CREATED)
@ -24,6 +30,10 @@ export class AuthController {
return this.authService.signup(userCredentials);
}
@ApiCreatedResponse({
description: 'User signin successfully',
type: TokensDto,
})
@Public()
@Post('signin')
@HttpCode(HttpStatus.OK)
@ -33,12 +43,20 @@ export class AuthController {
return this.authService.signin(userCredentials);
}
@ApiCreatedResponse({
description: 'User signed out successfully',
type: Boolean,
})
@Post('logout')
@HttpCode(HttpStatus.OK)
public async logout(@GetCurrentUserId() userId: number): Promise<boolean> {
return this.authService.logout(userId);
}
@ApiCreatedResponse({
description: 'User tokens refreshed successfully',
type: TokensDto,
})
@Public()
@UseGuards(RefreshTokenGuard)
@Post('refresh')

View File

@ -1,10 +1,21 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';
export class TokensDto {
@ApiProperty({
title: 'Access token',
description: 'Access token',
example: 'eyJhbGci',
})
@IsNotEmpty()
@IsString()
public access_token: string;
@ApiProperty({
title: 'Refresh token',
description: 'Refresh token',
example: 'eyJhbGci',
})
@IsNotEmpty()
@IsString()
public refresh_token: string;

View File

@ -1,10 +1,22 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsString, MinLength } from 'class-validator';
export class UserCredentialsDto {
@ApiProperty({
title: 'E-Mail',
description: 'User email',
example: 'foo@bar.com',
})
@IsNotEmpty()
@IsEmail()
public email: string;
@ApiProperty({
title: 'Password',
description: 'User password',
example: '$tr0ngP@$$w0rd',
minLength: 8,
})
@IsNotEmpty()
@IsString()
@MinLength(8)