@@ -8,41 +8,44 @@ type BuildTagCategoriesOptions = {
88 expandAllTags ?: boolean ;
99} ;
1010
11+ // Merges tags and x-tagGroups with the same name into a single sidebar
12+ // category (mimics OpenAPI 3.2.0 "Enhanced tags" behaviour).
1113export const buildTagCategories = ( {
1214 tagCategories,
1315 tagGroups,
1416 expandAllTags,
1517} : BuildTagCategoriesOptions ) : NavigationItem [ ] => {
1618 const consumedTags = new Set < string > ( ) ;
1719
18- const groupedCategories : NavigationItem [ ] = tagGroups . flatMap ( ( group ) => {
20+ const groupedCategories = tagGroups . flatMap < NavigationItem > ( ( group ) => {
21+ // Use a same-named tag as base so its operations appear first
1922 const matchingTag = tagCategories . get ( group . name ) ;
2023 const base = matchingTag ?. type === "category" ? matchingTag : undefined ;
2124
2225 if ( base ) consumedTags . add ( group . name ) ;
2326
24- const childTags = group . tags
25- . filter ( ( name ) => name !== group . name && tagCategories . has ( name ) )
26- . flatMap ( ( name ) => {
27- consumedTags . add ( name ) ;
28- const tag = tagCategories . get ( name ) ;
29- return tag ? [ tag ] : [ ] ;
30- } ) ;
27+ // Exclude group's own name to avoid nesting a tag inside itself
28+ const childTags = group . tags . flatMap ( ( name ) => {
29+ if ( name === group . name ) return [ ] ;
30+ const tag = tagCategories . get ( name ) ;
31+ if ( ! tag ) return [ ] ;
32+ consumedTags . add ( name ) ;
33+ return tag ;
34+ } ) ;
3135
3236 if ( ! base && childTags . length === 0 ) return [ ] ;
3337
34- return [
35- {
36- ...base ,
37- type : "category" as const ,
38- label : base ?. label ?? group . name ,
39- items : [ ...( base ?. items ?? [ ] ) , ...childTags ] ,
40- collapsible : base ?. collapsible ?? true ,
41- collapsed : base ?. collapsed ?? ! expandAllTags ,
42- } ,
43- ] ;
38+ return {
39+ ...base ,
40+ type : "category" ,
41+ label : base ?. label ?? group . name ,
42+ items : [ ...( base ?. items ?? [ ] ) , ...childTags ] ,
43+ collapsible : base ?. collapsible ?? true ,
44+ collapsed : base ?. collapsed ?? ! expandAllTags ,
45+ } ;
4446 } ) ;
4547
48+ // Tags not claimed by any group appear as standalone entries
4649 const ungroupedCategories = Array . from ( tagCategories . entries ( ) )
4750 . filter ( ( [ name ] ) => ! consumedTags . has ( name ) )
4851 . map ( ( [ , cat ] ) => cat ) ;
0 commit comments