Skip to content

Commit

Permalink
added swagger ui
Browse files Browse the repository at this point in the history
Signed-off-by: Tanmay Vaij <tanmayvaij22@gmail.com>
  • Loading branch information
tanmayvaij committed Jun 25, 2024
1 parent 9267ffa commit 0ab634c
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 9 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@
"build": "tsc -p ."
},
"dependencies": {
"@types/swagger-jsdoc": "^6.0.4",
"@types/swagger-ui-express": "^4.1.6",
"bcrypt": "^5.1.1",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.19.2",
"js-yaml": "^4.1.0",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.4.0"
"mongoose": "^8.4.0",
"swagger-jsdoc": "^6.2.8",
"swagger-ui-express": "^5.0.1"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/js-yaml": "^4.0.9",
"@types/jsonwebtoken": "^9.0.6",
"@types/node": "^20.12.12",
"nodemon": "^3.1.1",
Expand Down
117 changes: 117 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,130 @@ import { connectToDatabase } from "./database";

import { checkEnvVariables } from "./utils/checkEnvVariables";

import swaggerJSDoc from "swagger-jsdoc";
import { serve, setup } from "swagger-ui-express";

config();

const app = express();

app.use(cors());
app.use(express.json());

const options: swaggerJSDoc.Options = {
definition: {
openapi: "3.1.0",

basePath: "http://localhost:5000",

schemes: ["Hello ", "1", "2"],

tags: [{ name: "Authentication", description: "Sample tag desc" }],

host: "http://localhost:5000",

swagger: "aojvoja",

consumes: ["aojrg", "oav"],

externalDocs: {
url:""
},

produces:["fg", "fg"],

info: {
title: "UAuthX API Docs",
version: "1.0.0",
contact: {
email: "tanmayvaij22@gmail.com",
name: "Tanmay Vaij",
url: "https://www.github.com/tanmayvaij"
},
description:
"This is an interactive api documentation for uauthx authentication micro-service",
license: {
name: "MIT",
url: "",
},
termsOfService: "",
},

servers: [
{
url: "http://localhost:5000",
description: "",
},
],

paths: {
"/auth/sign-up": {
post: {
summary: "User sign up",
tags: ["Authentication"],

requestBody: {
required: true,
content: {
"application/json": {
schema: {
type: "object",
required: ["email", "password"],
properties: {
email: {
type: "string",
format: "email",
example: "johndoe@example.com",
},
password: {
type: "string",
format: "password",
example: "Strong_Password@123",
},
},
},
},
},
},

responses: {
"200": {
description: "",
content: {
"application/json": {
schema: {
type: "object",
properties: {
isSucess: {
type: "boolean",
example: "true",
},
authToken: {
type: "string",
example: "<your-auth-token>",
},
},
},
},
},
},
},
},
},

"/auth/sign-in": {
post: {
tags: ["Authentication"],
},
},
},
},

apis: [],
};

app.use("/api-docs", serve, setup(swaggerJSDoc(options)));

app.use("/", rootRouter);

const startServer = async () => {
Expand Down
Loading

0 comments on commit 0ab634c

Please sign in to comment.