Skip to content

Commit

Permalink
Sort properties
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian committed May 21, 2024
1 parent f9b86dc commit 6e0a30f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions _layouts/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ <h5>{{@key}}</h5>
<col width="70%" />
</colgroup>
<tbody>
{{#each properties}}
{{#each propertiesSorted}}
<tr>
<td><code>{{#if xml.name}}{{xml.name}}{{else}}{{@key}}{{/if}}</code></td>
<td><code>{{#if xml.name}}{{xml.name}}{{else}}{{key}}{{/if}}</code></td>
<td>
{{type}}{{#if format}} ({{format}}){{/if}}{{#if definition}}{{definition}}{{/if}}{{#if items.definition}}[{{items.definition}}]{{/if}}{{#if pattern}} ({{pattern}}){{/if}}
{{#if required}}<span class="label label-default">required</span>{{/if}}<br/>
Expand Down
31 changes: 29 additions & 2 deletions assets/js/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
});
}
}
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit 6e0a30f

Please sign in to comment.