From a7b75f320f8b450e1e56eb3de6a337d3cb9654f2 Mon Sep 17 00:00:00 2001 From: Aditya Rajan Date: Mon, 27 Dec 2021 12:38:19 +0530 Subject: [PATCH] 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 --- src/services/MenuBuilder.ts | 3 +++ src/services/RedocNormalizedOptions.ts | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/services/MenuBuilder.ts b/src/services/MenuBuilder.ts index 0021d361..ded2eed4 100644 --- a/src/services/MenuBuilder.ts +++ b/src/services/MenuBuilder.ts @@ -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; } diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index f1640b92..73e77de4 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -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);