Skip to content

Commit

Permalink
fix: Fixed method sortByRequired
Browse files Browse the repository at this point in the history
  • Loading branch information
yan.nan committed Dec 13, 2019
1 parent 42696a0 commit b08b896
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 @@ -154,12 +154,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 @@ -251,7 +251,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 @@ -280,11 +280,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 b08b896

Please sign in to comment.