add swagger example
Some checks failed
Build Docker Image Front / run (push) Successful in 23s
Build Docker Image Back / run (push) Successful in 1m7s
Build Docker Image Front / run (pull_request) Successful in 23s
Build Docker Image Back / run (pull_request) Successful in 20s
JsDocs / coverage (pull_request) Failing after 26s
Test and coverage / coverage (pull_request) Failing after 38s

This commit is contained in:
Clement 2024-05-06 20:37:03 +02:00
parent 9dbdde5419
commit e69773fdd6
3 changed files with 47 additions and 7 deletions

View File

@ -1,23 +1,32 @@
import express from "express";
import express from "express"
/**
* Initialize Express application instance.
* @returns An initialized Express application object.
*/
const app = express();
const app = express()
/**
* Handle GET request for homepage route ('/').
* Handle GET request for homepage route ('/welcome').
* Send back a simple json response.
* @param {express.Request} req - HTTP Request object.
* @param {express.Response} res - HTTP Response object.
*/
function getWelcome(req: express.Request, res: express.Response) {
const out = {hello:"world"};
res.send(out);
const out = {hello:"world"}
res.send(out)
}
app.get("/welcome", getWelcome);
/**
* @openapi
* /welcome:
* get:
* description: Welcome to swagger-jsdoc!
* responses:
* 200:
* description: Returns a welcome json.
*/
app.get("/welcome", getWelcome)
export default app;
export default app

View File

@ -1,10 +1,16 @@
import * as dotenv from "dotenv";
import app from "./app";
import options from "./swaggerDef";
const swaggerJsdoc = require("swagger-jsdoc"),
swaggerUi = require("swagger-ui-express");
dotenv.config({path: '../../.env'})
const port = parseInt(process.env.BAR_PORT || '3000')
const specs = swaggerJsdoc(options)
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(specs))
app.listen(port, () =>{
console.log(`serveur running in ${port}`)
})

View File

@ -0,0 +1,25 @@
import * as dotenv from "dotenv";
dotenv.config({path: '../../.env'})
const port = parseInt(process.env.BAR_PORT || '3000')
const options = {
definition: {
openapi: "3.1.0",
info: {
title: "LogRocket Express API with Swagger",
version: "0.1.0",
description:
"This is a simple CRUD API application made with Express and documented with Swagger",
},
servers: [
{
url: "http://localhost:"+port.toString(),
},
],
},
apis: ['./src/*.ts'],
}
export default options