api-render-ui 1.1.2 → 1.1.4
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 +30 -0
- package/dist/index.cjs +140 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +140 -30
- package/dist/index.js.map +1 -1
- package/example/animal.html +1082 -1020
- package/package.json +1 -1
- package/src/api-render-ui.css +67 -24
- package/src/api-render-ui.ts +87 -7
- package/src/inlined-styles.ts +67 -24
- package/src/model.ts +45 -0
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ declare class ApiRenderer {
|
|
|
9
9
|
container: any;
|
|
10
10
|
private static globalStyleInjected;
|
|
11
11
|
constructor(options: any);
|
|
12
|
-
render(apiSpec: OpenAPIV3CustomDoc, renderUnit?: boolean): void;
|
|
12
|
+
render(apiSpec: OpenAPIV3CustomDoc, currentServer?: any, serviceName?: string, renderUnit?: boolean): void;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export { ApiRenderer };
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,55 @@
|
|
|
1
1
|
// src/inlined-styles.ts
|
|
2
2
|
var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
3
3
|
align-items: flex-start;
|
|
4
|
-
background: white;
|
|
4
|
+
background: var(--surface, white);
|
|
5
5
|
display: inline-flex;
|
|
6
6
|
flex-direction: column;
|
|
7
7
|
gap: 5px;
|
|
8
8
|
justify-content: flex-start;
|
|
9
9
|
width: 100%
|
|
10
10
|
}
|
|
11
|
+
/* Theme variables and mappings */
|
|
12
|
+
:root {
|
|
13
|
+
--Labels---Vibrant---Controls-Primary-\u221A: #404040;
|
|
14
|
+
--primary: #404040;
|
|
15
|
+
--main-color: #404040; /* main / primary color */
|
|
16
|
+
--aux-color: #a9c7ef; /* auxiliary color for hover / accents */
|
|
17
|
+
--embellish-color: #ced8e7; /* embellishment color for active states */
|
|
18
|
+
--surface: white;
|
|
19
|
+
--text: black;
|
|
20
|
+
--even-bg: rgb(235, 239, 244);
|
|
21
|
+
--odd-bg: rgb(250, 246, 246);
|
|
22
|
+
--hover-bg: var(--aux-color, rgb(169, 199, 239));
|
|
23
|
+
--active-bg: var(--embellish-color, rgb(206, 216, 231));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.codigma-theme-light {
|
|
27
|
+
--main-color: #404040;
|
|
28
|
+
--aux-color: #a9c7ef;
|
|
29
|
+
--embellish-color: #ced8e7;
|
|
30
|
+
--primary: var(--main-color);
|
|
31
|
+
--Labels---Vibrant---Controls-Primary-\u221A: var(--main-color);
|
|
32
|
+
--surface: white;
|
|
33
|
+
--text: black;
|
|
34
|
+
--even-bg: rgb(235, 239, 244);
|
|
35
|
+
--odd-bg: rgb(250, 246, 246);
|
|
36
|
+
--hover-bg: var(--aux-color);
|
|
37
|
+
--active-bg: var(--embellish-color);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.codigma-theme-dark {
|
|
41
|
+
--main-color: #9fb8ff;
|
|
42
|
+
--aux-color: #334155;
|
|
43
|
+
--embellish-color: #22303a;
|
|
44
|
+
--primary: var(--main-color);
|
|
45
|
+
--Labels---Vibrant---Controls-Primary-\u221A: var(--main-color);
|
|
46
|
+
--surface: #1f1f1f;
|
|
47
|
+
--text: #e6e6e6;
|
|
48
|
+
--even-bg: #2a2a2a;
|
|
49
|
+
--odd-bg: #222222;
|
|
50
|
+
--hover-bg: var(--aux-color);
|
|
51
|
+
--active-bg: var(--embellish-color);
|
|
52
|
+
}
|
|
11
53
|
.codigma-apioperator {
|
|
12
54
|
align-items: center;
|
|
13
55
|
align-self: stretch;
|
|
@@ -18,18 +60,18 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
18
60
|
justify-content: flex-start
|
|
19
61
|
}
|
|
20
62
|
.codigma-apioperator:nth-child(even) {
|
|
21
|
-
|
|
63
|
+
color: var(--main-color, var(--primary, #404040));
|
|
22
64
|
}
|
|
23
65
|
.codigma-apioperator:nth-child(odd) {
|
|
24
|
-
|
|
66
|
+
color: var(--main-color, var(--primary, #404040));
|
|
25
67
|
}
|
|
26
68
|
|
|
27
69
|
.codigma-apioperator:hover {
|
|
28
70
|
cursor: pointer;
|
|
29
|
-
|
|
71
|
+
color: var(--main-color, var(--primary, #404040));
|
|
30
72
|
}
|
|
31
73
|
.codigma-apioperator:active {
|
|
32
|
-
|
|
74
|
+
color: var(--main-color, var(--primary, #404040));
|
|
33
75
|
}
|
|
34
76
|
.codigma-method {
|
|
35
77
|
align-items: center;
|
|
@@ -45,18 +87,18 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
45
87
|
justify-content: center
|
|
46
88
|
}
|
|
47
89
|
.codigma-get {
|
|
48
|
-
color: var(--
|
|
90
|
+
color: var(--main-color, var(--primary, #404040));
|
|
49
91
|
word-wrap: break-word
|
|
50
92
|
}
|
|
51
93
|
.codigma-requrl {
|
|
52
|
-
color: black;
|
|
94
|
+
color: var(--text, black);
|
|
53
95
|
flex: 1 1 0;
|
|
54
96
|
word-wrap: break-word
|
|
55
97
|
}
|
|
56
98
|
/**********************apiunit css style*************************/
|
|
57
99
|
.codigma-apiunit {
|
|
58
100
|
align-items: flex-start;
|
|
59
|
-
background: white;
|
|
101
|
+
background: var(--surface, white);
|
|
60
102
|
box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
|
|
61
103
|
display: inline-flex;
|
|
62
104
|
flex-direction: column;
|
|
@@ -67,8 +109,8 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
67
109
|
.codigma-apiunit-apioperator {
|
|
68
110
|
align-items: center;
|
|
69
111
|
align-self: stretch;
|
|
70
|
-
border-bottom: 1px var(--
|
|
71
|
-
border-top: 1px var(--
|
|
112
|
+
border-bottom: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
113
|
+
border-top: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
72
114
|
display: inline-flex;
|
|
73
115
|
gap: 10px;
|
|
74
116
|
height: 48px;
|
|
@@ -89,17 +131,18 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
89
131
|
justify-content: center
|
|
90
132
|
}
|
|
91
133
|
.codigma-apiunit-post {
|
|
92
|
-
color: var(--
|
|
134
|
+
color: var(--main-color, var(--primary, #404040));
|
|
93
135
|
word-wrap: break-word
|
|
94
136
|
}
|
|
95
137
|
.codigma-apiunit-requrl {
|
|
96
|
-
color: black;
|
|
138
|
+
color: var(--text, black);
|
|
97
139
|
flex: 1 1 0;
|
|
98
140
|
word-wrap: break-word;
|
|
99
141
|
border-left: 0;
|
|
100
142
|
border-right: 0;
|
|
101
143
|
border-top: 0;
|
|
102
|
-
border-bottom: 1px solid
|
|
144
|
+
border-bottom: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
145
|
+
height: 70%;
|
|
103
146
|
}
|
|
104
147
|
.codigma-apiunit-send-button {
|
|
105
148
|
align-items: center;
|
|
@@ -110,7 +153,7 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
110
153
|
width: 88px
|
|
111
154
|
}
|
|
112
155
|
.codigma-apiunit-send {
|
|
113
|
-
color: black;
|
|
156
|
+
color: var(--text, black);
|
|
114
157
|
word-wrap: break-word
|
|
115
158
|
}
|
|
116
159
|
.codigma-apiunit-send-button:hover {
|
|
@@ -139,7 +182,7 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
139
182
|
}
|
|
140
183
|
.codigma-apiunit-parameters-cnr {
|
|
141
184
|
align-items: center;
|
|
142
|
-
background: white;
|
|
185
|
+
background: var(--surface, white);
|
|
143
186
|
display: flex;
|
|
144
187
|
height: 42px;
|
|
145
188
|
justify-content: space-between;
|
|
@@ -148,7 +191,7 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
148
191
|
.codigma-apiunit-parakeyvalues {
|
|
149
192
|
align-items: flex-start;
|
|
150
193
|
align-self: stretch;
|
|
151
|
-
background: white;
|
|
194
|
+
background: var(--surface, white);
|
|
152
195
|
display: inline-flex;
|
|
153
196
|
flex-direction: column;
|
|
154
197
|
flex: 1 1 0;
|
|
@@ -166,11 +209,11 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
166
209
|
}
|
|
167
210
|
.codigma-apiunit-valuetext {
|
|
168
211
|
align-self: stretch;
|
|
169
|
-
background: white;
|
|
212
|
+
background: var(--surface, white);
|
|
170
213
|
border-left: 0;
|
|
171
214
|
border-right: 0;
|
|
172
215
|
border-top: 0;
|
|
173
|
-
border-bottom: 1px var(--
|
|
216
|
+
border-bottom: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
174
217
|
padding: 10px;
|
|
175
218
|
width: 161px
|
|
176
219
|
}
|
|
@@ -195,21 +238,21 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
195
238
|
.codigma-apiunit-parakeyvalues {
|
|
196
239
|
align-items: flex-start;
|
|
197
240
|
align-self: stretch;
|
|
198
|
-
background: white;
|
|
241
|
+
background: var(--surface, white);
|
|
199
242
|
display: flex;
|
|
200
243
|
flex: 1 1 0;
|
|
201
244
|
gap: 10px;
|
|
202
245
|
justify-content: flex-start;
|
|
203
246
|
outline-offset: -1px;
|
|
204
|
-
outline: 1px var(--
|
|
247
|
+
outline: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
205
248
|
overflow: hidden;
|
|
206
249
|
padding: 10px
|
|
207
250
|
}
|
|
208
251
|
.codigma-apiunit-reqresponse {
|
|
209
252
|
align-items: flex-start;
|
|
210
253
|
align-self: stretch;
|
|
211
|
-
background: white;
|
|
212
|
-
border-top: 1px var(--
|
|
254
|
+
background: var(--surface, white);
|
|
255
|
+
border-top: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
213
256
|
display: flex;
|
|
214
257
|
flex-direction: column;
|
|
215
258
|
flex: 1 1 0;
|
|
@@ -227,7 +270,7 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
227
270
|
}
|
|
228
271
|
.codigma-apiunit-responsetitle {
|
|
229
272
|
align-items: center;
|
|
230
|
-
border-bottom: 1px var(--
|
|
273
|
+
border-bottom: 1px var(--main-color, var(--primary, #404040)) solid;
|
|
231
274
|
display: flex;
|
|
232
275
|
height: 42px;
|
|
233
276
|
justify-content: space-between;
|
|
@@ -236,7 +279,7 @@ var GLOBAL_STYLES = `.codigma-apioperatorlist {
|
|
|
236
279
|
.codigma-apiunit-response-cnr {
|
|
237
280
|
align-items: center;
|
|
238
281
|
align-self: stretch;
|
|
239
|
-
background: white;
|
|
282
|
+
background: var(--surface, white);
|
|
240
283
|
display: flex;
|
|
241
284
|
justify-content: space-between;
|
|
242
285
|
padding-top: 2px;
|
|
@@ -261,11 +304,13 @@ var ApiRenderer = class _ApiRenderer {
|
|
|
261
304
|
mountPoint: document?.body,
|
|
262
305
|
// 默认挂载到body
|
|
263
306
|
className: "Apioperatorlist codigma-apioperatorlist",
|
|
264
|
-
layerName: "apioperatorlist"
|
|
307
|
+
layerName: "apioperatorlist",
|
|
308
|
+
// theme: can be a string like 'light' or 'dark', or an object palette
|
|
309
|
+
theme: "light"
|
|
265
310
|
}, options);
|
|
266
311
|
this.container = null;
|
|
267
312
|
}
|
|
268
|
-
render(apiSpec, renderUnit = false) {
|
|
313
|
+
render(apiSpec, currentServer, serviceName, renderUnit = false) {
|
|
269
314
|
const appendInlineStyle = (text) => {
|
|
270
315
|
if (!_ApiRenderer.globalStyleInjected) {
|
|
271
316
|
const styleEl = document.createElement("style");
|
|
@@ -280,9 +325,50 @@ var ApiRenderer = class _ApiRenderer {
|
|
|
280
325
|
if (!mountElement) {
|
|
281
326
|
throw new Error("Invalid mount point specified");
|
|
282
327
|
}
|
|
328
|
+
try {
|
|
329
|
+
const themeOpt = this.options.theme;
|
|
330
|
+
if (typeof themeOpt === "string") {
|
|
331
|
+
mountElement.classList.add(`codigma-theme-${themeOpt}`);
|
|
332
|
+
} else if (themeOpt && typeof themeOpt === "object") {
|
|
333
|
+
const palette = themeOpt;
|
|
334
|
+
const setVar = (key, value) => {
|
|
335
|
+
if (value == null) return;
|
|
336
|
+
const varName = key.startsWith("--") ? key : `--${key}`;
|
|
337
|
+
try {
|
|
338
|
+
mountElement.style.setProperty(varName, String(value));
|
|
339
|
+
} catch {
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
if (palette.main) {
|
|
343
|
+
setVar("--main-color", palette.main);
|
|
344
|
+
setVar("--primary", palette.main);
|
|
345
|
+
setVar("--Labels---Vibrant---Controls-Primary-\u221A", palette.main);
|
|
346
|
+
}
|
|
347
|
+
if (palette.aux) {
|
|
348
|
+
setVar("--aux-color", palette.aux);
|
|
349
|
+
setVar("--hover-bg", palette.aux);
|
|
350
|
+
}
|
|
351
|
+
if (palette.embellish || palette.embellishment) {
|
|
352
|
+
setVar("--embellish-color", palette.embellish || palette.embellishment);
|
|
353
|
+
setVar("--active-bg", palette.embellish || palette.embellishment);
|
|
354
|
+
}
|
|
355
|
+
if (palette.primary) {
|
|
356
|
+
setVar("--primary", palette.primary);
|
|
357
|
+
setVar("--Labels---Vibrant---Controls-Primary-\u221A", palette.primary);
|
|
358
|
+
setVar("--main-color", palette.primary);
|
|
359
|
+
}
|
|
360
|
+
if (palette["--even-bg"]) setVar("--even-bg", palette["--even-bg"]);
|
|
361
|
+
if (palette["--odd-bg"]) setVar("--odd-bg", palette["--odd-bg"]);
|
|
362
|
+
if (palette.surface) setVar("--surface", palette.surface);
|
|
363
|
+
Object.entries(palette).forEach(([k, v]) => {
|
|
364
|
+
if (k.startsWith("--")) setVar(k, v);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
} catch (e) {
|
|
368
|
+
}
|
|
283
369
|
if (apiSpec["openapi"] && apiSpec["openapi"].startsWith("3.") || apiSpec["swagger"] && apiSpec["swagger"].startsWith("2.")) {
|
|
284
370
|
const countApi = countOpenAPI(apiSpec);
|
|
285
|
-
const apiOperatorList =
|
|
371
|
+
const apiOperatorList = parseOpenApiSpec(apiSpec, currentServer, serviceName);
|
|
286
372
|
if (countApi == 1 && renderUnit) {
|
|
287
373
|
this.container = createApiUnit(apiOperatorList[0]);
|
|
288
374
|
} else {
|
|
@@ -1201,7 +1287,7 @@ function createSvg() {
|
|
|
1201
1287
|
svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
|
|
1202
1288
|
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1203
1289
|
path.setAttribute("d", "M5.5 8.5L10.5 13.5L15.5 8.5");
|
|
1204
|
-
path.setAttribute("stroke", "var(--
|
|
1290
|
+
path.setAttribute("stroke", "var(--main-color, var(--primary, #404040) )");
|
|
1205
1291
|
path.setAttribute("stroke-width", "2");
|
|
1206
1292
|
path.setAttribute("stroke-linecap", "round");
|
|
1207
1293
|
path.setAttribute("stroke-linejoin", "round");
|
|
@@ -1341,7 +1427,7 @@ var HTTP_METHODS = ["get", "put", "post", "delete", "options", "head", "patch",
|
|
|
1341
1427
|
function isHttpMethod(method) {
|
|
1342
1428
|
return HTTP_METHODS.includes(method);
|
|
1343
1429
|
}
|
|
1344
|
-
function
|
|
1430
|
+
function parseOpenApiSpec(openapiSpec, currentServer, serviceName) {
|
|
1345
1431
|
const apiOperatorList = [];
|
|
1346
1432
|
const pathEntries = [];
|
|
1347
1433
|
for (const path in openapiSpec.paths) {
|
|
@@ -1362,9 +1448,18 @@ function parseOpenAPI(openapiSpec) {
|
|
|
1362
1448
|
}
|
|
1363
1449
|
}
|
|
1364
1450
|
pathItemEntries.forEach(([method, operation]) => {
|
|
1451
|
+
let url = path;
|
|
1452
|
+
if (currentServer) {
|
|
1453
|
+
url = currentServer.value + "/api/" + serviceName + "/v1" + path;
|
|
1454
|
+
} else if (openapiSpec.servers && openapiSpec.servers.length > 0) {
|
|
1455
|
+
url = openapiSpec.servers[0].url + path;
|
|
1456
|
+
}
|
|
1365
1457
|
const apiOperator = {
|
|
1458
|
+
id: uuid(),
|
|
1459
|
+
label: path,
|
|
1460
|
+
children: [],
|
|
1366
1461
|
method: method.toUpperCase(),
|
|
1367
|
-
url
|
|
1462
|
+
url,
|
|
1368
1463
|
rawApiInfo: operation,
|
|
1369
1464
|
requestBody: null,
|
|
1370
1465
|
response: {},
|
|
@@ -1455,6 +1550,21 @@ function parseOpenAPI(openapiSpec) {
|
|
|
1455
1550
|
});
|
|
1456
1551
|
return apiOperatorList;
|
|
1457
1552
|
}
|
|
1553
|
+
function uuid() {
|
|
1554
|
+
let s = [];
|
|
1555
|
+
const hexDigits = "0123456789abcdef";
|
|
1556
|
+
for (let i = 0; i < 28; i++) {
|
|
1557
|
+
const start = Math.floor(Math.random() * 16);
|
|
1558
|
+
s[i] = hexDigits.substring(start, start + 1);
|
|
1559
|
+
}
|
|
1560
|
+
s[14] = "4";
|
|
1561
|
+
const start1 = s[19] & 3 | 8;
|
|
1562
|
+
s[19] = hexDigits.substring(start1, start1 + 1);
|
|
1563
|
+
s[8] = s[13] = s[18] = s[23] = "-";
|
|
1564
|
+
s[0] = "a";
|
|
1565
|
+
var uuid2 = s.join("");
|
|
1566
|
+
return uuid2;
|
|
1567
|
+
}
|
|
1458
1568
|
function countOpenAPI(openapiSpec) {
|
|
1459
1569
|
let apiCount = 0;
|
|
1460
1570
|
const pathEntries = [];
|