From 6e0a30f442c19b7a33a40b49a7a8e7bfcb425ad8 Mon Sep 17 00:00:00 2001 From: Fabian Vogler Date: Tue, 21 May 2024 15:26:38 +0200 Subject: [PATCH] Sort properties --- _layouts/api.html | 4 ++-- assets/js/docs.js | 31 +++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/_layouts/api.html b/_layouts/api.html index 4045da7..e82c975 100644 --- a/_layouts/api.html +++ b/_layouts/api.html @@ -130,9 +130,9 @@
{{@key}}
- {{#each properties}} + {{#each propertiesSorted}} - {{#if xml.name}}{{xml.name}}{{else}}{{@key}}{{/if}} + {{#if xml.name}}{{xml.name}}{{else}}{{key}}{{/if}} {{type}}{{#if format}} ({{format}}){{/if}}{{#if definition}}{{definition}}{{/if}}{{#if items.definition}}[{{items.definition}}]{{/if}}{{#if pattern}} ({{pattern}}){{/if}} {{#if required}}required{{/if}}
diff --git a/assets/js/docs.js b/assets/js/docs.js index 2c5601d..4099764 100644 --- a/assets/js/docs.js +++ b/assets/js/docs.js @@ -17,6 +17,8 @@ $(function () { if (typeof definition.properties != 'undefined' && definition.properties) { + definition.propertiesSorted = []; + $.each(definition.properties, function (name, property) { if ($.inArray(name, definition.required) !== -1) { property.required = true; @@ -29,6 +31,29 @@ $(function () { if (typeof property.items != 'undefined' && property.items.$ref != type) { property.items.definition = buildDefinitions(property.items.$ref, all, definitions); } + + property.key = name; + definition.propertiesSorted.push(property); + }); + + // sort properties by position attribute + definition.propertiesSorted.sort(function (a, b) { + if (a.position === b.position) { + return 0; + } + if (a.position === null) { + return 1; + } + if (b.position === null) { + return -1; + } + if (a.position < b.position) { + return -1; + } + if (a.position > b.position) { + return 1; + } + return 0; }); } } @@ -64,9 +89,11 @@ $(function () { if ('#/definitions/' + name == type) { - if (typeof definition.properties != 'undefined' && definition.properties) { + if (typeof definition.propertiesSorted != 'undefined' && definition.propertiesSorted) { - $.each(definition.properties, function (name, property) { + $.each(definition.propertiesSorted, function (index, property) { + + var name = property.key; if (optional || $.inArray(name, definition.required) !== -1) { if (typeof property.xml != 'undefined' && property.xml && typeof property.xml.name != 'undefined') {