operations: Add support for sortOperationsAlphabetically

Already documented but is currently `NO-OP` and not implemented
`sortOperationsAlphabetically`.

Allows sorting operations in sidebar menu according to their `name`
configured which is by default `summary` from Swaggerspec

TLDR:
Following commit adds support for `sortOperationsAlphabetically` already
documented but not implemented here: https://redoc.ly/docs/api-reference-docs/guides/migration-guide-2-0/#automated-sorting

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
This commit is contained in:
Aditya Rajan 2021-12-27 12:38:19 +05:30
parent 6c41e95aa0
commit a7b75f320f
No known key found for this signature in database
GPG Key ID: 8E5A8A19DF7C8673
2 changed files with 6 additions and 0 deletions

View File

@ -209,6 +209,9 @@ export class MenuBuilder {
operation.depth = depth;
res.push(operation);
}
if (options.sortOperationsAlphabetically) {
res.sort((a, b) => a.name.localeCompare(b.name));
}
return res;
}

View File

@ -18,6 +18,7 @@ export interface RedocRawOptions {
requiredPropsFirst?: boolean | string;
sortPropsAlphabetically?: boolean | string;
sortEnumValuesAlphabetically?: boolean | string;
sortOperationsAlphabetically?: boolean | string;
noAutoAuth?: boolean | string;
nativeScrollbars?: boolean | string;
pathInMiddlePanel?: boolean | string;
@ -203,6 +204,7 @@ export class RedocNormalizedOptions {
requiredPropsFirst: boolean;
sortPropsAlphabetically: boolean;
sortEnumValuesAlphabetically: boolean;
sortOperationsAlphabetically: boolean;
noAutoAuth: boolean;
nativeScrollbars: boolean;
pathInMiddlePanel: boolean;
@ -262,6 +264,7 @@ export class RedocNormalizedOptions {
this.requiredPropsFirst = argValueToBoolean(raw.requiredPropsFirst);
this.sortPropsAlphabetically = argValueToBoolean(raw.sortPropsAlphabetically);
this.sortEnumValuesAlphabetically = argValueToBoolean(raw.sortEnumValuesAlphabetically);
this.sortOperationsAlphabetically = argValueToBoolean(raw.sortOperationsAlphabetically);
this.noAutoAuth = argValueToBoolean(raw.noAutoAuth);
this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars);
this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);