From 37ff72720b256f31b36a3dfd4010ab7d7ffe9a92 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Mon, 10 May 2021 11:28:00 +0200 Subject: [PATCH] docs/api-viewer: improve rendering of array format by showing '[format, ...]' where 'format' is the simple format from the type of the items Signed-off-by: Dominik Csapak Signed-off-by: Thomas Lamprecht --- docs/api-viewer/PBSAPI.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/api-viewer/PBSAPI.js b/docs/api-viewer/PBSAPI.js index 2417b4de..d56f5e55 100644 --- a/docs/api-viewer/PBSAPI.js +++ b/docs/api-viewer/PBSAPI.js @@ -86,13 +86,9 @@ Ext.onReady(function() { return pdef['enum'] ? 'enum' : (pdef.type || 'string'); }; - var render_format = function(value, metaData, record) { - var pdef = record.data; - - metaData.style = 'white-space:normal;' - + let render_simple_format = function(pdef, type_fallback) { if (pdef.typetext) - return Ext.htmlEncode(pdef.typetext); + return pdef.typetext; if (pdef['enum']) return pdef['enum'].join(' | '); @@ -101,9 +97,28 @@ Ext.onReady(function() { return pdef.format; if (pdef.pattern) - return Ext.htmlEncode(pdef.pattern); + return pdef.pattern; - return ''; + if (pdef.type === 'boolean') + return ``; + + if (type_fallback && pdef.type) + return `<${pdef.type}>`; + + return; + }; + + let render_format = function(value, metaData, record) { + let pdef = record.data; + + metaData.style = 'white-space:normal;' + + if (pdef.type === 'array' && pdef.items) { + let format = render_simple_format(pdef.items, true); + return `[${Ext.htmlEncode(format)}, ...]`; + } + + return Ext.htmlEncode(render_simple_format(pdef) || ''); }; var real_path = function(path) {