@@ -7,9 +7,11 @@ import type { API_URL } from './types/apiTypes';
77
88export default class APICollector {
99 private items : Record < API_URL , OpenAPIV3_1 . PathItemObject > ;
10+ private pathCount : Record < string , number > ;
1011
1112 constructor ( ) {
1213 this . items = { } ;
14+ this . pathCount = { } ;
1315 }
1416
1517 /**
@@ -227,12 +229,24 @@ export default class APICollector {
227229 } ;
228230 }
229231
232+ private increasePathCountByUrl ( url : string ) {
233+ const paths = url . split ( "/" ) . slice ( 1 , 3 ) ;
234+ paths . forEach ( path => {
235+ this . pathCount [ path ] = this . pathCount [ path ] || 0 ;
236+ this . pathCount [ path ] ++ ;
237+ } ) ;
238+ }
239+
230240 private insertNewAPIItem (
231241 url : API_URL ,
232242 method : OpenAPIV3_1 . HttpMethods ,
233243 methodContent : OpenAPIV3_1 . OperationObject ,
234244 statusCode : number
235245 ) : void {
246+ if ( ! this . items [ url ] ) {
247+ this . increasePathCountByUrl ( url ) ;
248+ }
249+
236250 // If the url method doesnt exist
237251 if ( ! this . items [ url ] || ! this . items [ url ] [ method ] ) {
238252 this . items [ url ] = this . items [ url ] || { } ;
@@ -273,8 +287,11 @@ export default class APICollector {
273287 const statusCode = serverResponse . statusCode ;
274288 const url = this . extractURL ( serverResponse ) ;
275289 if ( ! url ) throw new Error ( 'No url found' ) ;
290+
276291 const method = this . extractMethod ( serverResponse ) ;
277- const operationObj : OpenAPIV3_1 . OperationObject = { } ;
292+ const operationObj : OpenAPIV3_1 . OperationObject = {
293+ tags : undefined
294+ } ;
278295 const methodsHasReqBody = [ 'post' , 'put' ] ;
279296
280297 if ( statusCode < 400 ) {
@@ -303,5 +320,9 @@ export default class APICollector {
303320 public getItems ( ) : Record < API_URL , OpenAPIV3_1 . PathItemObject > {
304321 return this . items ;
305322 }
323+
324+ public getCountByPath ( path : string ) : number {
325+ return this . pathCount [ path ] || 0 ;
326+ }
306327}
307328
0 commit comments