Skip to content

Commit

Permalink
removed unwanted props from swagger
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 26, 2024
1 parent 0ab634c commit 4df6126
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 121 deletions.
118 changes: 2 additions & 116 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { rootRouter } from "./routers";
import { connectToDatabase } from "./database";

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

import swaggerJSDoc from "swagger-jsdoc";
import { serve, setup } from "swagger-ui-express";
import { startSwagger } from "./utils/swagger";

config();

Expand All @@ -17,119 +15,7 @@ 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)));
startSwagger(app)

app.use("/", rootRouter);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request, Response } from "express";
import { User } from "../models";
import { User } from "../../models";
import { compare } from "bcrypt";
import { sign } from "jsonwebtoken";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request, Response } from "express";
import { User } from "../models";
import { User } from "../../models";
import { sign } from "jsonwebtoken";

// Sign up request handler
Expand All @@ -8,6 +8,8 @@ export const signUp = async (
res: Response
) => {
try {
console.log("/auth/sign-up api called");

// Checking if already the given email exists is database or not
const userExists = await User.findOne({ email: req.body.email });

Expand All @@ -28,6 +30,7 @@ export const signUp = async (
const authToken = sign(payload, process.env.SECRET_KEY!);

return res.json({ isSuccess: true, authToken });

} catch (error) {
return res.status(500).json({ isSuccess: false, error });
}
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions src/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./signIn.handler";
export * from "./signUp.handler";
export * from "./verifyUser.handler";
export * from "./auth/signIn.handler";
export * from "./auth/signUp.handler";
export * from "./auth/verifyUser.handler";

// admin routes
export * from "./admin/listUsers.handler";
136 changes: 136 additions & 0 deletions src/utils/swagger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import swaggerJSDoc from "swagger-jsdoc";
import { serve, setup } from "swagger-ui-express";
import { Express } from "express";

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

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

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>",
},
},
},
},
},
},

"409": {
description: "",
content: {
"application/json": {
schema: {
type: "object",
properties: {
isSuccess: {
type: "boolean",
example: false,
},
error: {
type: "string",
example: "Invalid username or password",
},
},
},
},
},
},
},
},
},

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

apis: [],
};

export const startSwagger = (app: Express) => {
app.use("/api-docs", serve, setup(swaggerJSDoc(options)));
};


interface P {
"200": {

}
}

0 comments on commit 4df6126

Please sign in to comment.