Ajout Swagger

This commit is contained in:
2024-12-07 10:32:44 +01:00
parent 15e0263559
commit 9b3fe93f4f
8 changed files with 116 additions and 52 deletions

View File

@ -1,22 +0,0 @@
import { Test, TestingModule } from '@nestjs/testing'
import { AppController } from './app.controller'
import { AppService } from './app.service'
describe('AppController', () => {
let appController: AppController
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile()
appController = app.get<AppController>(AppController)
})
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!')
})
})
})

View File

@ -1,12 +0,0 @@
import { Controller, Get } from '@nestjs/common'
import { AppService } from './app.service'
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
return this.appService.getHello()
}
}

View File

@ -1,11 +1,9 @@
import { Module } from '@nestjs/common'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { PrismaService } from './prisma/prisma.service'
import { PrismaModule } from './prisma/prisma.module'
@Module({
imports: [],
controllers: [AppController],
providers: [AppService, PrismaService],
imports: [PrismaModule],
providers: [PrismaService],
})
export class AppModule {}

View File

@ -1,8 +0,0 @@
import { Injectable } from '@nestjs/common'
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!'
}
}

View File

@ -1,8 +1,17 @@
import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
async function bootstrap() {
const app = await NestFactory.create(AppModule)
const config = new DocumentBuilder()
.setTitle('Traintrape-moi')
.setDescription('API permettant de stocker les données de Traintrape-moi')
.setVersion('1.0')
.build()
const document = SwaggerModule.createDocument(app, config)
SwaggerModule.setup('', app, document);
await app.listen(process.env.PORT ?? 3000)
}
bootstrap()

View File

@ -0,0 +1,8 @@
import { Module } from '@nestjs/common'
import { PrismaService } from './prisma.service'
@Module({
providers: [PrismaService],
exports: [PrismaService],
})
export class PrismaModule {}