exp-node-server 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +180 -0
  2. package/bin/cli.js +41 -0
  3. package/package.json +32 -0
  4. package/src/createProject.js +58 -0
  5. package/src/generateModule.js +61 -0
  6. package/src/utils/controllerGenerator.js +70 -0
  7. package/src/utils/routeGenerator.js +27 -0
  8. package/src/utils/routeInjector.js +40 -0
  9. package/src/utils/schemaGenerator.js +11 -0
  10. package/src/utils/serviceGenerator.js +49 -0
  11. package/src/utils/swaggerGenerator.js +112 -0
  12. package/src/utils/swaggerInjector.js +52 -0
  13. package/src/utils/validateModuleName.js +17 -0
  14. package/src/utils/validateProjectName.js +15 -0
  15. package/src/utils/validationGenerator.js +13 -0
  16. package/src/utils.js +26 -0
  17. package/templates/mongoose/.env.example +23 -0
  18. package/templates/mongoose/package.json +45 -0
  19. package/templates/mongoose/readme.md +180 -0
  20. package/templates/mongoose/src/app/configs/index.ts +26 -0
  21. package/templates/mongoose/src/app/errors/castError.ts +23 -0
  22. package/templates/mongoose/src/app/errors/duplicateError.ts +26 -0
  23. package/templates/mongoose/src/app/errors/validationError.ts +25 -0
  24. package/templates/mongoose/src/app/errors/zodError.ts +20 -0
  25. package/templates/mongoose/src/app/middlewares/auth.ts +50 -0
  26. package/templates/mongoose/src/app/middlewares/global_error_handler.ts +69 -0
  27. package/templates/mongoose/src/app/middlewares/not_found_api.ts +10 -0
  28. package/templates/mongoose/src/app/middlewares/request_validator.ts +14 -0
  29. package/templates/mongoose/src/app/middlewares/uploader.ts +16 -0
  30. package/templates/mongoose/src/app/modules/auth/auth.controller.ts +125 -0
  31. package/templates/mongoose/src/app/modules/auth/auth.interface.ts +24 -0
  32. package/templates/mongoose/src/app/modules/auth/auth.route.ts +46 -0
  33. package/templates/mongoose/src/app/modules/auth/auth.schema.ts +19 -0
  34. package/templates/mongoose/src/app/modules/auth/auth.service.ts +306 -0
  35. package/templates/mongoose/src/app/modules/auth/auth.swagger.ts +214 -0
  36. package/templates/mongoose/src/app/modules/auth/auth.validation.ts +37 -0
  37. package/templates/mongoose/src/app/modules/user/user.controller.ts +17 -0
  38. package/templates/mongoose/src/app/modules/user/user.interface.ts +15 -0
  39. package/templates/mongoose/src/app/modules/user/user.route.ts +20 -0
  40. package/templates/mongoose/src/app/modules/user/user.schema.ts +22 -0
  41. package/templates/mongoose/src/app/modules/user/user.service.ts +22 -0
  42. package/templates/mongoose/src/app/modules/user/user.swagger.ts +75 -0
  43. package/templates/mongoose/src/app/modules/user/user.validation.ts +18 -0
  44. package/templates/mongoose/src/app/types/error.d.ts +10 -0
  45. package/templates/mongoose/src/app/types/index.d.ts +12 -0
  46. package/templates/mongoose/src/app/utils/JWT.ts +26 -0
  47. package/templates/mongoose/src/app/utils/app_error.ts +12 -0
  48. package/templates/mongoose/src/app/utils/catch_async.ts +13 -0
  49. package/templates/mongoose/src/app/utils/cloudinary.ts +66 -0
  50. package/templates/mongoose/src/app/utils/isAccountExist.ts +31 -0
  51. package/templates/mongoose/src/app/utils/mail_sender.ts +102 -0
  52. package/templates/mongoose/src/app/utils/manage_response.ts +24 -0
  53. package/templates/mongoose/src/app.ts +42 -0
  54. package/templates/mongoose/src/routes.ts +13 -0
  55. package/templates/mongoose/src/server.ts +18 -0
  56. package/templates/mongoose/src/swaggerOptions.ts +44 -0
  57. package/templates/mongoose/tsconfig.json +20 -0
