katax-cli 1.1.4 → 1.2.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.
- package/dist/commands/add-endpoint.d.ts.map +1 -1
- package/dist/commands/add-endpoint.js +121 -97
- package/dist/commands/add-endpoint.js.map +1 -1
- package/dist/commands/deploy.d.ts +3 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +287 -153
- package/dist/commands/deploy.js.map +1 -1
- package/dist/commands/generate-crud.d.ts.map +1 -1
- package/dist/commands/generate-crud.js +60 -56
- package/dist/commands/generate-crud.js.map +1 -1
- package/dist/commands/generate-docs.d.ts +8 -0
- package/dist/commands/generate-docs.d.ts.map +1 -0
- package/dist/commands/generate-docs.js +159 -0
- package/dist/commands/generate-docs.js.map +1 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +281 -17
- package/dist/commands/init.js.map +1 -1
- package/dist/index.js +83 -69
- package/dist/index.js.map +1 -1
- package/dist/services/openapi-generator.service.d.ts +37 -0
- package/dist/services/openapi-generator.service.d.ts.map +1 -0
- package/dist/services/openapi-generator.service.js +333 -0
- package/dist/services/openapi-generator.service.js.map +1 -0
- package/dist/templates/generators/swagger-template.d.ts +3 -0
- package/dist/templates/generators/swagger-template.d.ts.map +1 -0
- package/dist/templates/generators/swagger-template.js +117 -0
- package/dist/templates/generators/swagger-template.js.map +1 -0
- package/dist/types/index.d.ts +19 -10
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
export function generateSwaggerSetup() {
|
|
2
|
+
return `import swaggerUi from 'swagger-ui-express';
|
|
3
|
+
import { Express } from 'express';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Setup Swagger UI documentation
|
|
9
|
+
*/
|
|
10
|
+
export function setupSwagger(app: Express): void {
|
|
11
|
+
try {
|
|
12
|
+
const swaggerPath = path.join(__dirname, '../openapi.json');
|
|
13
|
+
|
|
14
|
+
if (!fs.existsSync(swaggerPath)) {
|
|
15
|
+
console.warn('⚠️ OpenAPI spec not found. Run: katax generate docs');
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const swaggerDocument = JSON.parse(fs.readFileSync(swaggerPath, 'utf-8'));
|
|
20
|
+
|
|
21
|
+
// Swagger UI options
|
|
22
|
+
const options = {
|
|
23
|
+
explorer: true,
|
|
24
|
+
customCss: '.swagger-ui .topbar { display: none }',
|
|
25
|
+
customSiteTitle: 'API Documentation',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Setup Swagger UI
|
|
29
|
+
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options));
|
|
30
|
+
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options));
|
|
31
|
+
|
|
32
|
+
// JSON endpoint
|
|
33
|
+
app.get('/openapi.json', (req, res) => {
|
|
34
|
+
res.setHeader('Content-Type', 'application/json');
|
|
35
|
+
res.send(swaggerDocument);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
console.log('📖 API Documentation available at: http://localhost:3000/docs');
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.error('Failed to setup Swagger:', error);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
export function generateSwaggerReadme() {
|
|
46
|
+
return `# API Documentation
|
|
47
|
+
|
|
48
|
+
## Swagger UI
|
|
49
|
+
|
|
50
|
+
Interactive API documentation is available at:
|
|
51
|
+
|
|
52
|
+
- **Development**: http://localhost:3000/docs
|
|
53
|
+
- **OpenAPI Spec**: http://localhost:3000/openapi.json
|
|
54
|
+
|
|
55
|
+
## Features
|
|
56
|
+
|
|
57
|
+
✅ Interactive API testing
|
|
58
|
+
✅ Auto-generated from code
|
|
59
|
+
✅ Request/Response examples
|
|
60
|
+
✅ Schema validation docs
|
|
61
|
+
✅ Export to Postman
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
### View Documentation
|
|
66
|
+
|
|
67
|
+
\`\`\`bash
|
|
68
|
+
# Start your API
|
|
69
|
+
npm run dev
|
|
70
|
+
|
|
71
|
+
# Open browser
|
|
72
|
+
open http://localhost:3000/docs
|
|
73
|
+
\`\`\`
|
|
74
|
+
|
|
75
|
+
### Regenerate Documentation
|
|
76
|
+
|
|
77
|
+
\`\`\`bash
|
|
78
|
+
# Auto-regenerates when you generate endpoints
|
|
79
|
+
katax generate crud users
|
|
80
|
+
katax add endpoint products
|
|
81
|
+
|
|
82
|
+
# Or manually regenerate
|
|
83
|
+
katax generate docs
|
|
84
|
+
katax generate docs --force
|
|
85
|
+
\`\`\`
|
|
86
|
+
|
|
87
|
+
### Export to Postman
|
|
88
|
+
|
|
89
|
+
1. Open http://localhost:3000/openapi.json
|
|
90
|
+
2. Copy the JSON
|
|
91
|
+
3. In Postman: File → Import → Raw Text → Paste
|
|
92
|
+
4. ✅ All endpoints imported!
|
|
93
|
+
|
|
94
|
+
## Customization
|
|
95
|
+
|
|
96
|
+
Edit \`src/config/swagger.config.ts\` to customize:
|
|
97
|
+
- API title and description
|
|
98
|
+
- Server URLs
|
|
99
|
+
- Authentication schemes
|
|
100
|
+
- Contact information
|
|
101
|
+
|
|
102
|
+
## Maintaining Docs
|
|
103
|
+
|
|
104
|
+
Documentation is automatically updated when you:
|
|
105
|
+
- Generate CRUD resources
|
|
106
|
+
- Add new endpoints
|
|
107
|
+
- Update validators
|
|
108
|
+
|
|
109
|
+
The documentation reads directly from your:
|
|
110
|
+
- Route files (\`*.routes.ts\`)
|
|
111
|
+
- Validator files (\`*.validator.ts\`)
|
|
112
|
+
- Katax-core schemas
|
|
113
|
+
|
|
114
|
+
**No manual updates needed!** 🎉
|
|
115
|
+
`;
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=swagger-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swagger-template.js","sourceRoot":"","sources":["../../../src/templates/generators/swagger-template.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,oBAAoB;IAClC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyCR,CAAC;AACF,CAAC;AAED,MAAM,UAAU,qBAAqB;IACnC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqER,CAAC;AACF,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
export interface ProjectConfig {
|
|
2
2
|
name: string;
|
|
3
3
|
description?: string;
|
|
4
|
-
type:
|
|
4
|
+
type: "rest-api" | "graphql";
|
|
5
5
|
typescript: boolean;
|
|
6
|
-
database?:
|
|
7
|
-
authentication?:
|
|
8
|
-
validation:
|
|
9
|
-
|
|
6
|
+
database?: "postgresql" | "mysql" | "mongodb" | "none";
|
|
7
|
+
authentication?: "jwt" | "none";
|
|
8
|
+
validation: "katax-core" | "none";
|
|
9
|
+
swagger?: boolean;
|
|
10
|
+
orm?: "none" | "prisma" | "typeorm";
|
|
10
11
|
port: number;
|
|
12
|
+
useKataxServiceManager?: boolean;
|
|
13
|
+
useRedis?: boolean;
|
|
14
|
+
redisConfig?: {
|
|
15
|
+
host?: string;
|
|
16
|
+
port?: string;
|
|
17
|
+
password?: string;
|
|
18
|
+
db?: string;
|
|
19
|
+
};
|
|
11
20
|
dbConfig?: {
|
|
12
21
|
host?: string;
|
|
13
22
|
port?: string;
|
|
@@ -19,26 +28,26 @@ export interface ProjectConfig {
|
|
|
19
28
|
}
|
|
20
29
|
export interface EndpointConfig {
|
|
21
30
|
name: string;
|
|
22
|
-
method:
|
|
31
|
+
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
23
32
|
path: string;
|
|
24
33
|
addValidation: boolean;
|
|
25
34
|
fields?: FieldConfig[];
|
|
26
35
|
addAsyncValidators: boolean;
|
|
27
|
-
dbOperations?: (
|
|
36
|
+
dbOperations?: ("create" | "read" | "update" | "delete")[];
|
|
28
37
|
}
|
|
29
38
|
export interface FieldConfig {
|
|
30
39
|
name: string;
|
|
31
|
-
type:
|
|
40
|
+
type: "string" | "number" | "boolean" | "date" | "email" | "array" | "object";
|
|
32
41
|
required: boolean;
|
|
33
42
|
rules?: ValidationRule[];
|
|
34
43
|
asyncValidator?: {
|
|
35
|
-
type:
|
|
44
|
+
type: "unique" | "exists" | "custom";
|
|
36
45
|
table?: string;
|
|
37
46
|
column?: string;
|
|
38
47
|
};
|
|
39
48
|
}
|
|
40
49
|
export interface ValidationRule {
|
|
41
|
-
type:
|
|
50
|
+
type: "minLength" | "maxLength" | "min" | "max" | "email" | "regex" | "oneOf" | "custom";
|
|
42
51
|
value?: any;
|
|
43
52
|
message?: string;
|
|
44
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,UAAU,GAAG,SAAS,CAAC;IAC7B,UAAU,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,YAAY,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;IACvD,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IAChC,UAAU,EAAE,YAAY,GAAG,MAAM,CAAC;IAClC,GAAG,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MA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