Skip to content

Commit

Permalink
documented 3 endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Tanmay Vaij <tanmayvaij22@gmail.com>
  • Loading branch information
tanmayvaij committed Jul 3, 2024
1 parent 4df6126 commit b4863d3
Showing 1 changed file with 297 additions and 11 deletions.
308 changes: 297 additions & 11 deletions src/utils/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@ import swaggerJSDoc from "swagger-jsdoc";
import { serve, setup } from "swagger-ui-express";
import { Express } from "express";

interface PathOptions {
[endpoint: string]: {
post?: {
summary?: string;
tags?: string[];

requestBody?: {
required?: boolean;
};
};
};
}

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

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

info: {
Expand All @@ -37,6 +54,20 @@ const options: swaggerJSDoc.Options = {
},
],

components: {
securitySchemes: {
bearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
basicAuth: {
type: "http",
scheme: "basic",
},
},
},

paths: {
"/auth/sign-up": {
post: {
Expand Down Expand Up @@ -115,7 +146,269 @@ const options: swaggerJSDoc.Options = {

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

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

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

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

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

"/verify-user": {
get: {
summary: "Verify User",
description: "Verifies the user based on the provided JWT token.",
tags: ["Authentication"],
security: [
{
bearerAuth: [],
},
],
responses: {
"200": {
description: "User successfully verified",
content: {
"application/json": {
schema: {
type: "object",
properties: {
isSuccess: {
type: "boolean",
example: true,
},
userId: {
type: "string",
example: "12345",
},
},
},
},
},
},
"401": {
description: "Unauthorized - Token not provided or invalid",
content: {
"application/json": {
schema: {
type: "object",
properties: {
isSucess: {
type: "boolean",
example: false,
},
message: {
type: "string",
example: "Token not provided",
},
},
},
},
},
},
"500": {
description: "Internal Server Error",
content: {
"application/json": {
schema: {
type: "object",
properties: {
isSuccess: {
type: "boolean",
example: false,
},
error: {
type: "string",
example: "Error message",
},
},
},
},
},
},
},
},
},

"/admin/list-users": {
get: {
tags: ["Admin"],
summary: "List users",
security: [
{
basicAuth: [],
},
],
description:
"An endpoint to list users, accessible only by admin with basic authentication",
responses: {
"200": {
description: "Successful response",
content: {
"application/json": {
schema: {
type: "object",
properties: {
isSuccess: {
type: "boolean",
},
users: {
type: "array",
items: {
type: "object",
properties: {
id: {
type: "string",
},
username: {
type: "string",
},
// Add other user properties as necessary
},
},
},
},
},
},
},
},
"401": {
description: "Authorization token not found in the headers",
content: {
"application/json": {
schema: {
type: "object",
properties: {
isSuccess: {
type: "boolean",
},
error: {
type: "string",
},
},
},
},
},
},
"403": {
description: "Invalid admin credentials",
content: {
"application/json": {
schema: {
type: "object",
properties: {
isSuccess: {
type: "boolean",
},
error: {
type: "string",
},
},
},
},
},
},
"500": {
description: "Server error",
content: {
"application/json": {
schema: {
type: "object",
properties: {
isSuccess: {
type: "boolean",
},
error: {
type: "string",
},
},
},
},
},
},
},
},
},
},
Expand All @@ -127,10 +420,3 @@ const options: swaggerJSDoc.Options = {
export const startSwagger = (app: Express) => {
app.use("/api-docs", serve, setup(swaggerJSDoc(options)));
};


interface P {
"200": {

}
}

0 comments on commit b4863d3

Please sign in to comment.