mushroom-cli 1.1.2 → 1.2.0-alpha.10

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/docs/doc-mt.js CHANGED
@@ -1,526 +1,523 @@
1
- function toCSharpName(str) {
2
- var name = str.replace(/\W/g, "_");
3
- return name.charAt(0).toUpperCase() + name.substr(1);
4
- }
5
-
6
- function getHttpMethod(actionName) {
7
- switch (actionName) {
8
- case "findMany":
9
- case "findById":
10
- return "GET";
11
- case "createOne":
12
- case "createMany":
13
- return "POST";
14
- case "updateOne":
15
- case "updateMany":
16
- return "PUT";
17
- case "updatePartially":
18
- return "PATCH";
19
- case "deleteOne":
20
- case "deleteMany":
21
- return "DELETE";
22
- default:
23
- if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
24
- return actionName.substr("_raw_http_method_".length);
25
- return "UNKNOWN(" + actionName + ")";
26
- }
27
- }
28
-
29
- function getPanelClass(actionName) {
30
- switch (actionName) {
31
- case "findMany":
32
- case "findById":
33
- return "panel panel-primary";
34
- case "createOne":
35
- case "createMany":
36
- return "panel panel-info";
37
- case "updateOne":
38
- case "updateMany":
39
- return "panel panel-warning";
40
- case "updatePartially":
41
- return "panel panel-warning";
42
- case "deleteOne":
43
- case "deleteMany":
44
- return "panel panel-danger";
45
- default:
46
- return "panel panel-default";
47
- }
48
- }
49
-
50
- function getApiUrl(actionName, rootUrl, entityName) {
51
- switch (actionName) {
52
- case "findMany":
53
- case "createOne":
54
- case "createMany":
55
- case "updateMany":
56
- case "deleteMany":
57
- return rootUrl + entityName + "s";
58
- case "findById":
59
- case "updateOne":
60
- case "updatePartially":
61
- case "deleteOne":
62
- return rootUrl + entityName + "s/{" + entityName + "Id}";
63
- default:
64
- if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
65
- return (
66
- rootUrl +
67
- entityName +
68
- "s/" +
69
- actionName.substr("_raw_http_method_".length)
70
- );
71
- return "UNKNOWN(" + actionName + ")";
72
- }
73
- }
74
-
75
- function getApiViewUrl(rootUrl, entityName, viewName) {
76
- return rootUrl + entityName + "s/views/" + viewName;
77
- }
78
-
79
- function getDescriptionByActionName(actionName, entityName) {
80
- switch (actionName) {
81
- case "findMany":
82
- return "Lấy về danh sách các " + entityName;
83
- case "findById":
84
- return "Lấy về một " + entityName + " theo mã của nó";
85
- case "createOne":
86
- return "Tạo mới một " + entityName;
87
- case "createMany":
88
- return "Tạo mới hàng loạt các " + entityName;
89
- case "updateOne":
90
- return "Cập nhật một " + entityName;
91
- case "updateMany":
92
- return "Cập nhật hàng loạt các " + entityName;
93
- case "updatePartially":
94
- return "Cập nhật một phần dữ liệu của " + entityName;
95
- case "deleteOne":
96
- return "Xóa một " + entityName + " theo mã của nó";
97
- case "deleteMany":
98
- return "Xóa hàng loạt " + entityName;
99
- default:
100
- if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
101
- return "";
102
- return "UNKNOWN(" + actionName + ")";
103
- }
104
- }
105
-
106
- function getModalOutput(arrFields, fields, options) {
107
- if (!fields || !arrFields) return "";
108
-
109
- var obj = {};
110
- for (var j = 0; j < arrFields.length; j++) {
111
- if (!arrFields[j]) continue;
112
- var segs = arrFields[j].split(".");
113
- var objFields = fields;
114
- var cur = obj;
115
- for (var i = 0; i < segs.length; i++) {
116
- if (segs[i] in objFields) {
117
- var field = objFields[segs[i]];
118
-
119
- if (i === segs.length - 1) {
120
- if (!(segs[i] in cur))
121
- cur[segs[i]] = JSON.parse(JSON.stringify(field));
122
- } else if (field.type === "object") {
123
- objFields = field.fields;
124
- if (!(segs[i] in cur)) {
125
- var o = { type: "object", fields: {} };
126
- cur[segs[i]] = o;
127
- cur = o.fields;
128
- } else cur = cur[segs[i]].fields;
129
- } else if (field.type === "array") {
130
- objFields = field.items.fields;
131
- if (!(segs[i] in cur)) {
132
- var a = { type: "array", items: { type: "object", fields: {} } };
133
- cur[segs[i]] = a;
134
- cur = a.items.fields;
135
- } else cur = cur[segs[i]].items.fields;
136
- }
137
- }
138
- }
139
- }
140
-
141
- return formatModal(obj, "", options) /* + JSON.stringify(obj)*/;
142
- }
143
-
144
- function formatModal(obj, strIndent, options) {
145
- if (!obj) return "";
146
-
147
- options = options || {};
148
-
149
- var result = "";
150
- var nextIndent = strIndent + " ";
151
- for (var m in obj) {
152
- if (!obj.hasOwnProperty(m)) continue;
153
-
154
- var child = obj[m];
155
-
156
- var validation =
157
- !options.optionalToAll && child.validation && child.validation.required
158
- ? "required"
159
- : "optional";
160
- if (child.type === "IdRef" && child.reference) {
161
- validation +=
162
- ", ref: <a href='#" +
163
- encodeHtml(child.reference) +
164
- "' onclick='setTimeout(gotoHash, 20)'>" +
165
- encodeHtml(child.reference) +
166
- "</a>";
167
- }
168
-
169
- if (child.validation) {
170
- if ("validValues" in child.validation)
171
- validation +=
172
- ", enum(" + encodeHtml(child.validation.validValues.join(", ")) + ")";
173
- if ("invalidValues" in child.validation)
174
- validation +=
175
- ", not allow(" +
176
- encodeHtml(child.validation.invalidValues.join(", ")) +
177
- ")";
178
- if ("pattern" in child.validation)
179
- validation +=
180
- ", pattern: /" + encodeHtml(child.validation.pattern) + "/";
181
- if ("length" in child.validation)
182
- validation += ", length: " + child.validation.length;
183
- if ("minLength" in child.validation)
184
- validation += ", minLength: " + child.validation.minLength;
185
- if ("maxLength" in child.validation)
186
- validation += ", maxLength: " + child.validation.maxLength;
187
- if ("min" in child.validation)
188
- validation += ", min: " + encodeHtml(child.validation.min);
189
- if ("max" in child.validation)
190
- validation += ", max: " + encodeHtml(child.validation.max);
191
- if ("gt" in child.validation)
192
- validation += ", gt: " + encodeHtml(child.validation.gt);
193
- if ("lt" in child.validation)
194
- validation += ", lt: " + encodeHtml(child.validation.lt);
195
- }
196
-
197
- if (
198
- child.type === "array" &&
199
- child.items &&
200
- child.items.type != "object" &&
201
- child.items.validation
202
- ) {
203
- validation +=
204
- ", array items: " +
205
- (!options.optionalToAll && child.items.validation.required
206
- ? "required"
207
- : "optional");
208
- if ("validValues" in child.items.validation)
209
- validation +=
210
- ", enum(" +
211
- encodeHtml(child.items.validation.validValues.join(", ")) +
212
- ")";
213
- if ("invalidValues" in child.items.validation)
214
- validation +=
215
- ", not allow(" +
216
- encodeHtml(child.items.validation.invalidValues.join(", ")) +
217
- ")";
218
- if ("pattern" in child.items.validation)
219
- validation +=
220
- ", pattern: /" + encodeHtml(child.items.validation.pattern) + "/";
221
- if ("length" in child.items.validation)
222
- validation += ", length: " + child.items.validation.length;
223
- if ("minLength" in child.items.validation)
224
- validation += ", minLength: " + child.items.validation.minLength;
225
- if ("maxLength" in child.items.validation)
226
- validation += ", maxLength: " + child.items.validation.maxLength;
227
- if ("min" in child.items.validation)
228
- validation += ", min: " + encodeHtml(child.items.validation.min);
229
- if ("max" in child.items.validation)
230
- validation += ", max: " + encodeHtml(child.items.validation.max);
231
- if ("gt" in child.items.validation)
232
- validation += ", gt: " + encodeHtml(child.items.validation.gt);
233
- if ("lt" in child.items.validation)
234
- validation += ", lt: " + encodeHtml(child.items.validation.lt);
235
- }
236
-
237
- var comment = `<span class="code-comment">// ${validation} ${typeof child.description === "string" && child.description !== "" ? "- " + encodeHtml(child.description) : ""}</span>`;
238
-
239
- if (options.mode === "modal") {
240
- if (child.type === "object")
241
- result +=
242
- "\r\n" +
243
- nextIndent +
244
- '"' +
245
- m +
246
- '": ' +
247
- comment +
248
- formatModal(child.fields, nextIndent, options) +
249
- ",";
250
- else if (child.type === "array") {
251
- result += `\r\n${nextIndent}"${m}": [`;
252
- if (child.items.type === "object")
253
- result +=
254
- " " +
255
- comment +
256
- formatModal(child.items.fields, nextIndent, options);
257
- else if (child.items.type === "datetime")
258
- result +=
259
- `\r\n${nextIndent} ` +
260
- JSON.stringify(child.items.defaultValue || "ISODate_ISO_8601") +
261
- " " +
262
- comment +
263
- `\r\n${nextIndent}`;
264
- else if (child.items.type === "boolean")
265
- result +=
266
- `\r\n${nextIndent} ` + child.items.defaultValue ||
267
- "false" + " " + comment + `\r\n${nextIndent}`;
268
- else if (
269
- child.items.type === "integer" ||
270
- child.items.type === "long" ||
271
- child.items.type === "double"
272
- )
273
- result +=
274
- `\r\n${nextIndent} ` + child.items.defaultValue ||
275
- "0" + " " + comment + `\r\n${nextIndent}`;
276
- else
277
- result +=
278
- `\r\n${nextIndent} ` +
279
- JSON.stringify(child.defaultValue || child.type) +
280
- " " +
281
- comment +
282
- `\r\n${nextIndent}`;
283
- result += `]`;
284
- } else if (child.type === "datetime")
285
- result +=
286
- `\r\n${nextIndent}"${m}": ` +
287
- JSON.stringify(child.defaultValue || "ISODate_ISO_8601") +
288
- ", " +
289
- comment;
290
- else if (child.type === "boolean")
291
- result +=
292
- `\r\n${nextIndent}"${m}": ` +
293
- (child.defaultValue || "false") +
294
- ", " +
295
- comment;
296
- else if (
297
- child.type === "integer" ||
298
- child.type === "long" ||
299
- child.type === "double"
300
- )
301
- result +=
302
- `\r\n${nextIndent}"${m}": ` +
303
- (child.defaultValue || "0") +
304
- ", " +
305
- comment;
306
- else
307
- result +=
308
- `\r\n${nextIndent}"${m}": ` +
309
- JSON.stringify(child.defaultValue || child.type) +
310
- ", " +
311
- comment;
312
- } else if (options.mode === "modal_null") {
313
- if (child.type === "object")
314
- result +=
315
- "\r\n" +
316
- nextIndent +
317
- '"' +
318
- m +
319
- '": ' +
320
- comment +
321
- formatModal(child.fields, nextIndent, options);
322
- else if (child.type === "array") {
323
- result += `\r\n${nextIndent}"${m}": [`;
324
- if (child.items.type === "object")
325
- result +=
326
- " " +
327
- comment +
328
- formatModal(child.items.fields, nextIndent, options) +
329
- "],";
330
- else result += "], " + comment;
331
- } else result += `\r\n${nextIndent}"${m}": null, ${comment}`;
332
- } else if (options.mode === "modal_undefined") {
333
- if (child.type === "object")
334
- result +=
335
- "\r\n" +
336
- nextIndent +
337
- '"' +
338
- m +
339
- '": ' +
340
- comment +
341
- formatModal(child.fields, nextIndent, options);
342
- else if (child.type === "array") {
343
- result += `\r\n${nextIndent}"${m}": [`;
344
- if (child.items.type === "object")
345
- result +=
346
- " " +
347
- comment +
348
- formatModal(child.items.fields, nextIndent, options) +
349
- "], ";
350
- else result += "], " + comment;
351
- } else result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
352
- } else {
353
- result +=
354
- "\r\n" + strIndent + encodeHtml(m) + ": " + encodeHtml(child.type);
355
- if (child.type === "array")
356
- result +=
357
- child.items.type === "object"
358
- ? " of object"
359
- : " of " + child.items.type;
360
- if (child.type === "object")
361
- result +=
362
- " " +
363
- comment +
364
- formatModal(child.fields, strIndent + " ", options);
365
- else if (child.type === "array" && child.items.type === "object")
366
- result +=
367
- " " +
368
- comment +
369
- formatModal(child.items.fields, strIndent + " ", options);
370
- else result += ", " + comment;
371
- }
372
- }
373
-
374
- if (
375
- options.mode === "modal" ||
376
- options.mode === "modal_null" ||
377
- options.mode === "modal_undefined"
378
- ) {
379
- return (
380
- (strIndent ? "\r\n" + strIndent : "") +
381
- "{" +
382
- result +
383
- "\r\n" +
384
- strIndent +
385
- "}"
386
- );
387
- }
388
-
389
- return result;
390
- }
391
-
392
- function explainRoles(strRoles) {
393
- if (!strRoles) return "";
394
-
395
- return strRoles
396
- .split("|")
397
- .map(function (item) {
398
- if (item === "*") return "[Mọi người dùng]";
399
- var roles = item.split("+");
400
- var s = "";
401
- if (roles.length > 1) s += "(";
402
-
403
- s += roles.join(" và ");
404
-
405
- if (roles.length > 1) s += ")";
406
-
407
- return s;
408
- })
409
- .join(" hoặc ");
410
- }
411
-
412
- function getModalInput(excludedFields, fields, options) {
413
- fields = JSON.parse(JSON.stringify(fields));
414
- if (!fields) return "";
415
-
416
- options = options || {};
417
-
418
- fields.id = fields.id || {};
419
- fields.id.type = fields.id.type || "AutoId";
420
- fields.id.validation = fields.id.validation || {};
421
- fields.id.validation.required = true;
422
-
423
- if (excludedFields && Array.isArray(excludedFields)) {
424
- if (options.excludeId && fields.id.type === "AutoId")
425
- excludedFields.push("id");
426
-
427
- excludedFields.forEach(function (item) {
428
- var obj = fields;
429
- var segs = item.split(".");
430
- for (var i = 0; i < segs.length; i++) {
431
- var seg = segs[i];
432
- if (!(seg in obj)) return;
433
-
434
- if (i === segs.length - 1) delete obj[seg];
435
- else if (obj[seg].type === "object") obj = obj[seg].fields;
436
- else if (obj[seg].type === "array") obj = obj[seg].items;
437
- else return;
438
- }
439
- });
440
- }
441
-
442
- return formatModal(fields, "", {
443
- showValidation: true,
444
- optionalToAll: options.optionalToAll,
445
- mode: options.mode,
446
- });
447
- }
448
-
449
- function activeFirstChild() {
450
- $(this).find("> *").eq(0).addClass("active");
451
- }
452
-
453
- $("script[type='text/mt-template']").each(function () {
454
- mt.inlineModuleTemplates[this.id] = this.innerHTML;
455
- });
456
-
457
- var data = {};
458
-
459
- function afterGenerated() {
460
- var domApiName = document.querySelector("#apiName");
461
- if (domApiName) document.title = domApiName.textContent + " API Document";
462
- }
463
-
464
- function generateDocument() {
465
- // console.log(data);
466
- mt.bindDom(document.body, data);
467
- afterGenerated();
468
- }
469
-
470
- function saveDocument() {
471
- var textFileAsBlob = new Blob(
472
- ["<!DOCTYPE html>\r\n" + document.documentElement.outerHTML],
473
- { type: "application/octet-stream" },
474
- );
475
-
476
- var downloadLink = document.createElement("a");
477
- //downloadLink.download = data.name + "-docs.html";
478
- downloadLink.download = "docs.html";
479
- if (window.URL) {
480
- // Firefox requires the link to be added to the DOM
481
- // before it can be clicked.
482
- downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
483
- downloadLink.onclick = function () {
484
- document.body.removeChild(downloadLink);
485
- };
486
- downloadLink.style.display = "none";
487
- document.body.appendChild(downloadLink);
488
- } else if (window.webkitURL) {
489
- // Chrome allows the link to be clicked
490
- // without actually adding it to the DOM.
491
- downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
492
- }
493
-
494
- downloadLink.click();
495
- }
496
-
497
- function concat() {
498
- return String.prototype.concat.apply("", arguments);
499
- }
500
-
501
- function getRootApiUrl() {
502
- return window.data.rootUrl;
503
- }
504
-
505
- function getApiDomain() {
506
- var m = window.data.rootUrl.match(/^\w+:\/\/((\w+\.)+\w+(:\d+)?)/);
507
- if (m) return m[1];
508
- return "your host";
509
- }
510
-
511
- function getApiPath() {
512
- var m = window.data.rootUrl.match(/^\w+:\/\/(\w+\.)+\w+(:\d+)?/);
513
- if (m) return window.data.rootUrl.substr(m[0].length);
514
- return window.data.rootUrl;
515
- }
516
-
517
- function encodeHtml(data) {
518
- if (data === undefined || data === null) return "";
519
- var html = typeof data === "string" ? data : data.toString();
520
- html = html.replace(/&/g, "&amp;");
521
- html = html.replace(/</g, "&lt;");
522
- html = html.replace(/>/g, "&gt;");
523
- html = html.replace(/"/g, "&quot;");
524
- html = html.replace(/'/g, "&apos;");
525
- return html;
526
- }
1
+ function toCSharpName(str) {
2
+ var name = str.replace(/\W/g, "_");
3
+ return name.charAt(0).toUpperCase() + name.substr(1);
4
+ }
5
+
6
+ function getHttpMethod(actionName) {
7
+ switch (actionName) {
8
+ case "findMany":
9
+ case "findById":
10
+ return "GET";
11
+ case "createOne":
12
+ case "createMany":
13
+ return "POST";
14
+ case "updateOne":
15
+ case "updateMany":
16
+ return "PUT";
17
+ case "updatePartially":
18
+ return "PATCH";
19
+ case "deleteOne":
20
+ case "deleteMany":
21
+ return "DELETE";
22
+ default:
23
+ if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
24
+ return actionName.substr("_raw_http_method_".length);
25
+ return "UNKNOWN(" + actionName + ")";
26
+ }
27
+ }
28
+
29
+ function getPanelClass(actionName) {
30
+ switch (actionName) {
31
+ case "findMany":
32
+ case "findById":
33
+ return "panel panel-primary";
34
+ case "createOne":
35
+ case "createMany":
36
+ return "panel panel-info";
37
+ case "updateOne":
38
+ case "updateMany":
39
+ return "panel panel-warning";
40
+ case "updatePartially":
41
+ return "panel panel-warning";
42
+ case "deleteOne":
43
+ case "deleteMany":
44
+ return "panel panel-danger";
45
+ default:
46
+ return "panel panel-default";
47
+ }
48
+ }
49
+
50
+ function getApiUrl(actionName, rootUrl, entityName) {
51
+ switch (actionName) {
52
+ case "findMany":
53
+ case "createOne":
54
+ case "createMany":
55
+ case "updateMany":
56
+ case "deleteMany":
57
+ return rootUrl + entityName + "s";
58
+ case "findById":
59
+ case "updateOne":
60
+ case "updatePartially":
61
+ case "deleteOne":
62
+ return rootUrl + entityName + "s/{" + entityName + "Id}";
63
+ default:
64
+ if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
65
+ return rootUrl + entityName + "s/" + actionName.substr("_raw_http_method_".length);
66
+ return "UNKNOWN(" + actionName + ")";
67
+ }
68
+ }
69
+
70
+ function getApiViewUrl(rootUrl, entityName, viewName) {
71
+ return rootUrl + entityName + "s/views/" + viewName;
72
+ }
73
+
74
+ function getDescriptionByActionName(actionName, entityName) {
75
+ switch (actionName) {
76
+ case "findMany":
77
+ return "Lấy về danh sách các " + entityName;
78
+ case "findById":
79
+ return "Lấy về một " + entityName + " theo mã của nó";
80
+ case "createOne":
81
+ return "Tạo mới một " + entityName;
82
+ case "createMany":
83
+ return "Tạo mới hàng loạt các " + entityName;
84
+ case "updateOne":
85
+ return "Cập nhật một " + entityName;
86
+ case "updateMany":
87
+ return "Cập nhật hàng loạt các " + entityName;
88
+ case "updatePartially":
89
+ return "Cập nhật một phần dữ liệu của " + entityName;
90
+ case "deleteOne":
91
+ return "Xóa một " + entityName + " theo mã của nó";
92
+ case "deleteMany":
93
+ return "Xóa hàng loạt " + entityName;
94
+ default:
95
+ if (actionName && actionName.indexOf("_raw_http_method_") !== -1)
96
+ return "";
97
+ return "UNKNOWN(" + actionName + ")";
98
+ }
99
+ }
100
+
101
+ function getModalOutput(arrFields, fields, options) {
102
+ if (!fields || !arrFields)
103
+ return "";
104
+
105
+ var obj = {};
106
+ for (var j = 0; j < arrFields.length; j++) {
107
+ if (!arrFields[j])
108
+ continue;
109
+ var segs = arrFields[j].split('.');
110
+ var objFields = fields;
111
+ var cur = obj;
112
+ for (var i = 0; i < segs.length; i++) {
113
+ if (segs[i] in objFields) {
114
+ var field = objFields[segs[i]];
115
+
116
+ if (i === segs.length - 1) {
117
+ if (!(segs[i] in cur))
118
+ cur[segs[i]] = JSON.parse(JSON.stringify(field));
119
+ }
120
+ else if (field.type === "object") {
121
+ objFields = field.fields;
122
+ if (!(segs[i] in cur)) {
123
+ var o = { type: "object", fields: {} };
124
+ cur[segs[i]] = o;
125
+ cur = o.fields;
126
+ } else
127
+ cur = cur[segs[i]].fields;
128
+ }
129
+ else if (field.type === "array") {
130
+ objFields = field.items.fields;
131
+ if (!(segs[i] in cur)) {
132
+ var a = { type: "array", items: { type: "object", fields: {}} };
133
+ cur[segs[i]] = a;
134
+ cur = a.items.fields;
135
+ } else
136
+ cur = cur[segs[i]].items.fields;
137
+ }
138
+ }
139
+ }
140
+ }
141
+
142
+ return formatModal(obj, "", options)/* + JSON.stringify(obj)*/;
143
+ }
144
+
145
+ function formatModal(obj, strIndent, options) {
146
+ if (!obj)
147
+ return "";
148
+
149
+ options = options || {};
150
+
151
+ var result = "";
152
+ var nextIndent = strIndent + " ";
153
+ for (var m in obj) {
154
+ if (!obj.hasOwnProperty(m))
155
+ continue;
156
+
157
+ var child = obj[m];
158
+
159
+ var validation = !options.optionalToAll && child.validation && child.validation.required ? "required" : "optional";
160
+ if (child.type === "IdRef" && child.reference) {
161
+ validation += ", ref: <a href='#" + encodeHtml(child.reference) + "' onclick='setTimeout(gotoHash, 20)'>" + encodeHtml(child.reference) + "</a>";
162
+ }
163
+
164
+ if (child.validation) {
165
+ if ("validValues" in child.validation)
166
+ validation += ", enum(" + encodeHtml(child.validation.validValues.join(", ")) + ")";
167
+ if ("invalidValues" in child.validation)
168
+ validation += ", not allow(" + encodeHtml(child.validation.invalidValues.join(", ")) + ")";
169
+ if ("pattern" in child.validation)
170
+ validation += ", pattern: /" + encodeHtml(child.validation.pattern) + "/";
171
+ if ("length" in child.validation)
172
+ validation += ", length: " + child.validation.length;
173
+ if ("minLength" in child.validation)
174
+ validation += ", minLength: " + child.validation.minLength;
175
+ if ("maxLength" in child.validation)
176
+ validation += ", maxLength: " + child.validation.maxLength;
177
+ if ("min" in child.validation)
178
+ validation += ", min: " + encodeHtml(child.validation.min);
179
+ if ("max" in child.validation)
180
+ validation += ", max: " + encodeHtml(child.validation.max);
181
+ if ("gt" in child.validation)
182
+ validation += ", gt: " + encodeHtml(child.validation.gt);
183
+ if ("lt" in child.validation)
184
+ validation += ", lt: " + encodeHtml(child.validation.lt);
185
+ }
186
+
187
+ if (child.type === "array" && child.items && child.items.type != "object" && child.items.validation) {
188
+ validation += ", array items: " + (!options.optionalToAll && child.items.validation.required ? "required" : "optional");
189
+ if ("validValues" in child.items.validation)
190
+ validation += ", enum(" + encodeHtml(child.items.validation.validValues.join(", ")) + ")";
191
+ if ("invalidValues" in child.items.validation)
192
+ validation += ", not allow(" + encodeHtml(child.items.validation.invalidValues.join(", ")) + ")";
193
+ if ("pattern" in child.items.validation)
194
+ validation += ", pattern: /" + encodeHtml(child.items.validation.pattern) + "/";
195
+ if ("length" in child.items.validation)
196
+ validation += ", length: " + child.items.validation.length;
197
+ if ("minLength" in child.items.validation)
198
+ validation += ", minLength: " + child.items.validation.minLength;
199
+ if ("maxLength" in child.items.validation)
200
+ validation += ", maxLength: " + child.items.validation.maxLength;
201
+ if ("min" in child.items.validation)
202
+ validation += ", min: " + encodeHtml(child.items.validation.min);
203
+ if ("max" in child.items.validation)
204
+ validation += ", max: " + encodeHtml(child.items.validation.max);
205
+ if ("gt" in child.items.validation)
206
+ validation += ", gt: " + encodeHtml(child.items.validation.gt);
207
+ if ("lt" in child.items.validation)
208
+ validation += ", lt: " + encodeHtml(child.items.validation.lt);
209
+ }
210
+
211
+ var comment = `<span class="code-comment">// ${validation} ${typeof child.description === "string" && child.description !== "" ? "- " + encodeHtml(child.description) : ""}</span>`;
212
+
213
+ if (options.mode === "modal") {
214
+ if (child.type === "object")
215
+ result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatModal(child.fields, nextIndent, options) + ",";
216
+ else if (child.type === "array") {
217
+ result += `\r\n${nextIndent}"${m}": [`;
218
+ if (child.items.type === "object")
219
+ result += " " + comment + formatModal(child.items.fields, nextIndent, options);
220
+ else if (child.items.type === "datetime")
221
+ result += `\r\n${nextIndent} ` + JSON.stringify(child.items.defaultValue || "ISODate_ISO_8601") + " " + comment + `\r\n${nextIndent}`;
222
+ else if (child.items.type === "boolean")
223
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || "false" + " " + comment + `\r\n${nextIndent}`;
224
+ else if (child.items.type === "integer" || child.items.type === "long"|| child.items.type === "double")
225
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || "0" + " " + comment + `\r\n${nextIndent}`;
226
+ else
227
+ result += `\r\n${nextIndent} ` + JSON.stringify(child.defaultValue || child.type) + " " + comment + `\r\n${nextIndent}`;
228
+ result += `]`;
229
+ }
230
+ else if (child.type === "datetime")
231
+ result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || "ISODate_ISO_8601") + ", " + comment;
232
+ else if (child.type === "boolean")
233
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "false") + ", " + comment;
234
+ else if (child.type === "integer" || child.type === "long"|| child.type === "double")
235
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "0") + ", " + comment;
236
+ else
237
+ result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || child.type) + ", " + comment;
238
+ } else if (options.mode === "modal_null") {
239
+ if (child.type === "object")
240
+ result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatModal(child.fields, nextIndent, options);
241
+ else if (child.type === "array") {
242
+ result += `\r\n${nextIndent}"${m}": [`;
243
+ if (child.items.type === "object")
244
+ result += " " + comment + formatModal(child.items.fields, nextIndent, options) + "],";
245
+ else
246
+ result += "], " + comment;
247
+ }
248
+ else
249
+ result += `\r\n${nextIndent}"${m}": null, ${comment}`;
250
+ } else if (options.mode === "modal_undefined") {
251
+ if (child.type === "object")
252
+ result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatModal(child.fields, nextIndent, options);
253
+ else if (child.type === "array") {
254
+ result += `\r\n${nextIndent}"${m}": [`;
255
+ if (child.items.type === "object")
256
+ result += " " + comment + formatModal(child.items.fields, nextIndent, options) + "], ";
257
+ else
258
+ result += "], " + comment;
259
+ }
260
+ else
261
+ result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
262
+ } else {
263
+ result += "\r\n" + strIndent + encodeHtml(m) + ": " + encodeHtml(child.type);
264
+ if (child.type === "array")
265
+ result += child.items.type === "object" ? " of object" : " of " + child.items.type;
266
+ if (child.type === "object")
267
+ result += " " + comment + formatModal(child.fields, strIndent + " ", options);
268
+ else if (child.type === "array" && child.items.type === "object")
269
+ result += " " + comment + formatModal(child.items.fields, strIndent + " ", options);
270
+ else
271
+ result += ", " + comment;
272
+ }
273
+ }
274
+
275
+ if (options.mode === "modal" || options.mode === "modal_null" || options.mode === "modal_undefined") {
276
+ return (strIndent ? "\r\n" + strIndent : "") + "{" + result + "\r\n" + strIndent + "}";
277
+ }
278
+
279
+ return result;
280
+ }
281
+
282
+ function formatHintModal(obj, strIndent, options) {
283
+ if (!obj)
284
+ return "";
285
+
286
+ strIndent = strIndent || "";
287
+ options = options || {};
288
+
289
+ var result = "";
290
+ var nextIndent = strIndent + " ";
291
+ for (var m in obj) {
292
+ if (!obj.hasOwnProperty(m))
293
+ continue;
294
+
295
+ var child = obj[m];
296
+
297
+ var validation = !options.optionalToAll && child.required ? "required" : "optional";
298
+ if (child.type === "IdRef" && child.reference) {
299
+ validation += ", ref: <a href='#" + encodeHtml(child.reference) + "' onclick='setTimeout(gotoHash, 20)'>" + encodeHtml(child.reference) + "</a>";
300
+ }
301
+
302
+ if (child.validValues && Array.isArray(child.validValues)) {
303
+ validation += ", enum(" + encodeHtml(child.validValues.join(", ")) + ")";
304
+ }
305
+
306
+ if (child.type === "array" && child.items && child.items.type != "object") {
307
+ validation += ", array items: " + (!options.optionalToAll && child.items.required ? "required" : "optional");
308
+ if (child.items.validValues && Array.isArray(child.items.validValues))
309
+ validation += ", enum(" + encodeHtml(child.items.validValues.join(", ")) + ")";
310
+ }
311
+
312
+ var comment = `<span class="code-comment">// ${validation} ${typeof child.description === "string" && child.description !== "" ? "- " + encodeHtml(child.description) : ""}</span>`;
313
+
314
+ if (options.mode === "modal") {
315
+ if (child.type === "object")
316
+ result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatHintModal(child.fields, nextIndent, options) + ",";
317
+ else if (child.type === "array") {
318
+ result += `\r\n${nextIndent}"${m}": [`;
319
+ if (child.items.type === "object")
320
+ result += " " + comment + formatHintModal(child.items.fields, nextIndent, options);
321
+ else if (child.items.type === "datetime")
322
+ result += `\r\n${nextIndent} ` + JSON.stringify(child.items.defaultValue || "ISODate_ISO_8601") + " " + comment + `\r\n${nextIndent}`;
323
+ else if (child.items.type === "boolean")
324
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || "false" + " " + comment + `\r\n${nextIndent}`;
325
+ else if (child.items.type === "integer" || child.items.type === "long"|| child.items.type === "double")
326
+ result += `\r\n${nextIndent} ` + child.items.defaultValue || "0" + " " + comment + `\r\n${nextIndent}`;
327
+ else
328
+ result += `\r\n${nextIndent} ` + JSON.stringify(child.defaultValue || child.type) + " " + comment + `\r\n${nextIndent}`;
329
+ result += `]`;
330
+ }
331
+ else if (child.type === "datetime")
332
+ result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || "ISODate_ISO_8601") + ", " + comment;
333
+ else if (child.type === "boolean")
334
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "false") + ", " + comment;
335
+ else if (child.type === "integer" || child.type === "long"|| child.type === "double")
336
+ result += `\r\n${nextIndent}"${m}": ` + (child.defaultValue || "0") + ", " + comment;
337
+ else
338
+ result += `\r\n${nextIndent}"${m}": ` + JSON.stringify(child.defaultValue || child.type) + ", " + comment;
339
+ } else if (options.mode === "modal_null") {
340
+ if (child.type === "object")
341
+ result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatHintModal(child.fields, nextIndent, options);
342
+ else if (child.type === "array") {
343
+ result += `\r\n${nextIndent}"${m}": [`;
344
+ if (child.items.type === "object")
345
+ result += " " + comment + formatHintModal(child.items.fields, nextIndent, options) + "],";
346
+ else
347
+ result += "], " + comment;
348
+ }
349
+ else
350
+ result += `\r\n${nextIndent}"${m}": null, ${comment}`;
351
+ } else if (options.mode === "modal_undefined") {
352
+ if (child.type === "object")
353
+ result += "\r\n" + nextIndent + '"' + m + '": ' + comment + formatHintModal(child.fields, nextIndent, options);
354
+ else if (child.type === "array") {
355
+ result += `\r\n${nextIndent}"${m}": [`;
356
+ if (child.items.type === "object")
357
+ result += " " + comment + formatHintModal(child.items.fields, nextIndent, options) + "], ";
358
+ else
359
+ result += "], " + comment;
360
+ }
361
+ else
362
+ result += `\r\n${nextIndent}"${m}": undefined, ${comment}`;
363
+ } else {
364
+ result += "\r\n" + strIndent + encodeHtml(m) + ": " + encodeHtml(child.type);
365
+ if (child.type === "array")
366
+ result += child.items.type === "object" ? " of object" : " of " + child.items.type;
367
+ if (child.type === "object")
368
+ result += " " + comment + formatHintModal(child.fields, strIndent + " ", options);
369
+ else if (child.type === "array" && child.items.type === "object")
370
+ result += " " + comment + formatHintModal(child.items.fields, strIndent + " ", options);
371
+ else
372
+ result += ", " + comment;
373
+ }
374
+ }
375
+
376
+ if (options.mode === "modal" || options.mode === "modal_null" || options.mode === "modal_undefined") {
377
+ return (strIndent ? "\r\n" + strIndent : "") + "{" + result + "\r\n" + strIndent + "}";
378
+ }
379
+
380
+ return result;
381
+ }
382
+
383
+ function explainRoles(strRoles) {
384
+ if (!strRoles)
385
+ return "";
386
+
387
+ return strRoles.split("|").map(function (item) {
388
+ if (item === "*")
389
+ return "[Mọi người dùng]";
390
+ var roles = item.split("+");
391
+ var s = "";
392
+ if (roles.length > 1)
393
+ s += "(";
394
+
395
+ s += roles.join(" và ");
396
+
397
+ if (roles.length > 1)
398
+ s += ")";
399
+
400
+ return s;
401
+ }).join(" hoặc ");
402
+ }
403
+
404
+ function getModalInput(excludedFields, fields, options) {
405
+ fields = JSON.parse(JSON.stringify(fields));
406
+ if (!fields)
407
+ return "";
408
+
409
+ options = options || {};
410
+
411
+ fields.id = fields.id || {};
412
+ fields.id.type = fields.id.type || "AutoId";
413
+ fields.id.validation = fields.id.validation || {};
414
+ fields.id.validation.required = true;
415
+
416
+ if (excludedFields && Array.isArray(excludedFields)) {
417
+ if (options.excludeId && fields.id.type === "AutoId")
418
+ excludedFields.push("id");
419
+
420
+ excludedFields.forEach(function (item) {
421
+ var obj = fields;
422
+ var segs = item.split(".");
423
+ for (var i = 0; i < segs.length; i++) {
424
+ if (!obj) return;
425
+ var seg = segs[i];
426
+ if (!(seg in obj))
427
+ return;
428
+
429
+ if (i === segs.length - 1)
430
+ delete obj[seg];
431
+ else if (obj[seg].type === "object")
432
+ obj = obj[seg].fields;
433
+ else if (obj[seg].type === "array")
434
+ obj = obj[seg].items?.fields;
435
+ else
436
+ return;
437
+ }
438
+ });
439
+ }
440
+
441
+ return formatModal(fields, "", { showValidation: true, optionalToAll: options.optionalToAll, mode: options.mode });
442
+ }
443
+
444
+
445
+ function activeFirstChild() {
446
+ $(this).find("> *").eq(0).addClass("active");
447
+ }
448
+
449
+ $("script[type='text/mt-template']").each(function () {
450
+ mt.inlineModuleTemplates[this.id] = this.innerHTML;
451
+ });
452
+
453
+ var data = {};
454
+
455
+ function afterGenerated() {
456
+ var domApiName = document.querySelector("#apiName");
457
+ if (domApiName)
458
+ document.title = domApiName.textContent + " API Document";
459
+ }
460
+
461
+ function generateDocument() {
462
+ // console.log(data);
463
+ mt.bindDom(document.body, data);
464
+ afterGenerated();
465
+ }
466
+
467
+ function saveDocument() {
468
+ var textFileAsBlob = new Blob(["<!DOCTYPE html>\r\n" + document.documentElement.outerHTML], { type: "application/octet-stream" });
469
+
470
+ var downloadLink = document.createElement("a");
471
+ //downloadLink.download = data.name + "-docs.html";
472
+ downloadLink.download = "docs.html";
473
+ if (window.URL) {
474
+ // Firefox requires the link to be added to the DOM
475
+ // before it can be clicked.
476
+ downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
477
+ downloadLink.onclick = function () {
478
+ document.body.removeChild(downloadLink);
479
+ };
480
+ downloadLink.style.display = "none";
481
+ document.body.appendChild(downloadLink);
482
+ } else if (window.webkitURL) {
483
+ // Chrome allows the link to be clicked
484
+ // without actually adding it to the DOM.
485
+ downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
486
+ }
487
+
488
+ downloadLink.click();
489
+ }
490
+
491
+ function concat() {
492
+ return String.prototype.concat.apply("", arguments);
493
+ }
494
+
495
+ function getRootApiUrl() {
496
+ return window.data.rootUrl;
497
+ }
498
+
499
+ function getApiDomain() {
500
+ var m = window.data.rootUrl.match(/^\w+:\/\/((\w+\.)+\w+(:\d+)?)/);
501
+ if (m)
502
+ return m[1];
503
+ return "your host";
504
+ }
505
+
506
+ function getApiPath() {
507
+ var m = window.data.rootUrl.match(/^\w+:\/\/(\w+\.)+\w+(:\d+)?/);
508
+ if (m)
509
+ return window.data.rootUrl.substr(m[0].length);
510
+ return window.data.rootUrl;
511
+ }
512
+
513
+ function encodeHtml(data) {
514
+ if (data === undefined || data === null)
515
+ return "";
516
+ var html = typeof data === "string" ? data : data.toString();
517
+ html = html.replace(/&/g, "&amp;");
518
+ html = html.replace(/</g, "&lt;");
519
+ html = html.replace(/>/g, "&gt;");
520
+ html = html.replace(/"/g, "&quot;");
521
+ html = html.replace(/'/g, "&apos;");
522
+ return html;
523
+ }