]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
api-viewer: implement basic oneOf support
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 16 Nov 2023 15:21:52 +0000 (16:21 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 17 Nov 2023 08:58:17 +0000 (09:58 +0100)
for parameters only for now, also only implement the basic use case we
want to have currently: use in section config apis where we have more
than one type.

we could improve upon that, e.g. by properly grouping the type relevant
options, and also implementing that for return types.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/api-viewer/APIViewer.js

index d9753b2f41ef9c314929e1bcc0bec7de67eea574..26a1c0882c12935170d6edbb2953f9387f447281 100644 (file)
@@ -7,7 +7,7 @@ Ext.onReady(function() {
            'name', 'type', 'typetext', 'description', 'verbose_description',
            'enum', 'minimum', 'maximum', 'minLength', 'maxLength',
            'pattern', 'title', 'requires', 'format', 'default',
-           'disallow', 'extends', 'links',
+           'disallow', 'extends', 'links', 'instance-types',
            {
                name: 'optional',
                type: 'boolean',
@@ -214,6 +214,10 @@ Ext.onReady(function() {
                        },
                        groupField: 'optional',
                        sorters: [
+                           {
+                               property: 'instance-types',
+                               direction: 'ASC',
+                           },
                            {
                                property: 'name',
                                direction: 'ASC',
@@ -221,9 +225,27 @@ Ext.onReady(function() {
                        ],
                    });
 
+                   let has_type_properties = false;
+
                    Ext.Object.each(info.parameters.properties, function(name, pdef) {
-                       pdef.name = name;
-                       pstore.add(pdef);
+                       if (pdef.oneOf) {
+                           pdef.oneOf.forEach((alternative) => {
+                               alternative.name = name;
+                               pstore.add(alternative);
+                               has_type_properties = true;
+                           });
+                       } else if (pdef['instance-types']) {
+                           pdef['instance-types'].forEach((type) => {
+                               let typePdef = Ext.apply({}, pdef);
+                               typePdef.name = name;
+                               typePdef['instance-types'] = [type];
+                               pstore.add(typePdef);
+                               has_type_properties = true;
+                           });
+                       } else {
+                           pdef.name = name;
+                           pstore.add(pdef);
+                       }
                    });
 
                    pstore.sort();
@@ -255,6 +277,12 @@ Ext.onReady(function() {
                                renderer: render_type,
                                flex: 1,
                            },
+                           {
+                               header: 'For Types',
+                               dataIndex: 'instance-types',
+                               hidden: !has_type_properties,
+                               flex: 1,
+                           },
                            {
                                header: 'Default',
                                dataIndex: 'default',