Skip to content

Commit

Permalink
feat: add swagger plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
collettemathieu committed Sep 4, 2024
1 parent 17eee45 commit c179f39
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 65 deletions.
25 changes: 25 additions & 0 deletions apps/pathway-design/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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 @@ -14,6 +15,30 @@ 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
1 change: 1 addition & 0 deletions apps/pathway-design/server/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
optimization: process.env.BUN_ENV === 'production',
outputHashing:
process.env.BUN_ENV === 'production' ? 'all' : 'none',
transformers: [{ name: '@nestjs/swagger/plugin' }],
}),
],
};
Binary file modified bun.lockb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ import {
import {
Body,
Controller,
HttpStatus,
Post,
UsePipes,
ValidationPipe,
} from '@nestjs/common';
import {
ApiBadRequestResponse,
ApiCreatedResponse,
ApiTags,
} from '@nestjs/swagger';
// biome-ignore lint/style/useImportType: <explanation>
import { InitializePathwayRequestBodyDto } from '../dtos/request/body/index.dto';
import type { InitializedPathwayResponseBodyDto } from '../dtos/response/body/index.dto';
import { InitializedPathwayResponseBodyDto } from '../dtos/response/body/index.dto';

@ApiTags('Pathway')
@UsePipes(
new ValidationPipe({
whitelist: true,
Expand All @@ -29,6 +36,14 @@ export class InitializePathwayController {
) {}

@Post('init')
@ApiCreatedResponse({
description: 'Pathway initialized.',
type: InitializedPathwayResponseBodyDto,
})
@ApiBadRequestResponse({
status: HttpStatus.BAD_REQUEST,
description: 'Cannot initiate pathway. Data are not valid.',
})
execute(
@Body() initializePathwayRequestBodyDto: InitializePathwayRequestBodyDto
): Promise<InitializedPathwayResponseBodyDto> {
Expand Down
130 changes: 66 additions & 64 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,66 +1,68 @@
{
"dependencies": {
"@nestjs/common": "^10.0.2",
"@nestjs/core": "^10.0.2",
"@nestjs/cqrs": "^10.2.7",
"@nestjs/platform-express": "^10.0.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",
"swc-loader": "^0.2.6",
"tslib": "^2.3.0"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@commitlint/config-conventional": "^19.2.2",
"@cucumber/cucumber": "^10.8.0",
"@nestjs/schematics": "^10.0.1",
"@nestjs/testing": "^10.0.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",
"@types/bun": "^1.1.6",
"@types/node": "~18.16.9",
"@types/sinon": "^17.0.3",
"@types/supertest": "^6.0.2",
"bun-types": "^1.1.18",
"chokidar": "^3.6.0",
"commitlint": "^19.3.0",
"cucumber-tsflow": "^4.4.4",
"nx": "19.5.6",
"sinon": "^18.0.0",
"supertest": "^7.0.0",
"typescript": "~5.5.2",
"verdaccio": "^5.0.4",
"webpack-cli": "^5.1.4"
},
"license": "MIT",
"name": "bewoak",
"nx": {
"includedScripts": []
},
"private": true,
"scripts": {
"biome": "biome",
"build": "nx run-many --target=build --parallel=4",
"format": "biome format --write",
"format:check": "biome format",
"lint": "nx run-many --target=lint --parallel=4",
"nx": "nx",
"postinstall": "chmod +x .hooks/* && git config core.hooksPath .hooks",
"start": "nx serve pathway-design-server",
"test": "nx run-many --target=test --parallel=4",
"test:feature": "nx run-many --target=test-feature --parallel=4"
},
"version": "0.0.1"
"dependencies": {
"@nestjs/common": "^10.0.2",
"@nestjs/core": "^10.0.2",
"@nestjs/cqrs": "^10.2.7",
"@nestjs/platform-express": "^10.0.2",
"@nestjs/swagger": "^7.4.0",
"@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"
},
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@commitlint/config-conventional": "^19.2.2",
"@cucumber/cucumber": "^10.8.0",
"@nestjs/schematics": "^10.0.1",
"@nestjs/testing": "^10.0.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",
"@types/bun": "^1.1.6",
"@types/node": "~18.16.9",
"@types/sinon": "^17.0.3",
"@types/supertest": "^6.0.2",
"bun-types": "^1.1.18",
"chokidar": "^3.6.0",
"commitlint": "^19.3.0",
"cucumber-tsflow": "^4.4.4",
"nx": "19.5.6",
"sinon": "^18.0.0",
"supertest": "^7.0.0",
"typescript": "~5.5.2",
"verdaccio": "^5.0.4",
"webpack-cli": "^5.1.4"
},
"license": "MIT",
"name": "bewoak",
"nx": {
"includedScripts": []
},
"private": true,
"scripts": {
"biome": "biome",
"build": "nx run-many --target=build --parallel=4",
"format": "biome format --write",
"format:check": "biome format",
"lint": "nx run-many --target=lint --parallel=4",
"nx": "nx",
"postinstall": "chmod +x .hooks/* && git config core.hooksPath .hooks",
"start": "nx serve pathway-design-server",
"test": "nx run-many --target=test --parallel=4",
"test:feature": "nx run-many --target=test-feature --parallel=4"
},
"version": "0.0.1"
}

0 comments on commit c179f39

Please sign in to comment.