Skip to content

Commit

Permalink
fix: fix sortByRequired (stabilise sort) (#1136)
Browse files Browse the repository at this point in the history
fixes #1104
fixes #1121
fixes #1061
  • Loading branch information
yannan authored and RomanHotsiy committed Dec 13, 2019
1 parent 1bf490c commit d92434d
Show file tree
Hide file tree
Showing 4 changed files with 391 additions and 20 deletions.
5 changes: 2 additions & 3 deletions src/services/models/Operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,11 @@ export class OperationModel implements IMenuItem {
).map(paramOrRef => new FieldModel(this.parser, paramOrRef, this.pointer, this.options));

if (this.options.sortPropsAlphabetically) {
sortByField(_parameters, 'name');
return sortByField(_parameters, 'name');
}
if (this.options.requiredPropsFirst) {
sortByRequired(_parameters);
return sortByRequired(_parameters);
}
return _parameters;
}

@memoize
Expand Down
6 changes: 3 additions & 3 deletions src/services/models/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function buildFields(
const props = schema.properties || {};
const additionalProps = schema.additionalProperties;
const defaults = schema.default || {};
const fields = Object.keys(props || []).map(fieldName => {
let fields = Object.keys(props || []).map(fieldName => {
let field = props[fieldName];

if (!field) {
Expand Down Expand Up @@ -304,11 +304,11 @@ function buildFields(
});

if (options.sortPropsAlphabetically) {
sortByField(fields, 'name');
fields = sortByField(fields, 'name');
}
if (options.requiredPropsFirst) {
// if not sort alphabetically sort in the order from required keyword
sortByRequired(fields, !options.sortPropsAlphabetically ? schema.required : undefined);
fields = sortByRequired(fields, !options.sortPropsAlphabetically ? schema.required : undefined);
}

if (typeof additionalProps === 'object' || additionalProps === true) {
Expand Down
Loading

0 comments on commit d92434d

Please sign in to comment.