@@ -3,6 +3,7 @@ import OpenApiResolver from 'openapi-resolver/dist/openapi-resolver.browser.js';
33import { marked } from 'marked' ;
44import { invalidCharsRegEx } from './common-utils.js' ;
55import cloneDeep from 'lodash.clonedeep' ;
6+ import toposort from 'toposort' ;
67
78export default async function ProcessSpec ( specUrlOrObject , serverUrl = '' ) {
89 const inputSpecIsAUrl = typeof specUrlOrObject === 'string' && specUrlOrObject . match ( / ^ h t t p / ) || typeof specUrlOrObject === 'object' && typeof specUrlOrObject . href === 'string' ;
@@ -146,19 +147,27 @@ function getComponents(openApiSpec) {
146147
147148function groupByTags ( openApiSpec ) {
148149 const supportedMethods = [ 'get' , 'query' , 'put' , 'post' , 'patch' , 'delete' , 'head' , 'options' ] ; // this is also used for ordering endpoints by methods
149- const tags = openApiSpec . tags && Array . isArray ( openApiSpec . tags )
150- ? openApiSpec . tags . map ( ( t ) => {
150+ const rawTags = openApiSpec . tags && Array . isArray ( openApiSpec . tags ) ? openApiSpec . tags : [ ] ;
151+ const unsortedTags = rawTags
152+ // Only support nav tags in grouping, because these tags will be used for navigation.
153+ . filter ( t => ! t . kind || t . kind === 'nav' )
154+ . map ( ( t ) => {
151155 const name = typeof t === 'string' ? t : t . name ;
152156 return {
153157 elementId : `tag--${ name . replace ( invalidCharsRegEx , '-' ) } ` ,
154158 name : name ,
159+ summary : t . summary ,
155160 description : t . description || '' ,
156161 headers : t . description ? getHeadersFromMarkdown ( t . description ) : [ ] ,
157162 paths : [ ] ,
158163 expanded : true
159164 } ;
160- } )
161- : [ ] ;
165+ } ) ;
166+
167+ const tagMap = unsortedTags . reduce ( ( acc , t ) => ( { ...acc , [ t . name ] : t } ) , { } ) ;
168+
169+ const tagDependencies = rawTags . map ( t => t . parent && [ t . parent , t . name ] || [ t . name , 'null' ] ) ;
170+ const tags = toposort ( tagDependencies ) . map ( tagName => tagMap [ tagName ] ) . filter ( t => t ) ;
162171
163172 const pathsAndWebhooks = openApiSpec . paths || { } ;
164173 if ( openApiSpec . webhooks ) {
0 commit comments