diff --git a/packages/fdr-sdk/src/navigation/converters/ApiReferenceNavigationConverter.ts b/packages/fdr-sdk/src/navigation/converters/ApiReferenceNavigationConverter.ts index 10b21cc6f9..9055c4cdc8 100644 --- a/packages/fdr-sdk/src/navigation/converters/ApiReferenceNavigationConverter.ts +++ b/packages/fdr-sdk/src/navigation/converters/ApiReferenceNavigationConverter.ts @@ -18,6 +18,7 @@ export class ApiReferenceNavigationConverter { baseSlug: string, parentSlug: string, idgen?: NodeIdGenerator, + lexicographic?: boolean, ) { return new ApiReferenceNavigationConverter( apiSection, @@ -25,6 +26,7 @@ export class ApiReferenceNavigationConverter { baseSlug, parentSlug, idgen ?? new NodeIdGenerator(), + lexicographic, ).convert(); } @@ -41,6 +43,7 @@ export class ApiReferenceNavigationConverter { private baseSlug: string, private apiDefinitionParentSlug: string, idgen: NodeIdGenerator, + private lexicographic: boolean = false, ) { this.apiDefinitionId = FernNavigation.ApiDefinitionId(api.id); this.#holder = ApiDefinitionHolder.create(api); @@ -229,7 +232,17 @@ export class ApiReferenceNavigationConverter { this.#visitedSubpackages.add(subpackageId); - return this.mergeEndpointPairs(children); + const toRet = this.mergeEndpointPairs(children); + + if (this.lexicographic) { + toRet.sort((a, b) => { + const aTitle = a.type === "endpointPair" ? a.nonStream.title : a.title; + const bTitle = b.type === "endpointPair" ? b.nonStream.title : b.title; + return aTitle.localeCompare(bTitle); + }); + } + + return toRet; } private convertApiNavigationItems( diff --git a/packages/fdr-sdk/src/navigation/converters/NavigationConfigConverter.ts b/packages/fdr-sdk/src/navigation/converters/NavigationConfigConverter.ts index 39bcce046d..0c7f83db28 100644 --- a/packages/fdr-sdk/src/navigation/converters/NavigationConfigConverter.ts +++ b/packages/fdr-sdk/src/navigation/converters/NavigationConfigConverter.ts @@ -14,14 +14,16 @@ export class NavigationConfigConverter { private config: DocsV1Read.NavigationConfig, private apis: Record, private basePath: string | undefined, + private lexicographic?: boolean, ) {} public static convert( config: DocsV1Read.NavigationConfig, apis: Record, basePath: string | undefined, + lexicographic?: boolean, ): FernNavigation.RootNode { - return new NavigationConfigConverter(config, apis, basePath).convert(); + return new NavigationConfigConverter(config, apis, basePath, lexicographic).convert(); } #idgen = new NodeIdGenerator(); @@ -250,7 +252,14 @@ export class NavigationConfigConverter { if (api == null) { throw new Error(`API ${apiSection.api} not found}`); } - return ApiReferenceNavigationConverter.convert(apiSection, api, baseSlug, parentSlug, this.#idgen); + return ApiReferenceNavigationConverter.convert( + apiSection, + api, + baseSlug, + parentSlug, + this.#idgen, + this.lexicographic, + ); }, changelog: (changelog) => ChangelogNavigationConverter.convert(changelog, baseSlug, parentSlug, this.#idgen), diff --git a/packages/fdr-sdk/src/navigation/utils/convertLoadDocsForUrlResponse.ts b/packages/fdr-sdk/src/navigation/utils/convertLoadDocsForUrlResponse.ts index 10bcca8baa..f4a6209b0f 100644 --- a/packages/fdr-sdk/src/navigation/utils/convertLoadDocsForUrlResponse.ts +++ b/packages/fdr-sdk/src/navigation/utils/convertLoadDocsForUrlResponse.ts @@ -7,9 +7,16 @@ export function convertLoadDocsForUrlResponse(response: DocsV2Read.LoadDocsForUr response.definition.config.navigation, hackReorderApis(response.definition.apis, response.baseUrl.domain), response.baseUrl.basePath, + isLexicographicSortEnabled(response.baseUrl.domain), ); } +function isLexicographicSortEnabled(domain: string): boolean { + // HACKHACK: This is a temporary solution to enable lexicographic sorting for AIA docs. + // Vercel's edge config UI is broken right now so we can't modify it there. + return domain.toLowerCase().includes("aia.docs.buildwithfern.com"); +} + function hackReorderApis( apis: Record, domain: string,