@gxp-dev/tools 2.0.62 → 2.0.64
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/README.md +32 -31
- package/bin/gx-devtools.js +74 -54
- package/bin/lib/cli.js +23 -21
- package/bin/lib/commands/add-dependency.js +366 -325
- package/bin/lib/commands/assets.js +137 -139
- package/bin/lib/commands/build.js +169 -174
- package/bin/lib/commands/datastore.js +181 -183
- package/bin/lib/commands/dev.js +127 -131
- package/bin/lib/commands/extensions.js +147 -149
- package/bin/lib/commands/extract-config.js +73 -67
- package/bin/lib/commands/index.js +12 -12
- package/bin/lib/commands/init.js +342 -240
- package/bin/lib/commands/publish.js +69 -75
- package/bin/lib/commands/socket.js +69 -69
- package/bin/lib/commands/ssl.js +14 -14
- package/bin/lib/constants.js +10 -24
- package/bin/lib/tui/App.tsx +761 -705
- package/bin/lib/tui/components/AIPanel.tsx +191 -171
- package/bin/lib/tui/components/CommandInput.tsx +394 -343
- package/bin/lib/tui/components/GeminiPanel.tsx +175 -151
- package/bin/lib/tui/components/Header.tsx +23 -21
- package/bin/lib/tui/components/LogPanel.tsx +244 -220
- package/bin/lib/tui/components/TabBar.tsx +50 -48
- package/bin/lib/tui/components/WelcomeScreen.tsx +126 -71
- package/bin/lib/tui/index.tsx +37 -39
- package/bin/lib/tui/services/AIService.ts +518 -462
- package/bin/lib/tui/services/ExtensionService.ts +140 -129
- package/bin/lib/tui/services/GeminiService.ts +367 -337
- package/bin/lib/tui/services/ServiceManager.ts +344 -322
- package/bin/lib/tui/services/SocketService.ts +168 -168
- package/bin/lib/tui/services/ViteService.ts +88 -88
- package/bin/lib/tui/services/index.ts +47 -22
- package/bin/lib/utils/ai-scaffold.js +291 -280
- package/bin/lib/utils/extract-config.js +157 -140
- package/bin/lib/utils/files.js +82 -86
- package/bin/lib/utils/index.js +7 -7
- package/bin/lib/utils/paths.js +34 -34
- package/bin/lib/utils/prompts.js +194 -169
- package/bin/lib/utils/ssl.js +79 -81
- package/browser-extensions/README.md +0 -1
- package/browser-extensions/chrome/background.js +244 -237
- package/browser-extensions/chrome/content.js +32 -29
- package/browser-extensions/chrome/devtools.html +7 -7
- package/browser-extensions/chrome/devtools.js +19 -19
- package/browser-extensions/chrome/inspector.js +802 -767
- package/browser-extensions/chrome/manifest.json +71 -63
- package/browser-extensions/chrome/panel.html +674 -636
- package/browser-extensions/chrome/panel.js +722 -712
- package/browser-extensions/chrome/popup.html +586 -543
- package/browser-extensions/chrome/popup.js +282 -244
- package/browser-extensions/chrome/rules.json +1 -1
- package/browser-extensions/chrome/test-chrome.html +216 -136
- package/browser-extensions/chrome/test-mixed-content.html +284 -189
- package/browser-extensions/chrome/test-uri-pattern.html +221 -198
- package/browser-extensions/firefox/README.md +9 -6
- package/browser-extensions/firefox/background.js +221 -218
- package/browser-extensions/firefox/content.js +55 -52
- package/browser-extensions/firefox/debug-errors.html +386 -228
- package/browser-extensions/firefox/debug-https.html +153 -105
- package/browser-extensions/firefox/devtools.html +7 -7
- package/browser-extensions/firefox/devtools.js +23 -20
- package/browser-extensions/firefox/inspector.js +802 -767
- package/browser-extensions/firefox/manifest.json +68 -68
- package/browser-extensions/firefox/panel.html +674 -636
- package/browser-extensions/firefox/panel.js +722 -712
- package/browser-extensions/firefox/popup.html +572 -535
- package/browser-extensions/firefox/popup.js +281 -236
- package/browser-extensions/firefox/test-gramercy.html +170 -125
- package/browser-extensions/firefox/test-imports.html +59 -55
- package/browser-extensions/firefox/test-masking.html +231 -140
- package/browser-extensions/firefox/test-uri-pattern.html +221 -198
- package/dist/tui/App.d.ts +1 -1
- package/dist/tui/App.d.ts.map +1 -1
- package/dist/tui/App.js +154 -150
- package/dist/tui/App.js.map +1 -1
- package/dist/tui/components/AIPanel.d.ts.map +1 -1
- package/dist/tui/components/AIPanel.js +42 -35
- package/dist/tui/components/AIPanel.js.map +1 -1
- package/dist/tui/components/CommandInput.d.ts +1 -1
- package/dist/tui/components/CommandInput.d.ts.map +1 -1
- package/dist/tui/components/CommandInput.js +92 -62
- package/dist/tui/components/CommandInput.js.map +1 -1
- package/dist/tui/components/GeminiPanel.d.ts.map +1 -1
- package/dist/tui/components/GeminiPanel.js +37 -30
- package/dist/tui/components/GeminiPanel.js.map +1 -1
- package/dist/tui/components/Header.d.ts.map +1 -1
- package/dist/tui/components/Header.js +1 -1
- package/dist/tui/components/Header.js.map +1 -1
- package/dist/tui/components/LogPanel.d.ts +1 -1
- package/dist/tui/components/LogPanel.d.ts.map +1 -1
- package/dist/tui/components/LogPanel.js +26 -24
- package/dist/tui/components/LogPanel.js.map +1 -1
- package/dist/tui/components/TabBar.d.ts +2 -2
- package/dist/tui/components/TabBar.d.ts.map +1 -1
- package/dist/tui/components/TabBar.js +11 -11
- package/dist/tui/components/TabBar.js.map +1 -1
- package/dist/tui/components/WelcomeScreen.d.ts.map +1 -1
- package/dist/tui/components/WelcomeScreen.js +6 -6
- package/dist/tui/components/WelcomeScreen.js.map +1 -1
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/index.js +8 -8
- package/dist/tui/index.js.map +1 -1
- package/dist/tui/services/AIService.d.ts +2 -2
- package/dist/tui/services/AIService.d.ts.map +1 -1
- package/dist/tui/services/AIService.js +165 -125
- package/dist/tui/services/AIService.js.map +1 -1
- package/dist/tui/services/ExtensionService.d.ts +1 -1
- package/dist/tui/services/ExtensionService.d.ts.map +1 -1
- package/dist/tui/services/ExtensionService.js +33 -26
- package/dist/tui/services/ExtensionService.js.map +1 -1
- package/dist/tui/services/GeminiService.d.ts +1 -1
- package/dist/tui/services/GeminiService.d.ts.map +1 -1
- package/dist/tui/services/GeminiService.js +87 -76
- package/dist/tui/services/GeminiService.js.map +1 -1
- package/dist/tui/services/ServiceManager.d.ts +3 -3
- package/dist/tui/services/ServiceManager.d.ts.map +1 -1
- package/dist/tui/services/ServiceManager.js +72 -58
- package/dist/tui/services/ServiceManager.js.map +1 -1
- package/dist/tui/services/SocketService.d.ts.map +1 -1
- package/dist/tui/services/SocketService.js +32 -32
- package/dist/tui/services/SocketService.js.map +1 -1
- package/dist/tui/services/ViteService.d.ts.map +1 -1
- package/dist/tui/services/ViteService.js +26 -28
- package/dist/tui/services/ViteService.js.map +1 -1
- package/dist/tui/services/index.d.ts +6 -6
- package/dist/tui/services/index.d.ts.map +1 -1
- package/dist/tui/services/index.js +6 -6
- package/dist/tui/services/index.js.map +1 -1
- package/mcp/gxp-api-server.js +83 -81
- package/package.json +109 -93
- package/runtime/PortalContainer.vue +258 -234
- package/runtime/dev-tools/DevToolsModal.vue +153 -155
- package/runtime/dev-tools/LayoutSwitcher.vue +144 -140
- package/runtime/dev-tools/MockDataEditor.vue +456 -433
- package/runtime/dev-tools/SocketSimulator.vue +379 -371
- package/runtime/dev-tools/StoreInspector.vue +517 -455
- package/runtime/dev-tools/index.js +5 -5
- package/runtime/fallback-layouts/PrivateLayout.vue +2 -2
- package/runtime/fallback-layouts/PublicLayout.vue +2 -2
- package/runtime/fallback-layouts/SystemLayout.vue +2 -2
- package/runtime/gxpStringsPlugin.js +159 -134
- package/runtime/index.html +17 -19
- package/runtime/main.js +24 -22
- package/runtime/mock-api/auth-middleware.js +15 -15
- package/runtime/mock-api/image-generator.js +46 -46
- package/runtime/mock-api/index.js +55 -55
- package/runtime/mock-api/response-generator.js +116 -105
- package/runtime/mock-api/route-generator.js +107 -84
- package/runtime/mock-api/socket-triggers.js +94 -93
- package/runtime/mock-api/spec-loader.js +79 -80
- package/runtime/package.json +3 -0
- package/runtime/server.js +68 -68
- package/runtime/stores/gxpPortalConfigStore.js +204 -186
- package/runtime/stores/index.js +2 -2
- package/runtime/vite-inspector-plugin.js +858 -707
- package/runtime/vite-source-tracker-plugin.js +132 -113
- package/runtime/vite.config.js +207 -132
- package/scripts/launch-chrome.js +41 -41
- package/scripts/pack-chrome.js +38 -39
- package/socket-events/AiSessionMessageCreated.json +17 -17
- package/socket-events/SocialStreamPostCreated.json +23 -23
- package/socket-events/SocialStreamPostVariantCompleted.json +22 -22
- package/template/.claude/agents/gxp-developer.md +100 -99
- package/template/.claude/settings.json +7 -7
- package/template/AGENTS.md +30 -23
- package/template/GEMINI.md +20 -20
- package/template/README.md +70 -53
- package/template/app-manifest.json +2 -4
- package/template/configuration.json +10 -10
- package/template/default-styling.css +1 -1
- package/template/index.html +18 -20
- package/template/main.js +24 -22
- package/template/src/DemoPage.vue +415 -362
- package/template/src/Plugin.vue +76 -85
- package/template/src/stores/index.js +3 -3
- package/template/src/stores/test-data.json +164 -172
- package/template/theme-layouts/AdditionalStyling.css +50 -50
- package/template/theme-layouts/PrivateLayout.vue +8 -12
- package/template/theme-layouts/PublicLayout.vue +8 -12
- package/template/theme-layouts/SystemLayout.vue +8 -12
- package/template/vite.extend.js +45 -0
- package/template/vite.config.js +0 -409
|
@@ -5,12 +5,23 @@
|
|
|
5
5
|
* Supports x-mock extensions for delays, error simulation, and scenarios.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
const express = require("express")
|
|
9
|
-
const {
|
|
10
|
-
|
|
8
|
+
const express = require("express")
|
|
9
|
+
const {
|
|
10
|
+
generateResponse,
|
|
11
|
+
generateErrorResponse,
|
|
12
|
+
} = require("./response-generator")
|
|
13
|
+
const { createAuthMiddleware } = require("./auth-middleware")
|
|
11
14
|
|
|
12
15
|
// HTTP methods supported by Express
|
|
13
|
-
const HTTP_METHODS = [
|
|
16
|
+
const HTTP_METHODS = [
|
|
17
|
+
"get",
|
|
18
|
+
"post",
|
|
19
|
+
"put",
|
|
20
|
+
"patch",
|
|
21
|
+
"delete",
|
|
22
|
+
"options",
|
|
23
|
+
"head",
|
|
24
|
+
]
|
|
14
25
|
|
|
15
26
|
/**
|
|
16
27
|
* Convert OpenAPI path to Express path
|
|
@@ -19,7 +30,7 @@ const HTTP_METHODS = ["get", "post", "put", "patch", "delete", "options", "head"
|
|
|
19
30
|
* @returns {string} Express path with :param syntax
|
|
20
31
|
*/
|
|
21
32
|
function convertPath(openApiPath) {
|
|
22
|
-
return openApiPath.replace(/\{([^}]+)\}/g, ":$1")
|
|
33
|
+
return openApiPath.replace(/\{([^}]+)\}/g, ":$1")
|
|
23
34
|
}
|
|
24
35
|
|
|
25
36
|
/**
|
|
@@ -30,26 +41,26 @@ function convertPath(openApiPath) {
|
|
|
30
41
|
*/
|
|
31
42
|
function getResponseSchema(operation, status) {
|
|
32
43
|
if (!operation.responses) {
|
|
33
|
-
return null
|
|
44
|
+
return null
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
// Try exact status code
|
|
37
48
|
if (operation.responses[status]) {
|
|
38
|
-
return operation.responses[status]
|
|
49
|
+
return operation.responses[status]
|
|
39
50
|
}
|
|
40
51
|
|
|
41
52
|
// Try wildcard (2XX, 4XX, etc.)
|
|
42
|
-
const wildcard = `${Math.floor(status / 100)}XX
|
|
53
|
+
const wildcard = `${Math.floor(status / 100)}XX`
|
|
43
54
|
if (operation.responses[wildcard]) {
|
|
44
|
-
return operation.responses[wildcard]
|
|
55
|
+
return operation.responses[wildcard]
|
|
45
56
|
}
|
|
46
57
|
|
|
47
58
|
// Try default
|
|
48
59
|
if (operation.responses.default) {
|
|
49
|
-
return operation.responses.default
|
|
60
|
+
return operation.responses.default
|
|
50
61
|
}
|
|
51
62
|
|
|
52
|
-
return null
|
|
63
|
+
return null
|
|
53
64
|
}
|
|
54
65
|
|
|
55
66
|
/**
|
|
@@ -59,19 +70,19 @@ function getResponseSchema(operation, status) {
|
|
|
59
70
|
* @returns {number} Status code
|
|
60
71
|
*/
|
|
61
72
|
function getSuccessStatus(method, operation) {
|
|
62
|
-
const responses = operation.responses || {}
|
|
73
|
+
const responses = operation.responses || {}
|
|
63
74
|
|
|
64
75
|
// Check for explicit success codes
|
|
65
76
|
for (const code of ["200", "201", "202", "204"]) {
|
|
66
77
|
if (responses[code]) {
|
|
67
|
-
return parseInt(code)
|
|
78
|
+
return parseInt(code)
|
|
68
79
|
}
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
// Default by method
|
|
72
|
-
if (method === "post") return 201
|
|
73
|
-
if (method === "delete") return 204
|
|
74
|
-
return 200
|
|
83
|
+
if (method === "post") return 201
|
|
84
|
+
if (method === "delete") return 204
|
|
85
|
+
return 200
|
|
75
86
|
}
|
|
76
87
|
|
|
77
88
|
/**
|
|
@@ -80,13 +91,13 @@ function getSuccessStatus(method, operation) {
|
|
|
80
91
|
* @returns {Promise} Resolves after delay
|
|
81
92
|
*/
|
|
82
93
|
function applyDelay(mockConfig) {
|
|
83
|
-
const delay = mockConfig.delay || parseInt(process.env.MOCK_API_DELAY) || 0
|
|
94
|
+
const delay = mockConfig.delay || parseInt(process.env.MOCK_API_DELAY) || 0
|
|
84
95
|
|
|
85
96
|
if (delay > 0) {
|
|
86
|
-
return new Promise((resolve) => setTimeout(resolve, delay))
|
|
97
|
+
return new Promise((resolve) => setTimeout(resolve, delay))
|
|
87
98
|
}
|
|
88
99
|
|
|
89
|
-
return Promise.resolve()
|
|
100
|
+
return Promise.resolve()
|
|
90
101
|
}
|
|
91
102
|
|
|
92
103
|
/**
|
|
@@ -95,12 +106,12 @@ function applyDelay(mockConfig) {
|
|
|
95
106
|
* @returns {boolean} True if should error
|
|
96
107
|
*/
|
|
97
108
|
function shouldSimulateError(mockConfig) {
|
|
98
|
-
const errorRate = mockConfig.errorRate || 0
|
|
109
|
+
const errorRate = mockConfig.errorRate || 0
|
|
99
110
|
|
|
100
|
-
if (errorRate <= 0) return false
|
|
101
|
-
if (errorRate >= 1) return true
|
|
111
|
+
if (errorRate <= 0) return false
|
|
112
|
+
if (errorRate >= 1) return true
|
|
102
113
|
|
|
103
|
-
return Math.random() < errorRate
|
|
114
|
+
return Math.random() < errorRate
|
|
104
115
|
}
|
|
105
116
|
|
|
106
117
|
/**
|
|
@@ -110,33 +121,33 @@ function shouldSimulateError(mockConfig) {
|
|
|
110
121
|
*/
|
|
111
122
|
function selectScenario(scenarios) {
|
|
112
123
|
if (!scenarios || typeof scenarios !== "object") {
|
|
113
|
-
return null
|
|
124
|
+
return null
|
|
114
125
|
}
|
|
115
126
|
|
|
116
|
-
const entries = Object.entries(scenarios)
|
|
117
|
-
if (entries.length === 0) return null
|
|
127
|
+
const entries = Object.entries(scenarios)
|
|
128
|
+
if (entries.length === 0) return null
|
|
118
129
|
|
|
119
130
|
// Calculate total weight
|
|
120
131
|
const totalWeight = entries.reduce(
|
|
121
132
|
(sum, [, config]) => sum + (config.weight || 1),
|
|
122
|
-
0
|
|
123
|
-
)
|
|
133
|
+
0,
|
|
134
|
+
)
|
|
124
135
|
|
|
125
136
|
// Random selection
|
|
126
|
-
let random = Math.random() * totalWeight
|
|
137
|
+
let random = Math.random() * totalWeight
|
|
127
138
|
|
|
128
139
|
for (const [name, config] of entries) {
|
|
129
|
-
const weight = config.weight || 1
|
|
130
|
-
random -= weight
|
|
140
|
+
const weight = config.weight || 1
|
|
141
|
+
random -= weight
|
|
131
142
|
|
|
132
143
|
if (random <= 0) {
|
|
133
|
-
return { name, ...config }
|
|
144
|
+
return { name, ...config }
|
|
134
145
|
}
|
|
135
146
|
}
|
|
136
147
|
|
|
137
148
|
// Fallback to first scenario
|
|
138
|
-
const [name, config] = entries[0]
|
|
139
|
-
return { name, ...config }
|
|
149
|
+
const [name, config] = entries[0]
|
|
150
|
+
return { name, ...config }
|
|
140
151
|
}
|
|
141
152
|
|
|
142
153
|
/**
|
|
@@ -149,69 +160,72 @@ function selectScenario(scenarios) {
|
|
|
149
160
|
* @returns {function} Express route handler
|
|
150
161
|
*/
|
|
151
162
|
function buildRouteHandler(method, path, operation, spec, options = {}) {
|
|
152
|
-
const { io, socketTriggers } = options
|
|
163
|
+
const { io, socketTriggers } = options
|
|
153
164
|
|
|
154
165
|
return async (req, res) => {
|
|
155
|
-
const mockConfig = operation["x-mock"] || {}
|
|
156
|
-
const operationId =
|
|
166
|
+
const mockConfig = operation["x-mock"] || {}
|
|
167
|
+
const operationId =
|
|
168
|
+
operation.operationId || `${method.toUpperCase()} ${path}`
|
|
157
169
|
|
|
158
|
-
console.log(`🎭 Mock API: ${operationId}`)
|
|
170
|
+
console.log(`🎭 Mock API: ${operationId}`)
|
|
159
171
|
|
|
160
172
|
try {
|
|
161
173
|
// Apply delay
|
|
162
|
-
await applyDelay(mockConfig)
|
|
174
|
+
await applyDelay(mockConfig)
|
|
163
175
|
|
|
164
176
|
// Check for scenario mode
|
|
165
|
-
const scenario = selectScenario(mockConfig.scenarios)
|
|
177
|
+
const scenario = selectScenario(mockConfig.scenarios)
|
|
166
178
|
|
|
167
179
|
// Determine if we should simulate an error
|
|
168
180
|
if (shouldSimulateError(mockConfig)) {
|
|
169
|
-
const errorSchema = getResponseSchema(operation, 500)
|
|
181
|
+
const errorSchema = getResponseSchema(operation, 500)
|
|
170
182
|
const errorBody = errorSchema
|
|
171
183
|
? generateResponse(errorSchema, spec)
|
|
172
|
-
: generateErrorResponse(500, "Simulated server error")
|
|
184
|
+
: generateErrorResponse(500, "Simulated server error")
|
|
173
185
|
|
|
174
|
-
console.log(
|
|
175
|
-
|
|
186
|
+
console.log(
|
|
187
|
+
` ⚠️ Simulated error (errorRate: ${mockConfig.errorRate})`,
|
|
188
|
+
)
|
|
189
|
+
return res.status(500).json(errorBody)
|
|
176
190
|
}
|
|
177
191
|
|
|
178
192
|
// Use scenario status if defined
|
|
179
|
-
const status = scenario?.status || getSuccessStatus(method, operation)
|
|
193
|
+
const status = scenario?.status || getSuccessStatus(method, operation)
|
|
180
194
|
|
|
181
195
|
// Get response schema for this status
|
|
182
|
-
const responseSchema = getResponseSchema(operation, status)
|
|
196
|
+
const responseSchema = getResponseSchema(operation, status)
|
|
183
197
|
|
|
184
198
|
// Generate response body
|
|
185
|
-
let body
|
|
199
|
+
let body
|
|
186
200
|
if (status === 204) {
|
|
187
201
|
// No content
|
|
188
|
-
body = undefined
|
|
202
|
+
body = undefined
|
|
189
203
|
} else if (scenario?.response) {
|
|
190
204
|
// Use scenario-defined response
|
|
191
|
-
body = scenario.response
|
|
205
|
+
body = scenario.response
|
|
192
206
|
} else if (responseSchema) {
|
|
193
|
-
body = generateResponse(responseSchema, spec)
|
|
207
|
+
body = generateResponse(responseSchema, spec)
|
|
194
208
|
} else {
|
|
195
|
-
body = { success: true }
|
|
209
|
+
body = { success: true }
|
|
196
210
|
}
|
|
197
211
|
|
|
198
212
|
// Log response info
|
|
199
213
|
if (scenario) {
|
|
200
|
-
console.log(` 📋 Scenario: ${scenario.name}`)
|
|
214
|
+
console.log(` 📋 Scenario: ${scenario.name}`)
|
|
201
215
|
}
|
|
202
|
-
console.log(` ✅ Status: ${status}`)
|
|
216
|
+
console.log(` ✅ Status: ${status}`)
|
|
203
217
|
|
|
204
218
|
// Send response
|
|
205
219
|
if (status === 204) {
|
|
206
|
-
res.status(204).end()
|
|
220
|
+
res.status(204).end()
|
|
207
221
|
} else {
|
|
208
|
-
res.status(status).json(body)
|
|
222
|
+
res.status(status).json(body)
|
|
209
223
|
}
|
|
210
224
|
|
|
211
225
|
// Trigger socket events if configured
|
|
212
226
|
if (io && socketTriggers) {
|
|
213
|
-
const { triggerSocketEvents } = require("./socket-triggers")
|
|
214
|
-
const operationKey = `${method.toUpperCase()} ${path}
|
|
227
|
+
const { triggerSocketEvents } = require("./socket-triggers")
|
|
228
|
+
const operationKey = `${method.toUpperCase()} ${path}`
|
|
215
229
|
|
|
216
230
|
triggerSocketEvents(io, socketTriggers, operationKey, {
|
|
217
231
|
request: {
|
|
@@ -225,13 +239,13 @@ function buildRouteHandler(method, path, operation, spec, options = {}) {
|
|
|
225
239
|
status,
|
|
226
240
|
body,
|
|
227
241
|
},
|
|
228
|
-
})
|
|
242
|
+
})
|
|
229
243
|
}
|
|
230
244
|
} catch (error) {
|
|
231
|
-
console.error(` ❌ Error: ${error.message}`)
|
|
232
|
-
res.status(500).json(generateErrorResponse(500, error.message))
|
|
245
|
+
console.error(` ❌ Error: ${error.message}`)
|
|
246
|
+
res.status(500).json(generateErrorResponse(500, error.message))
|
|
233
247
|
}
|
|
234
|
-
}
|
|
248
|
+
}
|
|
235
249
|
}
|
|
236
250
|
|
|
237
251
|
/**
|
|
@@ -241,43 +255,52 @@ function buildRouteHandler(method, path, operation, spec, options = {}) {
|
|
|
241
255
|
* @returns {express.Router} Express router with mock routes
|
|
242
256
|
*/
|
|
243
257
|
function generateRoutes(openApiSpec, options = {}) {
|
|
244
|
-
const router = express.Router()
|
|
258
|
+
const router = express.Router()
|
|
245
259
|
|
|
246
260
|
if (!openApiSpec || !openApiSpec.paths) {
|
|
247
|
-
console.warn("⚠️ No paths found in OpenAPI spec")
|
|
248
|
-
return router
|
|
261
|
+
console.warn("⚠️ No paths found in OpenAPI spec")
|
|
262
|
+
return router
|
|
249
263
|
}
|
|
250
264
|
|
|
251
|
-
let routeCount = 0
|
|
265
|
+
let routeCount = 0
|
|
252
266
|
|
|
253
267
|
// Iterate over all paths
|
|
254
268
|
for (const [path, pathItem] of Object.entries(openApiSpec.paths)) {
|
|
255
|
-
const expressPath = convertPath(path)
|
|
269
|
+
const expressPath = convertPath(path)
|
|
256
270
|
|
|
257
271
|
// Iterate over HTTP methods
|
|
258
272
|
for (const method of HTTP_METHODS) {
|
|
259
|
-
const operation = pathItem[method]
|
|
273
|
+
const operation = pathItem[method]
|
|
260
274
|
|
|
261
|
-
if (!operation) continue
|
|
275
|
+
if (!operation) continue
|
|
262
276
|
|
|
263
277
|
// Create auth middleware for this operation
|
|
264
|
-
const authMiddleware = createAuthMiddleware(operation)
|
|
278
|
+
const authMiddleware = createAuthMiddleware(operation)
|
|
265
279
|
|
|
266
280
|
// Create route handler
|
|
267
|
-
const handler = buildRouteHandler(
|
|
281
|
+
const handler = buildRouteHandler(
|
|
282
|
+
method,
|
|
283
|
+
path,
|
|
284
|
+
operation,
|
|
285
|
+
openApiSpec,
|
|
286
|
+
options,
|
|
287
|
+
)
|
|
268
288
|
|
|
269
289
|
// Register route
|
|
270
|
-
router[method](expressPath, authMiddleware, handler)
|
|
271
|
-
routeCount
|
|
272
|
-
|
|
273
|
-
const operationId =
|
|
274
|
-
|
|
290
|
+
router[method](expressPath, authMiddleware, handler)
|
|
291
|
+
routeCount++
|
|
292
|
+
|
|
293
|
+
const operationId =
|
|
294
|
+
operation.operationId || `${method.toUpperCase()} ${path}`
|
|
295
|
+
console.log(
|
|
296
|
+
` 📍 ${method.toUpperCase()} ${expressPath} (${operationId})`,
|
|
297
|
+
)
|
|
275
298
|
}
|
|
276
299
|
}
|
|
277
300
|
|
|
278
|
-
console.log(`✅ Generated ${routeCount} mock routes`)
|
|
301
|
+
console.log(`✅ Generated ${routeCount} mock routes`)
|
|
279
302
|
|
|
280
|
-
return router
|
|
303
|
+
return router
|
|
281
304
|
}
|
|
282
305
|
|
|
283
306
|
/**
|
|
@@ -287,30 +310,30 @@ function generateRoutes(openApiSpec, options = {}) {
|
|
|
287
310
|
*/
|
|
288
311
|
function getRouteStats(openApiSpec) {
|
|
289
312
|
if (!openApiSpec || !openApiSpec.paths) {
|
|
290
|
-
return { total: 0, byMethod: {} }
|
|
313
|
+
return { total: 0, byMethod: {} }
|
|
291
314
|
}
|
|
292
315
|
|
|
293
316
|
const stats = {
|
|
294
317
|
total: 0,
|
|
295
318
|
byMethod: {},
|
|
296
319
|
paths: [],
|
|
297
|
-
}
|
|
320
|
+
}
|
|
298
321
|
|
|
299
322
|
for (const [path, pathItem] of Object.entries(openApiSpec.paths)) {
|
|
300
323
|
for (const method of HTTP_METHODS) {
|
|
301
324
|
if (pathItem[method]) {
|
|
302
|
-
stats.total
|
|
303
|
-
stats.byMethod[method] = (stats.byMethod[method] || 0) + 1
|
|
325
|
+
stats.total++
|
|
326
|
+
stats.byMethod[method] = (stats.byMethod[method] || 0) + 1
|
|
304
327
|
stats.paths.push({
|
|
305
328
|
method: method.toUpperCase(),
|
|
306
329
|
path,
|
|
307
330
|
operationId: pathItem[method].operationId,
|
|
308
|
-
})
|
|
331
|
+
})
|
|
309
332
|
}
|
|
310
333
|
}
|
|
311
334
|
}
|
|
312
335
|
|
|
313
|
-
return stats
|
|
336
|
+
return stats
|
|
314
337
|
}
|
|
315
338
|
|
|
316
339
|
module.exports = {
|
|
@@ -320,4 +343,4 @@ module.exports = {
|
|
|
320
343
|
getSuccessStatus,
|
|
321
344
|
buildRouteHandler,
|
|
322
345
|
getRouteStats,
|
|
323
|
-
}
|
|
346
|
+
}
|