Skip to content

Commit

Permalink
feat(swagger): add swagger settings to the project
Browse files Browse the repository at this point in the history
Refs #94
  • Loading branch information
samuelncaetano committed Jan 30, 2025
1 parent 6817eae commit 32b492c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
43 changes: 43 additions & 0 deletions backend/src/main/config/swaggerConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Express } from "express";
import swaggerJSDoc from "swagger-jsdoc";
import swaggerUi from "swagger-ui-express";

const options = {
definition: {
openapi: "3.0.0",
info: {
title: "API Documentation",
version: "1.0.0",
description: "API documentation for the project",
},
servers: [
{
url: "http://localhost:8000",
},
{
url: "https://your-app-name.onrender.com",
},
],
components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
},
},
security: [
{
bearerAuth: [],
},
],
},
apis: ["./src/**/*.ts"], // Caminho para os arquivos que contêm as anotações JSDoc
};

const swaggerSpec = swaggerJSDoc(options);

export const setupSwagger = (app: Express): void => {
app.use("/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
};
3 changes: 3 additions & 0 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import categoryRoutes from "./main/routes/category/categoryRoutes";
import cors from "cors";
import dotenv from "dotenv";
import express from "express";
import { setupSwagger } from "./main/config/swaggerConfig";
import transactionRoutes from "./main/routes/transaction/transactionRoutes";
import userRoutes from "./main/routes/user/userRoutes";

Expand All @@ -17,6 +18,8 @@ app.use(userRoutes);
app.use(categoryRoutes);
app.use(transactionRoutes);

setupSwagger(app);

app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});

0 comments on commit 32b492c

Please sign in to comment.