package/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # ⚡ Express + Mongoose + TypeScript Module Generator
2
+
3
+ [![npm version](https://img.shields.io/npm/v/exp-cli-gen.svg)](https://www.npmjs.com/package/exp-cli-gen)
4
+ [![npm downloads](https://img.shields.io/npm/dw/exp-cli-gen.svg)](https://www.npmjs.com/package/exp-cli-gen)
5
+ [![npm total downloads](https://img.shields.io/npm/dt/exp-cli-gen.svg)](https://www.npmjs.com/package/exp-cli-gen)
6
+ [![GitHub stars](https://img.shields.io/github/stars/abumahid/mongo-server-stater-pack.svg)](https://github.com/abumahid/mongo-server-stater-pack/stargazers)
7
+ [![GitHub issues](https://img.shields.io/github/issues/abumahid/mongo-server-stater-pack.svg)](https://github.com/abumahid/mongo-server-stater-pack/issues)
8
+ [![License](https://img.shields.io/github/license/abumahid/mongo-server-stater-pack.svg)](https://github.com/abumahid/mongo-server-stater-pack/blob/main/LICENSE)
9
+ [![GitHub last commit](https://img.shields.io/github/last-commit/abumahid/mongo-server-stater-pack.svg)](https://github.com/abumahid/mongo-server-stater-pack/commits/main)
10
+ [![Made with TypeScript](https://img.shields.io/badge/Made%20with-TypeScript-blue.svg)](https://www.typescriptlang.org/)
11
+ [![Node.js](https://img.shields.io/badge/Node.js-18+-green.svg)](https://nodejs.org/)
12
+
13
+ ---
14
+
15
+ ## 🚀 Overview
16
+
17
+ **exp-cli-gen** is a powerful **Express + TypeScript module generator** that uses **Mongoose** for database interaction.
18
+ It automatically creates a complete module structure — including **models, controllers, services, routes, Zod validations, and Swagger documentation** — all in one command.
19
+
20
+ Ideal for developers who want to quickly scaffold modular Express APIs with clean architecture and ready-to-use integrations.
21
+
22
+ ---
23
+
24
+ ## ✨ Features
25
+
26
+ - ⚙️ Generates full-featured Express + TypeScript modules
27
+ - 🧩 Automatically integrates Mongoose models and Zod validations
28
+ - 📘 Adds Swagger documentation automatically
29
+ - 🚀 Clones and sets up a ready-to-run Express starter project
30
+ - 🔁 Can add new modules anytime with a single command
31
+ - 🧠 Skips redundant setup if the starter pack already exists
32
+ - 💪 Built for scalability and maintainability
33
+
34
+ ---
35
+
36
+ ## 📦 Installation
37
+
38
+ Install globally:
39
+
40
+ ```bash
41
+ npm install -g exp-cli-gen
42
+ ```
43
+ Or run directly using npx (recommended):
44
+
45
+ ```bash
46
+ npx exp-cli-gen <module-name>
47
+ ```
48
+ ## Usage
49
+ 🏗️ Generate your first module
50
+
51
+ Run:
52
+
53
+ ```bash
54
+ npx exp-cli-gen test
55
+ ```
56
+ First run example:
57
+
58
+ ```bash
59
+ Need to install the following packages:
60
+ exp-cli-gen@1.0.1
61
+ Ok to proceed? (y)
62
+
63
+ ⠋ No Express project found. Cloning starter pack...
64
+ ✔ Starter project cloned!
65
+
66
+ ✔ Git logs removed!
67
+
68
+ 📦 Installing dependencies...
69
+
70
+ 🚀 Project setup complete.
71
+ 🧩 Generating module: test...
72
+ ✔ test.interface.ts created
73
+ ✔ test.schema.ts created
74
+ ✔ test.validation.ts created
75
+ ✔ test.route.ts created
76
+ ✔ test.controller.ts created
77
+ ✔ test.service.ts created
78
+ ✔ test.swagger.ts created
79
+
80
+ 🔗 Route added to src/app/routes.ts
81
+ 📘 Swagger doc added to src/swaggerOptions.ts
82
+ ✨ Module 'test' created successfully!
83
+
84
+ ```
85
+
86
+ ## 📁 Generated Module Structure
87
+
88
+ Each generated module will contain the following files:
89
+
90
+ ```pgsql
91
+ src/app/modules/<module-name>/
92
+ ├── <module-name>.interface.ts
93
+ ├── <module-name>.schema.ts
94
+ ├── <module-name>.validation.ts
95
+ ├── <module-name>.route.ts
96
+ ├── <module-name>.controller.ts
97
+ ├── <module-name>.service.ts
98
+ └── <module-name>.swagger.ts
99
+ ```
100
+
101
+ ## 🔄 Add More Modules
102
+
103
+ Need another module? Just run:
104
+
105
+ ```bash
106
+ npx exp-cli-gen products
107
+ ```
108
+
109
+ If the starter project already exists, it will skip cloning and directly add the new module.
110
+
111
+ Example output:
112
+ ```bash
113
+ ℹ 📦 Starter folder already exists. Skipping clone.
114
+ 📦 Dependencies already installed. Skipping npm install.
115
+ 🧩 Generating module: products...
116
+ ✔ products files created
117
+ ✨ Module 'products' created successfully!
118
+
119
+ src/app/modules/products/
120
+ ├── products.interface.ts
121
+ ├── products.schema.ts
122
+ ├── products.validation.ts
123
+ ├── products.route.ts
124
+ ├── products.controller.ts
125
+ ├── products.service.ts
126
+ └── products.swagger.ts
127
+ ```
128
+
129
+ Then, refresh your Swagger docs at:
130
+ ```bash
131
+ http://localhost:5000/docs
132
+ ```
133
+
134
+ You’ll see your new routes automatically added.
135
+
136
+ ---
137
+
138
+ ## ⚙️ Configuration
139
+
140
+ After setup, update your .env file following the .env.example file in the starter project.
141
+
142
+ To start the server:
143
+ ```bash
144
+ npm run dev
145
+ ```
146
+ Open Swagger documentation at:
147
+ ```bash
148
+ http://localhost:5000/docs
149
+ ```
150
+
151
+ ---
152
+ ## 🧠 Tech Stack
153
+
154
+ - Express.js — Backend framework
155
+ - TypeScript — Strongly typed JavaScript
156
+ - Mongoose — MongoDB ORM
157
+ - Zod — Runtime schema validation
158
+ - Swagger — API documentation
159
+ - CLI (Node.js) — Command-line automation
160
+
161
+ ---
162
+ ## 🧩 Starter Pack Repository
163
+
164
+ This CLI uses the following base project as a starter:
165
+
166
+ 👉 [mongo-server-stater-pack](https://github.com/abumahid/mongo-server-stater-pack.git)
167
+
168
+ ---
169
+ ## 💬 Author
170
+
171
+ Abu Mahid
172
+
173
+ 🧠 [GitHub Profile](https://github.com/abumahid)
174
+
175
+ 💼 [npm Profile](https://www.npmjs.com/~dev_abumahid)
176
+
177
+ ---
178
+ ### ⭐ Star this project
179
+
180
+ If you like this CLI, please give it a ⭐ on GitHub — it helps others discover it too! Thank you!
package/bin/cli.js ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+
3
+ import chalk from "chalk";
4
+ import { createProject } from "../src/createProject.js";
5
+ import { generateModule } from "../src/generateModule.js";
6
+ import { validateModuleName } from "../src/utils/validateModuleName.js";
7
+ import { validateProjectName } from "../src/utils/validateProjectName.js";
8
+
9
+ const args = process.argv.slice(2);
10
+
11
+ if (!args.length) {
12
+ console.log(chalk.yellow("Usage:"));
13
+ console.log(" npx express-server -c <project-name>");
14
+ console.log(" npx express-server -g <module-name>");
15
+ process.exit(0);
16
+ }
17
+
18
+ const command = args[0];
19
+
20
+ if (command === "-c") {
21
+ const projectName = validateProjectName(args[1]);
22
+
23
+ if (!projectName) {
24
+ console.log(chalk.red("❌ Project name required"));
25
+ process.exit(1);
26
+ }
27
+
28
+ await createProject(projectName);
29
+ } else if (command === "-g") {
30
+ const moduleName = validateModuleName(args[1]);
31
+
32
+ if (!moduleName) {
33
+ console.log(chalk.red("❌ Module name required"));
34
+ process.exit(1);
35
+ }
36
+ await generateModule(moduleName);
37
+ }
38
+ else {
39
+ console.log(chalk.red("❌ Invalid command, use -c or -g"));
40
+ process.exit(1);
41
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "exp-node-server",
3
+ "version": "1.1.0",
4
+ "type": "module",
5
+ "bin": {
6
+ "exp-node-server": "./bin/cli.js"
7
+ },
8
+ "files": [
9
+ "bin",
10
+ "src",
11
+ "templates"
12
+ ],
13
+ "dependencies": {
14
+ "chalk": "^5.3.0",
15
+ "ora": "^7.0.1",
16
+ "inquirer": "^9.2.7"
17
+ },
18
+ "keywords": [
19
+ "express",
20
+ "mongoose",
21
+ "typescript",
22
+ "cli",
23
+ "generator",
24
+ "nodejs",
25
+ "api",
26
+ "module-generator",
27
+ "exp-cli-gen"
28
+ ],
29
+ "engines": {
30
+ "node": ">=20.0.0"
31
+ }
32
+ }
@@ -0,0 +1,58 @@
1
+ import chalk from "chalk";
2
+ import fs from "fs";
3
+ import inquirer from "inquirer";
4
+ import ora from "ora";
5
+ import path from "path";
6
+ import { fileURLToPath } from "url";
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+
10
+ export async function createProject(projectName) {
11
+
12
+ // ask user template
13
+ const answers = await inquirer.prompt([
14
+ {
15
+ type: "list",
16
+ name: "template",
17
+ message: "Select a project template:",
18
+ choices: [
19
+ { name: "Mongoose (MongoDB)", value: "mongoose" },
20
+ { name: "Prisma (PostgreSQL)", value: "prisma" },
21
+ ],
22
+ },
23
+ ]);
24
+
25
+ const template = answers.template;
26
+
27
+ const templateDir = path.join(
28
+ __dirname,
29
+ `../templates/${template}`
30
+ );
31
+
32
+ const targetDir = path.join(process.cwd(), projectName);
33
+
34
+ if (fs.existsSync(targetDir)) {
35
+ console.log(chalk.red("❌ Folder already exists"));
36
+ process.exit(1);
37
+ }
38
+
39
+ const spinner = ora(`Creating ${template} project...`).start();
40
+
41
+ try {
42
+
43
+ fs.cpSync(templateDir, targetDir, {
44
+ recursive: true,
45
+ });
46
+
47
+ spinner.succeed("Project created successfully");
48
+
49
+ console.log(chalk.green(`\nNext steps:`));
50
+ console.log(chalk.cyan(`cd ${projectName}`));
51
+ console.log(chalk.cyan(`npm install`));
52
+ console.log(chalk.cyan(`npm run dev`));
53
+
54
+ } catch (err) {
55
+ spinner.fail("Failed to create project");
56
+ console.error(err);
57
+ }
58
+ }
@@ -0,0 +1,61 @@
1
+ import chalk from "chalk";
2
+ import path from "path";
3
+ import { createDir, createFile } from "./utils.js";
4
+ import { controllerGenerator } from "./utils/controllerGenerator.js";
5
+ import { routeGenerator } from "./utils/routeGenerator.js";
6
+ import { injectRoute } from "./utils/routeInjector.js";
7
+ import { schemaGenerator } from "./utils/schemaGenerator.js";
8
+ import { serviceGenerator } from "./utils/serviceGenerator.js";
9
+ import { swaggerGenerator } from "./utils/swaggerGenerator.js";
10
+ import { injectSwagger } from "./utils/swaggerInjector.js";
11
+ import { validationGenerator } from "./utils/validationGenerator.js";
12
+
13
+ export async function generateModule(name) {
14
+
15
+ const base = path.join(
16
+ process.cwd(),
17
+ "src/app/modules",
18
+ name
19
+ );
20
+
21
+ createDir(base);
22
+
23
+ createFile(
24
+ path.join(base, `${name}.controller.ts`),
25
+ controllerGenerator(name)
26
+ );
27
+
28
+ createFile(
29
+ path.join(base, `${name}.service.ts`),
30
+ serviceGenerator(name)
31
+ );
32
+
33
+ createFile(
34
+ path.join(base, `${name}.route.ts`),
35
+ routeGenerator(name)
36
+ );
37
+
38
+ createFile(
39
+ path.join(base, `${name}.schema.ts`),
40
+ schemaGenerator(name)
41
+ );
42
+
43
+ createFile(
44
+ path.join(base, `${name}.interface.ts`),
45
+ `export type T_${name} = {
46
+ }`
47
+ );
48
+
49
+ createFile(
50
+ path.join(base, `${name}.validation.ts`),
51
+ validationGenerator(name)
52
+ );
53
+ createFile(
54
+ path.join(base, `${name}.swagger.ts`),
55
+ swaggerGenerator(name)
56
+ );
57
+ injectRoute(name);
58
+ injectSwagger(name);
59
+
60
+ console.log(chalk.green(`\nModule '${name}' created successfully`));
61
+ }
@@ -0,0 +1,70 @@
1
+ export const controllerGenerator = (name) => {
2
+ return `
3
+ import catchAsync from "../../utils/catch_async";
4
+ import manageResponse from "../../utils/manage_response";
5
+ import { ${name}_service } from "./${name}.service";
6
+
7
+ const get_all_${name} = catchAsync(async (req, res) => {
8
+ const result = await ${name}_service.get_all_${name}_from_db(req);
9
+ manageResponse(res, {
10
+ success: true,
11
+ statusCode: 200,
12
+ message: "All ${name} fetched successfully.",
13
+ data: result,
14
+ meta: {},
15
+ });
16
+ });
17
+
18
+ const get_single_${name} = catchAsync(async (req, res) => {
19
+ const result = await ${name}_service.get_single_${name}_from_db(req);
20
+ manageResponse(res, {
21
+ success: true,
22
+ statusCode: 200,
23
+ message: "Single ${name} fetched successfully.",
24
+ data: result,
25
+ meta: {},
26
+ });
27
+ });
28
+
29
+ const create_${name} = catchAsync(async (req, res) => {
30
+ const result = await ${name}_service.create_${name}_into_db(req);
31
+ manageResponse(res, {
32
+ success: true,
33
+ statusCode: 200,
34
+ message: "${name} created successfully.",
35
+ data: result,
36
+ meta: {},
37
+ });
38
+ });
39
+
40
+ const update_${name} = catchAsync(async (req, res) => {
41
+ const result = await ${name}_service.update_${name}_into_db(req);
42
+ manageResponse(res, {
43
+ success: true,
44
+ statusCode: 200,
45
+ message: "${name} updated successfully.",
46
+ data: result,
47
+ meta: {},
48
+ });
49
+ });
50
+
51
+ const delete_${name} = catchAsync(async (req, res) => {
52
+ const result = await ${name}_service.delete_${name}_from_db(req);
53
+ manageResponse(res, {
54
+ success: true,
55
+ statusCode: 200,
56
+ message: "${name} deleted successfully.",
57
+ data: result,
58
+ meta: {},
59
+ });
60
+ });
61
+
62
+ export const ${name}_controller = {
63
+ get_all_${name},
64
+ get_single_${name},
65
+ create_${name},
66
+ update_${name},
67
+ delete_${name},
68
+ };
69
+ `
70
+ }
@@ -0,0 +1,27 @@
1
+ export const routeGenerator = (name) => {
2
+
3
+ return `
4
+ import { Router } from "express";
5
+ import RequestValidator from "../../middlewares/request_validator";
6
+ import { ${name}_controller } from "./${name}.controller";
7
+ import { ${name}_validations } from "./${name}.validation";
8
+
9
+ const router = Router();
10
+
11
+ router.get("/", ${name}_controller.get_all_${name});
12
+ router.post(
13
+ "/",
14
+ RequestValidator(${name}_validations.create_${name}),
15
+ ${name}_controller.create_${name},
16
+ );
17
+ router.get("/:id", ${name}_controller.get_single_${name});
18
+ router.patch(
19
+ "/:id",
20
+ RequestValidator(${name}_validations.update_${name}),
21
+ ${name}_controller.update_${name},
22
+ );
23
+ router.delete("/:id", ${name}_controller.delete_${name});
24
+
25
+ export default router;
26
+ `
27
+ }
@@ -0,0 +1,40 @@
1
+ import chalk from "chalk";
2
+ import fs from "fs";
3
+ import path from "path";
4
+
5
+ export function injectRoute(name) {
6
+ const routeFile = path.join(process.cwd(), "src/routes.ts");
7
+
8
+ if (!fs.existsSync(routeFile)) {
9
+ console.log(chalk.yellow("routes.ts not found"));
10
+ return;
11
+ }
12
+
13
+ let content = fs.readFileSync(routeFile, "utf-8");
14
+
15
+ const importLine = `import ${name}Route from "./app/modules/${name}/${name}.route";`;
16
+ const routeEntry = `{ path: "/${name}", route: ${name}Route },`;
17
+
18
+ // add import
19
+ if (!content.includes(importLine)) {
20
+ const lastImportIndex = content.lastIndexOf("import ");
21
+ const nextLine = content.indexOf("\n", lastImportIndex);
22
+
23
+ content =
24
+ content.slice(0, nextLine + 1) +
25
+ importLine +
26
+ "\n" +
27
+ content.slice(nextLine + 1);
28
+ }
29
+
30
+ // add route entry
31
+ if (!content.includes(routeEntry)) {
32
+ content = content.replace(
33
+ /const moduleRoutes = \[/,
34
+ `const moduleRoutes = [\n ${routeEntry}`
35
+ );
36
+ }
37
+
38
+ fs.writeFileSync(routeFile, content);
39
+ console.log(chalk.green(`Route registered for ${name}`));
40
+ }
@@ -0,0 +1,11 @@
1
+ export const schemaGenerator = (name) => {
2
+ return `
3
+ import { Schema, model } from "mongoose";
4
+ import { T_${name} } from "./${name}.interface";
5
+
6
+ const schema = new Schema<T_${name}>({});
7
+
8
+ export const ${name}_model = model("${name}", schema);
9
+
10
+ `
11
+ }
@@ -0,0 +1,49 @@
1
+ export const serviceGenerator = (name) => {
2
+ return `
3
+ import { Request } from "express";
4
+ import { ${name}_model } from "./${name}.schema";
5
+
6
+ const get_all_${name}_from_db = async (req: Request) => {
7
+ // define your own login here
8
+ const result = await ${name}_model.find().lean();
9
+ return result;
10
+ };
11
+
12
+ const get_single_${name}_from_db = async (req: Request) => {
13
+ // define your own login here
14
+ const { id } = req.params;
15
+ const result = await ${name}_model.findById(id).lean();
16
+ return result;
17
+ };
18
+
19
+ const create_${name}_into_db = async (req: Request) => {
20
+ // define your own login here
21
+ const result = await ${name}_model.create(req.body);
22
+ return result;
23
+ };
24
+
25
+ const update_${name}_into_db = async (req: Request) => {
26
+ // define your own login here
27
+ const { id } = req.params;
28
+ const result = await ${name}_model.findByIdAndUpdate(id, req.body, {
29
+ new: true,
30
+ });
31
+ return result;
32
+ };
33
+
34
+ const delete_${name}_from_db = async (req: Request) => {
35
+ // define your own login here
36
+ const { id } = req.params;
37
+ const result = await ${name}_model.findByIdAndDelete(id);
38
+ return result;
39
+ };
40
+
41
+ export const ${name}_service = {
42
+ get_all_${name}_from_db,
43
+ get_single_${name}_from_db,
44
+ create_${name}_into_db,
45
+ update_${name}_into_db,
46
+ delete_${name}_from_db,
47
+ };
48
+ `
49
+ }
@@ -0,0 +1,112 @@
1
+ export const swaggerGenerator = (name) => {
2
+ return `
3
+ export const ${name}SwaggerDocs = {
4
+ "/api/${name}": {
5
+ post: {
6
+ tags: ["${name}"],
7
+ summary: "Create new ${name}",
8
+ description: "",
9
+ requestBody: {
10
+ required: true,
11
+ content: {
12
+ "application/json": {
13
+ example: JSON.stringify({}), // put your request body
14
+ },
15
+ },
16
+ },
17
+ responses: {
18
+ 201: { description: "${name} created successfully" },
19
+ 500: { description: "Validation error or internal server error" },
20
+ },
21
+ },
22
+ get: {
23
+ tags: ["${name}"],
24
+ summary: "Get all ${name}",
25
+ description: "",
26
+ parameters: [
27
+ {
28
+ name: "page",
29
+ in: "query",
30
+ required: false,
31
+ schema: { type: "number" },
32
+ },
33
+ {
34
+ name: "limit",
35
+ in: "query",
36
+ required: false,
37
+ schema: { type: "number" },
38
+ },
39
+ ],
40
+ responses: {
41
+ 200: { description: "${name} fetched successfully" },
42
+ 401: { description: "unauthorized" },
43
+ },
44
+ },
45
+ },
46
+
47
+ "/api/${name}/{id}": {
48
+ get: {
49
+ tags: ["${name}"],
50
+ summary: "Get single ${name}",
51
+ description: "",
52
+ parameters: [
53
+ {
54
+ name: "id",
55
+ in: "path",
56
+ required: true,
57
+ schema: { type: "string" },
58
+ },
59
+ ],
60
+ responses: {
61
+ 200: { description: "${name} fetched successfully" },
62
+ 401: { description: "unauthorized" },
63
+ },
64
+ },
65
+ patch: {
66
+ tags: ["${name}"],
67
+ summary: "Update ${name}",
68
+ description: "",
69
+ parameters: [
70
+ {
71
+ name: "id",
72
+ in: "path",
73
+ required: true,
74
+ schema: { type: "string" },
75
+ },
76
+ ],
77
+ requestBody: {
78
+ required: true,
79
+ content: {
80
+ "application/json": {
81
+ example: JSON.stringify({}), // put your request body
82
+ },
83
+ },
84
+ },
85
+ responses: {
86
+ 200: { description: "${name} updated successfully" },
87
+ 500: { description: "Validation error or internal server error" },
88
+ },
89
+ },
90
+ delete: {
91
+ tags: ["${name}"],
92
+ summary: "Delete ${name}",
93
+ description: "",
94
+ parameters: [
95
+ {
96
+ name: "id",
97
+ in: "path",
98
+ required: true,
99
+ schema: { type: "string" },
100
+ },
101
+ ],
102
+ responses: {
103
+ 200: { description: "${name} delete successfully" },
104
+ 401: { description: "unauthorized" },
105
+ },
106
+ },
107
+ },
108
+ };
109
+
110
+
111
+ `
112
+ }