create-charcole 2.2.0 → 2.2.2
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.
- package/.github/workflows/release.yml +26 -26
- package/CHANGELOG.md +301 -301
- package/LICENSE +21 -21
- package/README.md +357 -354
- package/bin/index.js +494 -444
- package/bin/lib/pkgManager.js +49 -49
- package/bin/lib/templateHandler.js +33 -33
- package/package.json +42 -27
- package/packages/swagger/BACKWARD_COMPATIBILITY.md +1 -1
- package/packages/swagger/CHANGELOG.md +1 -1
- package/packages/swagger/README.md +3 -3
- package/packages/swagger/package.json +57 -44
- package/packages/swagger/src/index.d.ts +126 -126
- package/packages/swagger/src/index.js +12 -12
- package/packages/swagger/src/setup.js +100 -100
- package/template/js/.env.example +16 -15
- package/template/js/README.md +982 -978
- package/template/js/basePackage.json +26 -26
- package/template/js/src/app.js +81 -81
- package/template/js/src/config/constants.js +20 -20
- package/template/js/src/config/env.js +26 -26
- package/template/js/src/config/swagger.config.js +15 -15
- package/template/js/src/lib/swagger/SWAGGER_GUIDE.md +3 -3
- package/template/js/src/middlewares/errorHandler.js +180 -180
- package/template/js/src/middlewares/requestLogger.js +33 -33
- package/template/js/src/middlewares/validateRequest.js +42 -42
- package/template/js/src/modules/auth/auth.constants.js +3 -3
- package/template/js/src/modules/auth/auth.controller.js +29 -29
- package/template/js/src/modules/auth/auth.middlewares.js +19 -19
- package/template/js/src/modules/auth/auth.routes.js +131 -131
- package/template/js/src/modules/auth/auth.schemas.js +60 -60
- package/template/js/src/modules/auth/auth.service.js +67 -67
- package/template/js/src/modules/auth/package.json +6 -6
- package/template/js/src/modules/health/controller.js +151 -151
- package/template/js/src/modules/swagger/package.json +5 -5
- package/template/js/src/repositories/user.repo.js +19 -19
- package/template/js/src/routes/index.js +25 -25
- package/template/js/src/routes/protected.js +57 -57
- package/template/js/src/server.js +38 -38
- package/template/js/src/utils/AppError.js +182 -182
- package/template/js/src/utils/logger.js +73 -73
- package/template/js/src/utils/response.js +51 -51
- package/template/ts/.env.example +16 -15
- package/template/ts/README.md +982 -978
- package/template/ts/basePackage.json +36 -36
- package/template/ts/build.js +46 -46
- package/template/ts/src/app.ts +71 -71
- package/template/ts/src/config/constants.ts +27 -27
- package/template/ts/src/config/env.ts +40 -40
- package/template/ts/src/config/swagger.config.ts +30 -30
- package/template/ts/src/lib/swagger/SWAGGER_GUIDE.md +2 -2
- package/template/ts/src/middlewares/errorHandler.ts +201 -201
- package/template/ts/src/middlewares/requestLogger.ts +38 -38
- package/template/ts/src/middlewares/validateRequest.ts +46 -46
- package/template/ts/src/modules/auth/auth.constants.ts +6 -6
- package/template/ts/src/modules/auth/auth.controller.ts +32 -32
- package/template/ts/src/modules/auth/auth.middlewares.ts +46 -46
- package/template/ts/src/modules/auth/auth.routes.ts +52 -52
- package/template/ts/src/modules/auth/auth.schemas.ts +73 -73
- package/template/ts/src/modules/auth/auth.service.ts +106 -106
- package/template/ts/src/modules/auth/package.json +10 -10
- package/template/ts/src/modules/health/controller.ts +80 -80
- package/template/ts/src/modules/swagger/package.json +5 -5
- package/template/ts/src/repositories/user.repo.ts +33 -33
- package/template/ts/src/routes/index.ts +24 -24
- package/template/ts/src/routes/protected.ts +46 -46
- package/template/ts/src/server.ts +41 -41
- package/template/ts/src/types/express.d.ts +9 -9
- package/template/ts/src/utils/AppError.ts +220 -220
- package/template/ts/src/utils/logger.ts +55 -55
- package/template/ts/src/utils/response.ts +100 -100
- package/template/ts/tsconfig.json +26 -26
- package/packages/swagger/package-lock.json +0 -1715
- package/tmpclaude-1049-cwd +0 -1
- package/tmpclaude-3e37-cwd +0 -1
- package/tmpclaude-4d73-cwd +0 -1
- package/tmpclaude-8a8e-cwd +0 -1
package/bin/lib/pkgManager.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
const { execSync } = require("child_process");
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Detect which package manager the user is using
|
|
7
|
-
* Priority: pnpm > yarn > npm
|
|
8
|
-
*/
|
|
9
|
-
function detectPackageManager() {
|
|
10
|
-
const userAgent = process.env.npm_config_user_agent;
|
|
11
|
-
|
|
12
|
-
if (userAgent) {
|
|
13
|
-
if (userAgent.includes("pnpm")) return "pnpm";
|
|
14
|
-
if (userAgent.includes("yarn")) return "yarn";
|
|
15
|
-
if (userAgent.includes("npm")) return "npm";
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const lockFiles = {
|
|
19
|
-
"pnpm-lock.yaml": "pnpm",
|
|
20
|
-
"yarn.lock": "yarn",
|
|
21
|
-
"package-lock.json": "npm",
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
for (const [lockFile, manager] of Object.entries(lockFiles)) {
|
|
25
|
-
if (fs.existsSync(path.join(process.cwd(), lockFile))) {
|
|
26
|
-
return manager;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return "npm";
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Install dependencies
|
|
35
|
-
*/
|
|
36
|
-
function installDependencies(targetDir, pkgManager) {
|
|
37
|
-
const installCmd =
|
|
38
|
-
pkgManager === "yarn" ? "yarn install" : `${pkgManager} install`;
|
|
39
|
-
|
|
40
|
-
execSync(installCmd, {
|
|
41
|
-
cwd: targetDir,
|
|
42
|
-
stdio: "inherit",
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
module.exports = {
|
|
47
|
-
detectPackageManager,
|
|
48
|
-
installDependencies,
|
|
49
|
-
};
|
|
1
|
+
const { execSync } = require("child_process");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Detect which package manager the user is using
|
|
7
|
+
* Priority: pnpm > yarn > npm
|
|
8
|
+
*/
|
|
9
|
+
function detectPackageManager() {
|
|
10
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
11
|
+
|
|
12
|
+
if (userAgent) {
|
|
13
|
+
if (userAgent.includes("pnpm")) return "pnpm";
|
|
14
|
+
if (userAgent.includes("yarn")) return "yarn";
|
|
15
|
+
if (userAgent.includes("npm")) return "npm";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const lockFiles = {
|
|
19
|
+
"pnpm-lock.yaml": "pnpm",
|
|
20
|
+
"yarn.lock": "yarn",
|
|
21
|
+
"package-lock.json": "npm",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
for (const [lockFile, manager] of Object.entries(lockFiles)) {
|
|
25
|
+
if (fs.existsSync(path.join(process.cwd(), lockFile))) {
|
|
26
|
+
return manager;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return "npm";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Install dependencies
|
|
35
|
+
*/
|
|
36
|
+
function installDependencies(targetDir, pkgManager) {
|
|
37
|
+
const installCmd =
|
|
38
|
+
pkgManager === "yarn" ? "yarn install" : `${pkgManager} install`;
|
|
39
|
+
|
|
40
|
+
execSync(installCmd, {
|
|
41
|
+
cwd: targetDir,
|
|
42
|
+
stdio: "inherit",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports = {
|
|
47
|
+
detectPackageManager,
|
|
48
|
+
installDependencies,
|
|
49
|
+
};
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Recursively copy directory contents, excluding specific files
|
|
6
|
-
*/
|
|
7
|
-
function copyDir(src, dest, excludeFiles = []) {
|
|
8
|
-
if (!fs.existsSync(dest)) {
|
|
9
|
-
fs.mkdirSync(dest, { recursive: true });
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
13
|
-
|
|
14
|
-
for (const entry of entries) {
|
|
15
|
-
const srcPath = path.join(src, entry.name);
|
|
16
|
-
const destPath = path.join(dest, entry.name);
|
|
17
|
-
|
|
18
|
-
// Skip excluded files
|
|
19
|
-
if (excludeFiles.includes(entry.name)) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (entry.isDirectory()) {
|
|
24
|
-
copyDir(srcPath, destPath, excludeFiles);
|
|
25
|
-
} else {
|
|
26
|
-
fs.copyFileSync(srcPath, destPath);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = {
|
|
32
|
-
copyDir,
|
|
33
|
-
};
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Recursively copy directory contents, excluding specific files
|
|
6
|
+
*/
|
|
7
|
+
function copyDir(src, dest, excludeFiles = []) {
|
|
8
|
+
if (!fs.existsSync(dest)) {
|
|
9
|
+
fs.mkdirSync(dest, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
13
|
+
|
|
14
|
+
for (const entry of entries) {
|
|
15
|
+
const srcPath = path.join(src, entry.name);
|
|
16
|
+
const destPath = path.join(dest, entry.name);
|
|
17
|
+
|
|
18
|
+
// Skip excluded files
|
|
19
|
+
if (excludeFiles.includes(entry.name)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (entry.isDirectory()) {
|
|
24
|
+
copyDir(srcPath, destPath, excludeFiles);
|
|
25
|
+
} else {
|
|
26
|
+
fs.copyFileSync(srcPath, destPath);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = {
|
|
32
|
+
copyDir,
|
|
33
|
+
};
|
package/package.json
CHANGED
|
@@ -1,27 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "create-charcole",
|
|
3
|
-
"version": "2.2.
|
|
4
|
-
"description": "CLI to create production-ready Node.js Express APIs with TypeScript/JavaScript, JWT auth, auto-generated Swagger docs, and repository pattern",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"author": {
|
|
7
|
-
"name": "Sheraz Manzoor",
|
|
8
|
-
"email": "sheraz.dev121@gmail.com"
|
|
9
|
-
},
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"charcole"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "create-charcole",
|
|
3
|
+
"version": "2.2.2",
|
|
4
|
+
"description": "CLI to create production-ready Node.js Express APIs with TypeScript/JavaScript, JWT auth, auto-generated Swagger docs, and repository pattern",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Sheraz Manzoor",
|
|
8
|
+
"email": "sheraz.dev121@gmail.com"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/sheraz4196/charcole.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/sheraz4196/charcole/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://www.charcole.site/",
|
|
18
|
+
"bin": {
|
|
19
|
+
"create-charcole": "bin/index.js"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"express",
|
|
23
|
+
"backend",
|
|
24
|
+
"starter",
|
|
25
|
+
"boilerplate",
|
|
26
|
+
"production",
|
|
27
|
+
"charcole",
|
|
28
|
+
"nodejs starter",
|
|
29
|
+
"express starter",
|
|
30
|
+
"typescript backend",
|
|
31
|
+
"swagger",
|
|
32
|
+
"backend template",
|
|
33
|
+
"api-boilerplate",
|
|
34
|
+
"zod validation"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=16"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"prompts": "^2.4.2"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -30,7 +30,7 @@ const app = express();
|
|
|
30
30
|
|
|
31
31
|
setupSwagger(app, {
|
|
32
32
|
title: "My API",
|
|
33
|
-
version: "1.0.
|
|
33
|
+
version: "1.0.1",
|
|
34
34
|
schemas: {
|
|
35
35
|
createUserSchema, // Auto-converted from Zod!
|
|
36
36
|
loginSchema,
|
|
@@ -107,7 +107,7 @@ Sets up Swagger UI and documentation generation.
|
|
|
107
107
|
| Option | Type | Default | Description |
|
|
108
108
|
| ------------------------ | ------- | ---------------------------------- | ----------------------------------- |
|
|
109
109
|
| `title` | string | "Charcole API" | API title |
|
|
110
|
-
| `version` | string | "1.0.
|
|
110
|
+
| `version` | string | "1.0.1" | API version |
|
|
111
111
|
| `description` | string | "Auto-generated API documentation" | API description |
|
|
112
112
|
| `path` | string | "/api-docs" | Swagger UI path |
|
|
113
113
|
| `servers` | array | `[{url: "http://localhost:3000"}]` | Server URLs |
|
|
@@ -267,7 +267,7 @@ const app: Application = express();
|
|
|
267
267
|
|
|
268
268
|
const options: SwaggerOptions = {
|
|
269
269
|
title: "My API",
|
|
270
|
-
version: "1.0.
|
|
270
|
+
version: "1.0.1",
|
|
271
271
|
schemas: {
|
|
272
272
|
mySchema,
|
|
273
273
|
},
|
|
@@ -1,44 +1,57 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@charcoles/swagger",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Auto-generated Swagger documentation for Charcole APIs",
|
|
5
|
-
"main": "src/index.js",
|
|
6
|
-
"types": "src/index.d.ts",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"exports": {
|
|
9
|
-
".": {
|
|
10
|
-
"types": "./src/index.d.ts",
|
|
11
|
-
"default": "./src/index.js"
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@charcoles/swagger",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Auto-generated Swagger documentation for Charcole APIs",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"types": "src/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"default": "./src/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"author": {
|
|
15
|
+
"name": "Sheraz Manzoor",
|
|
16
|
+
"email": "sheraz.dev121@gmail.com"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/sheraz4196/charcole.git",
|
|
21
|
+
"directory": "packages/swagger"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/sheraz4196/charcole/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://www.charcole.site/guides/swagger/introduction",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "echo \"No tests yet\" && exit 0",
|
|
29
|
+
"prepare": "echo 'Ready for npm link'"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"swagger-ui-express": "^4.6.3",
|
|
33
|
+
"swagger-jsdoc": "^6.2.8",
|
|
34
|
+
"glob": "^10.3.10",
|
|
35
|
+
"zod-to-json-schema": "^3.22.4"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"zod": "^3.0.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"zod": {
|
|
42
|
+
"optional": true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"keywords": [
|
|
46
|
+
"charcole",
|
|
47
|
+
"swagger",
|
|
48
|
+
"openapi",
|
|
49
|
+
"documentation",
|
|
50
|
+
"express",
|
|
51
|
+
"charcole swagger"
|
|
52
|
+
],
|
|
53
|
+
"license": "ISC",
|
|
54
|
+
"publishConfig": {
|
|
55
|
+
"access": "public"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
import { Application } from "express";
|
|
2
|
-
import { ZodType, ZodSchema } from "zod";
|
|
3
|
-
|
|
4
|
-
export interface SwaggerServer {
|
|
5
|
-
url: string;
|
|
6
|
-
description: string;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface SwaggerOptions {
|
|
10
|
-
title?: string;
|
|
11
|
-
version?: string;
|
|
12
|
-
description?: string;
|
|
13
|
-
path?: string;
|
|
14
|
-
servers?: SwaggerServer[];
|
|
15
|
-
// NEW: Auto-register Zod schemas
|
|
16
|
-
schemas?: Record<string, ZodType<any>>;
|
|
17
|
-
// NEW: Include common response templates (default: true)
|
|
18
|
-
includeCommonResponses?: boolean;
|
|
19
|
-
// NEW: Custom response schemas
|
|
20
|
-
customResponses?: Record<string, any>;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface OpenAPISpec {
|
|
24
|
-
openapi: string;
|
|
25
|
-
info: {
|
|
26
|
-
title: string;
|
|
27
|
-
version: string;
|
|
28
|
-
description: string;
|
|
29
|
-
};
|
|
30
|
-
servers: SwaggerServer[];
|
|
31
|
-
components: {
|
|
32
|
-
securitySchemes: {
|
|
33
|
-
bearerAuth: {
|
|
34
|
-
type: string;
|
|
35
|
-
scheme: string;
|
|
36
|
-
bearerFormat: string;
|
|
37
|
-
description: string;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
schemas?: Record<string, any>;
|
|
41
|
-
responses?: Record<string, any>;
|
|
42
|
-
};
|
|
43
|
-
paths?: Record<string, any>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function setupSwagger(
|
|
47
|
-
app: Application,
|
|
48
|
-
options?: SwaggerOptions,
|
|
49
|
-
): OpenAPISpec;
|
|
50
|
-
|
|
51
|
-
// Helper functions
|
|
52
|
-
export interface EndpointParameter {
|
|
53
|
-
in: "path" | "query" | "header";
|
|
54
|
-
name: string;
|
|
55
|
-
required?: boolean;
|
|
56
|
-
type?: string;
|
|
57
|
-
description?: string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface EndpointOptions {
|
|
61
|
-
summary: string;
|
|
62
|
-
description?: string;
|
|
63
|
-
tags?: string[];
|
|
64
|
-
schema?: string;
|
|
65
|
-
responseSchema?: string;
|
|
66
|
-
security?: boolean;
|
|
67
|
-
params?: EndpointParameter[];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export interface SwaggerDocOptions {
|
|
71
|
-
method: string;
|
|
72
|
-
path: string;
|
|
73
|
-
summary: string;
|
|
74
|
-
description?: string;
|
|
75
|
-
tags?: string[];
|
|
76
|
-
requestSchema?: string;
|
|
77
|
-
responseSchemaName?: string;
|
|
78
|
-
security?: boolean;
|
|
79
|
-
parameters?: EndpointParameter[];
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Convert Zod schema to OpenAPI JSON Schema
|
|
84
|
-
*/
|
|
85
|
-
export function convertZodToOpenAPI(
|
|
86
|
-
zodSchema: ZodType<any>,
|
|
87
|
-
name: string,
|
|
88
|
-
): object | null;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Extract body schema from a Zod schema that has a .body property
|
|
92
|
-
*/
|
|
93
|
-
export function extractBodySchema(schema: ZodType<any>): ZodType<any> | null;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Get common response schemas (Success, ValidationError, Unauthorized, etc.)
|
|
97
|
-
*/
|
|
98
|
-
export function getCommonResponses(): Record<string, any>;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Detect security requirements from middleware chain
|
|
102
|
-
*/
|
|
103
|
-
export function detectSecurity(
|
|
104
|
-
middlewares: Function[],
|
|
105
|
-
): Array<{ bearerAuth: [] }>;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Create a Swagger documentation comment block
|
|
109
|
-
*/
|
|
110
|
-
export function createSwaggerDoc(options: SwaggerDocOptions): string;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Register Zod schemas for auto-documentation
|
|
114
|
-
*/
|
|
115
|
-
export function registerSchemas(
|
|
116
|
-
schemas: Record<string, ZodType<any>>,
|
|
117
|
-
): Record<string, any>;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Simplified API for quick endpoint documentation
|
|
121
|
-
*/
|
|
122
|
-
export function endpoint(
|
|
123
|
-
method: string,
|
|
124
|
-
path: string,
|
|
125
|
-
options?: EndpointOptions,
|
|
126
|
-
): Record<string, any>;
|
|
1
|
+
import { Application } from "express";
|
|
2
|
+
import { ZodType, ZodSchema } from "zod";
|
|
3
|
+
|
|
4
|
+
export interface SwaggerServer {
|
|
5
|
+
url: string;
|
|
6
|
+
description: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface SwaggerOptions {
|
|
10
|
+
title?: string;
|
|
11
|
+
version?: string;
|
|
12
|
+
description?: string;
|
|
13
|
+
path?: string;
|
|
14
|
+
servers?: SwaggerServer[];
|
|
15
|
+
// NEW: Auto-register Zod schemas
|
|
16
|
+
schemas?: Record<string, ZodType<any>>;
|
|
17
|
+
// NEW: Include common response templates (default: true)
|
|
18
|
+
includeCommonResponses?: boolean;
|
|
19
|
+
// NEW: Custom response schemas
|
|
20
|
+
customResponses?: Record<string, any>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface OpenAPISpec {
|
|
24
|
+
openapi: string;
|
|
25
|
+
info: {
|
|
26
|
+
title: string;
|
|
27
|
+
version: string;
|
|
28
|
+
description: string;
|
|
29
|
+
};
|
|
30
|
+
servers: SwaggerServer[];
|
|
31
|
+
components: {
|
|
32
|
+
securitySchemes: {
|
|
33
|
+
bearerAuth: {
|
|
34
|
+
type: string;
|
|
35
|
+
scheme: string;
|
|
36
|
+
bearerFormat: string;
|
|
37
|
+
description: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
schemas?: Record<string, any>;
|
|
41
|
+
responses?: Record<string, any>;
|
|
42
|
+
};
|
|
43
|
+
paths?: Record<string, any>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function setupSwagger(
|
|
47
|
+
app: Application,
|
|
48
|
+
options?: SwaggerOptions,
|
|
49
|
+
): OpenAPISpec;
|
|
50
|
+
|
|
51
|
+
// Helper functions
|
|
52
|
+
export interface EndpointParameter {
|
|
53
|
+
in: "path" | "query" | "header";
|
|
54
|
+
name: string;
|
|
55
|
+
required?: boolean;
|
|
56
|
+
type?: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface EndpointOptions {
|
|
61
|
+
summary: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
tags?: string[];
|
|
64
|
+
schema?: string;
|
|
65
|
+
responseSchema?: string;
|
|
66
|
+
security?: boolean;
|
|
67
|
+
params?: EndpointParameter[];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface SwaggerDocOptions {
|
|
71
|
+
method: string;
|
|
72
|
+
path: string;
|
|
73
|
+
summary: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
tags?: string[];
|
|
76
|
+
requestSchema?: string;
|
|
77
|
+
responseSchemaName?: string;
|
|
78
|
+
security?: boolean;
|
|
79
|
+
parameters?: EndpointParameter[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Convert Zod schema to OpenAPI JSON Schema
|
|
84
|
+
*/
|
|
85
|
+
export function convertZodToOpenAPI(
|
|
86
|
+
zodSchema: ZodType<any>,
|
|
87
|
+
name: string,
|
|
88
|
+
): object | null;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Extract body schema from a Zod schema that has a .body property
|
|
92
|
+
*/
|
|
93
|
+
export function extractBodySchema(schema: ZodType<any>): ZodType<any> | null;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Get common response schemas (Success, ValidationError, Unauthorized, etc.)
|
|
97
|
+
*/
|
|
98
|
+
export function getCommonResponses(): Record<string, any>;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Detect security requirements from middleware chain
|
|
102
|
+
*/
|
|
103
|
+
export function detectSecurity(
|
|
104
|
+
middlewares: Function[],
|
|
105
|
+
): Array<{ bearerAuth: [] }>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Create a Swagger documentation comment block
|
|
109
|
+
*/
|
|
110
|
+
export function createSwaggerDoc(options: SwaggerDocOptions): string;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Register Zod schemas for auto-documentation
|
|
114
|
+
*/
|
|
115
|
+
export function registerSchemas(
|
|
116
|
+
schemas: Record<string, ZodType<any>>,
|
|
117
|
+
): Record<string, any>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Simplified API for quick endpoint documentation
|
|
121
|
+
*/
|
|
122
|
+
export function endpoint(
|
|
123
|
+
method: string,
|
|
124
|
+
path: string,
|
|
125
|
+
options?: EndpointOptions,
|
|
126
|
+
): Record<string, any>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export { setupSwagger } from "./setup.js";
|
|
2
|
-
|
|
3
|
-
// Export helper functions for advanced usage
|
|
4
|
-
export {
|
|
5
|
-
convertZodToOpenAPI,
|
|
6
|
-
extractBodySchema,
|
|
7
|
-
getCommonResponses,
|
|
8
|
-
detectSecurity,
|
|
9
|
-
createSwaggerDoc,
|
|
10
|
-
registerSchemas,
|
|
11
|
-
endpoint,
|
|
12
|
-
} from "./helpers.js";
|
|
1
|
+
export { setupSwagger } from "./setup.js";
|
|
2
|
+
|
|
3
|
+
// Export helper functions for advanced usage
|
|
4
|
+
export {
|
|
5
|
+
convertZodToOpenAPI,
|
|
6
|
+
extractBodySchema,
|
|
7
|
+
getCommonResponses,
|
|
8
|
+
detectSecurity,
|
|
9
|
+
createSwaggerDoc,
|
|
10
|
+
registerSchemas,
|
|
11
|
+
endpoint,
|
|
12
|
+
} from "./helpers.js";
|