diff --git a/src/services/AppStore.ts b/src/services/AppStore.ts index 9387c521..bc4fc4f4 100644 --- a/src/services/AppStore.ts +++ b/src/services/AppStore.ts @@ -81,7 +81,7 @@ export class AppStore { MenuStore.updateOnHistory(history.currentId, this.scroll); this.spec = new SpecStore(spec, specUrl, this.options); - this.menu = new MenuStore(this.spec, this.scroll, history); + this.menu = new MenuStore(this.spec, this.scroll, history, this.options); if (!this.options.disableSearch) { this.search = new SearchStore(); diff --git a/src/services/MenuStore.ts b/src/services/MenuStore.ts index 2a619af6..4aed7d50 100644 --- a/src/services/MenuStore.ts +++ b/src/services/MenuStore.ts @@ -8,9 +8,12 @@ import { ScrollService } from './ScrollService'; import { flattenByProp, SECURITY_SCHEMES_SECTION_PREFIX } from '../utils'; import { GROUP_DEPTH } from './MenuBuilder'; +import {RedocNormalizedOptions} from "./RedocNormalizedOptions"; + export type MenuItemGroupType = 'group' | 'tag' | 'section'; export type MenuItemType = MenuItemGroupType | 'operation'; + /** Generic interface for MenuItems */ export interface IMenuItem { id: string; @@ -74,11 +77,21 @@ export class MenuStore { * * @param spec [SpecStore](#SpecStore) which contains page content structure * @param scroll scroll service instance used by this menu + * @param history + * @param options */ - constructor(spec: SpecStore, public scroll: ScrollService, public history: HistoryService) { + constructor(spec: SpecStore, public scroll: ScrollService, public history: HistoryService, public options: RedocNormalizedOptions) { this.items = spec.contentItems; - this.flatItems = flattenByProp(this.items || [], 'items'); + if (this.options.sortNavigationTags) { + this.flatItems.map((item) => { + if (item.type === "tag") { + item.items.sort((a, b) => (a.name > b.name) ? 1 : -1) + } + }); + this.flatItems = flattenByProp(this.items || [], 'items'); + } + this.flatItems.forEach((item, idx) => (item.absoluteIdx = idx)); this.subscribe(); diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index 75f3e9b4..26963459 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -11,6 +11,7 @@ export interface RedocRawOptions { hideHostname?: boolean | string; expandResponses?: string | 'all'; requiredPropsFirst?: boolean | string; + sortNavigationTags?: boolean | string; sortPropsAlphabetically?: boolean | string; sortEnumValuesAlphabetically?: boolean | string; noAutoAuth?: boolean | string; @@ -165,6 +166,7 @@ export class RedocNormalizedOptions { hideHostname: boolean; expandResponses: { [code: string]: boolean } | 'all'; requiredPropsFirst: boolean; + sortNavigationTags: boolean; sortPropsAlphabetically: boolean; sortEnumValuesAlphabetically: boolean; noAutoAuth: boolean; @@ -220,6 +222,7 @@ export class RedocNormalizedOptions { this.requiredPropsFirst = argValueToBoolean(raw.requiredPropsFirst); this.sortPropsAlphabetically = argValueToBoolean(raw.sortPropsAlphabetically); this.sortEnumValuesAlphabetically = argValueToBoolean(raw.sortEnumValuesAlphabetically); + this.sortNavigationTags = argValueToBoolean(raw.sortNavigationTags); this.noAutoAuth = argValueToBoolean(raw.noAutoAuth); this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars); this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);