feat: new option sortEnumValuesAlphabetically (#1321)

This commit is contained in:
Roman Hotsiy 2020-07-21 16:10:48 +03:00 committed by GitHub
parent 4db5bc470b
commit a96a11a4dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -12,6 +12,7 @@ export interface RedocRawOptions {
expandResponses?: string | 'all';
requiredPropsFirst?: boolean | string;
sortPropsAlphabetically?: boolean | string;
sortEnumValuesAlphabetically?: boolean | string;
noAutoAuth?: boolean | string;
nativeScrollbars?: boolean | string;
pathInMiddlePanel?: boolean | string;
@ -154,6 +155,7 @@ export class RedocNormalizedOptions {
expandResponses: { [code: string]: boolean } | 'all';
requiredPropsFirst: boolean;
sortPropsAlphabetically: boolean;
sortEnumValuesAlphabetically: boolean;
noAutoAuth: boolean;
nativeScrollbars: boolean;
pathInMiddlePanel: boolean;
@ -205,6 +207,7 @@ export class RedocNormalizedOptions {
this.expandResponses = RedocNormalizedOptions.normalizeExpandResponses(raw.expandResponses);
this.requiredPropsFirst = argValueToBoolean(raw.requiredPropsFirst);
this.sortPropsAlphabetically = argValueToBoolean(raw.sortPropsAlphabetically);
this.sortEnumValuesAlphabetically = argValueToBoolean(raw.sortEnumValuesAlphabetically);
this.noAutoAuth = argValueToBoolean(raw.noAutoAuth);
this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars);
this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);

View File

@ -168,6 +168,10 @@ export class SchemaModel {
this.enum = this.items.enum;
}
}
if (this.enum.length && this.options.sortEnumValuesAlphabetically) {
this.enum.sort();
}
}
private initOneOf(oneOf: OpenAPISchema[], parser: OpenAPIParser) {