@@ -9,7 +9,7 @@ const defaultOperationTag = 'Operations'
9
9
const operationHttpMethods = [ 'get' , 'put' , 'post' , 'delete' , 'options' , 'head' , 'patch' , 'trace' ] as const
10
10
11
11
export function getOperationsByTag ( document : Schema [ 'document' ] ) {
12
- const operationsByTag = new Map < string , PathItemOperation [ ] > ( )
12
+ const operationsByTag = new Map < string , { entries : PathItemOperation [ ] ; tag : OperationTag } > ( )
13
13
14
14
for ( const [ pathItemPath , pathItem ] of Object . entries ( document . paths ?? { } ) ) {
15
15
if ( ! isPathItem ( pathItem ) ) {
@@ -32,9 +32,9 @@ export function getOperationsByTag(document: Schema['document']) {
32
32
const operationIdSlug = slug ( operationId )
33
33
34
34
for ( const tag of operation . tags ?? [ defaultOperationTag ] ) {
35
- const operations = operationsByTag . get ( tag ) ?? [ ]
35
+ const operations = operationsByTag . get ( tag ) ?? { entries : [ ] , tag : { name : tag } }
36
36
37
- operations . push ( {
37
+ operations . entries . push ( {
38
38
method,
39
39
operation,
40
40
path : pathItemPath ,
@@ -52,18 +52,18 @@ export function getOperationsByTag(document: Schema['document']) {
52
52
}
53
53
54
54
if ( document . tags ) {
55
- const orderedTags = new Map ( document . tags . map ( ( tag , index ) => [ tag . name , index ] ) )
55
+ const orderedTags = new Map ( document . tags . map ( ( tag , index ) => [ tag . name , { index, tag } ] ) )
56
56
const operationsByTagArray = [ ...operationsByTag . entries ( ) ] . sort ( ( [ tagA ] , [ tagB ] ) => {
57
- const orderA = orderedTags . get ( tagA ) ?? Number . POSITIVE_INFINITY
58
- const orderB = orderedTags . get ( tagB ) ?? Number . POSITIVE_INFINITY
57
+ const orderA = orderedTags . get ( tagA ) ?. index ?? Number . POSITIVE_INFINITY
58
+ const orderB = orderedTags . get ( tagB ) ?. index ?? Number . POSITIVE_INFINITY
59
59
60
60
return orderA - orderB
61
61
} )
62
62
63
63
operationsByTag . clear ( )
64
64
65
65
for ( const [ tag , operations ] of operationsByTagArray ) {
66
- operationsByTag . set ( tag , operations )
66
+ operationsByTag . set ( tag , { ... operations , tag : orderedTags . get ( tag ) ?. tag ?? operations . tag } )
67
67
}
68
68
}
69
69
@@ -110,6 +110,10 @@ export function isPathItemOperation<TMethod extends OperationHttpMethod>(
110
110
return method in pathItem
111
111
}
112
112
113
+ export function isMinimalOperationTag ( tag : OperationTag ) : boolean {
114
+ return ( tag . description === undefined || tag . description . length === 0 ) && tag . externalDocs === undefined
115
+ }
116
+
113
117
export function getOperationURLs ( document : Document , { operation, path, pathItem } : PathItemOperation ) : OperationURL [ ] {
114
118
const urls : OperationURL [ ] = [ ]
115
119
@@ -159,6 +163,7 @@ export interface PathItemOperation {
159
163
160
164
export type Operation = OpenAPI . Operation
161
165
export type OperationHttpMethod = ( typeof operationHttpMethods ) [ number ]
166
+ export type OperationTag = NonNullable < Document [ 'tags' ] > [ number ]
162
167
163
168
interface OperationURL {
164
169
description ?: string | undefined
0 commit comments