Skip to content

Commit

Permalink
fix: validation pipe does not work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
collettemathieu committed Aug 6, 2024
1 parent 8fbbf05 commit 2760aeb
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 70 deletions.
24 changes: 0 additions & 24 deletions apps/pathway-design/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';

import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './app/app.module';

async function bootstrap() {
Expand All @@ -15,29 +14,6 @@ async function bootstrap() {
app.setGlobalPrefix(globalPrefix);
const port = process.env.PORT ?? 3000;

// Setting up Swagger document
const options = new DocumentBuilder()
.setTitle('Pathway Design Application')
.setDescription(
'Application Programming Interface (API) of Pathway Design Application'
)
.setVersion('1.0')
.addBearerAuth(
{
description:
'Please enter token in following format: Bearer <JWT>',
name: 'Authorization',
bearerFormat: 'Bearer',
scheme: 'Bearer',
type: 'http',
in: 'Header',
},
'access-token'
)
.build();
const document = SwaggerModule.createDocument(app, options);
SwaggerModule.setup('api', app, document);

await app.listen(port);
Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ControllerSteps {
}

@then('I should retrieve a pathway initialized with its data')
public thenIShouldSeeAPathwayInitiated(dataTable: DataTable) {
public thenIShouldRetrieveAPathwayInitiated(dataTable: DataTable) {
const firstRow = dataTable.hashes()[0];

assert.strictEqual(this.response.body.title, firstRow.title);
Expand Down
14 changes: 0 additions & 14 deletions apps/pathway-design/server/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,6 @@ module.exports = {
optimization: process.env.BUN_ENV === 'production',
outputHashing:
process.env.BUN_ENV === 'production' ? 'all' : 'none',
transformers: [
{
name: '@nestjs/swagger/plugin',
options: {
classValidatorShim: true,
dtoFileNameSuffix: [
'.dto.ts',
'.entity.ts',
'.schema.ts',
],
introspectComments: true,
},
},
],
}),
],
};
Binary file modified bun.lockb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@ import {
UsePipes,
ValidationPipe,
} from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import type { InitializePathwayRequestBodyDto } from '../dtos/request/body/index.dto';
import type { InitializedPathwayResponseBodyDto } from '../dtos/response/body/index.dto';

@ApiTags('Pathway')
@UsePipes(
new ValidationPipe({
whitelist: true,
forbidNonWhitelisted: true,
})
)
@UsePipes(new ValidationPipe())
@Controller({
path: 'pathway',
})
Expand All @@ -31,7 +24,6 @@ export class InitializePathwayController {
) {}

@Post('init')
@ApiBearerAuth('access-token')
execute(
@Body() initializePathwayRequestBodyDto: InitializePathwayRequestBodyDto
): Promise<InitializedPathwayResponseBodyDto> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
export class InitializePathwayRequestBodyDto
implements IInitializePathwayRequestBodyDto
{
readonly title!: string;
import { IsString } from 'class-validator';

readonly description!: string;
export class InitializePathwayRequestBodyDto {
@IsString()
title!: string;

readonly researchField!: string;
}
@IsString()
description!: string;

export interface IInitializePathwayRequestBodyDto {
description: string;
researchField: string;
title: string;
@IsString()
researchField!: string;
}
20 changes: 9 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
"@nestjs/core": "^10.0.2",
"@nestjs/cqrs": "^10.2.7",
"@nestjs/platform-express": "^10.0.2",
"@nestjs/swagger": "^7.4.0",
"@nx/nest": "^19.4.2",
"@swc/cli": "^0.4.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"crypto": "^1.0.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.0",
"swagger-ui-express": "^5.0.1",
"swc-loader": "^0.2.6",
"tslib": "^2.3.0"
},
Expand All @@ -22,12 +19,13 @@
"@cucumber/cucumber": "^10.8.0",
"@nestjs/schematics": "^10.0.1",
"@nestjs/testing": "^10.0.2",
"@nx/eslint": "19.4.2",
"@nx/js": "19.4.2",
"@nx/node": "19.4.2",
"@nx/web": "19.4.2",
"@nx/webpack": "19.4.2",
"@nx/workspace": "19.4.2",
"@nx/eslint": "19.5.6",
"@nx/js": "19.5.6",
"@nx/nest": "^19.5.6",
"@nx/node": "19.5.6",
"@nx/web": "19.5.6",
"@nx/webpack": "19.5.6",
"@nx/workspace": "19.5.6",
"@swc-node/register": "~1.9.1",
"@swc/core": "~1.5.7",
"@swc/helpers": "~0.5.11",
Expand All @@ -39,10 +37,10 @@
"chokidar": "^3.6.0",
"commitlint": "^19.3.0",
"cucumber-tsflow": "^4.4.4",
"nx": "19.4.2",
"nx": "19.5.6",
"sinon": "^18.0.0",
"supertest": "^7.0.0",
"typescript": "~5.4.2",
"typescript": "~5.5.2",
"verdaccio": "^5.0.4",
"webpack-cli": "^5.1.4"
},
Expand Down

0 comments on commit 2760aeb

Please sign in to comment.