]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
fix #4271: api-viewer: display nested formats instead of [object Object]
authorMatthias Heiserer <m.heiserer@proxmox.com>
Wed, 12 Oct 2022 13:23:31 +0000 (15:23 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 16 Nov 2022 19:35:22 +0000 (20:35 +0100)
I tried to keep the format as close to the HTML docs as possible, but
there are a few discrepancies between HTML docs and how this patch
displays parameters, instead of:
- <enum>,the enum variants are displayed. [1]
- <0|1>, <boolean> is displayed.

[1] The HTML docs explain parameters after the initial format string,
which the GUI doesn't (and there's no space for that). Showing the
variants inline is the easiest way to not loose information here.

Signed-off-by: Matthias Heiserer <m.heiserer@proxmox.com>
src/api-viewer/APIViewer.js

index c6580bbb67094f97a9161a171f6050ea66798ff1..2b04b8caf822ecb21e3c75ff2744410a16e57eea 100644 (file)
@@ -79,6 +79,27 @@ Ext.onReady(function() {
        return pdef.enum ? 'enum' : pdef.type || 'string';
     };
 
+    const renderFormatString = function(obj) {
+       if (!Ext.isObject(obj)) {
+           return obj;
+       }
+       const mandatory = [];
+       const optional = [];
+       Object.entries(obj).forEach(function([name, param]) {
+           let list = param.optional ? optional : mandatory;
+           let str = param.default_key ? `[${name}=]` : `${name}=`;
+           if (param.alias) {
+               return;
+           } else if (param.enum) {
+               str += `(${param.enum?.join(' | ')})`;
+           } else {
+               str += `<${param.format_description || param.pattern || param.type}>`;
+           }
+           list.push(str);
+       });
+       return mandatory.join(", ") + ' ' + optional.map(each => `[,${each}]`).join(' ');
+    };
+
     let render_simple_format = function(pdef, type_fallback) {
        if (pdef.typetext) {
            return pdef.typetext;
@@ -87,7 +108,7 @@ Ext.onReady(function() {
            return pdef.enum.join(' | ');
        }
        if (pdef.format) {
-           return pdef.format;
+           return renderFormatString(pdef.format);
        }
        if (pdef.pattern) {
            return pdef.pattern;