@@ -4,45 +4,54 @@ import { fileURLToPath } from 'node:url';
44
55const __filename = fileURLToPath ( import . meta. url ) ;
66const __dirname = path . dirname ( __filename ) ;
7- const ATLAS_ADMIN_API_V2_DOC = 'atlas-admin-api-v2' ;
87
98const SPEC_MAPPING = [
109 {
11- doc : 'atlas-admin-api-v1 ' ,
10+ doc : 'f929d2d7-27d7-4591-b22f-6c2e543a7874 ' ,
1211 file : 'openapi/v1-deprecated/v1.json' ,
1312 branch : 'main' ,
1413 } ,
15- // Need to programmatically handle resource versions separately
16- {
17- doc : ATLAS_ADMIN_API_V2_DOC ,
18- file : 'openapi/v2.json' ,
19- branch : 'latest' ,
20- } ,
2114] ;
2215
2316/**
2417 * Handles the resource versions for Atlas Admin API v2
2518 */
26- function handleResourceVersions ( ) {
19+ function handleAdminAPIv2 ( ) {
20+ const docId = '2accf4b8-a543-426c-94c3-794ae26b68be' ;
2721 const directory = 'openapi/v2' ;
2822 const filePath = path . join ( __dirname , `../../${ directory } /versions.json` ) ;
2923 const versions = JSON . parse ( fs . readFileSync ( filePath , 'utf8' ) ) ;
3024
31- for ( const version of versions ) {
25+ if ( ! versions || ! Array . isArray ( versions ) ) {
26+ return ;
27+ }
28+
29+ for ( const [ index , version ] of versions . entries ( ) ) {
3230 const openapiFilename = `openapi-${ version } .json` ;
3331 const openapiFilePath = path . join ( path . dirname ( filePath ) , openapiFilename ) ;
3432
3533 if ( ! fs . existsSync ( openapiFilePath ) ) {
3634 continue ;
3735 }
3836
37+ const file = `${ directory } /${ openapiFilename } ` ;
3938 SPEC_MAPPING . push ( {
40- doc : ATLAS_ADMIN_API_V2_DOC ,
41- file : ` ${ directory } / ${ openapiFilename } ` ,
39+ doc : docId ,
40+ file,
4241 branch : version ,
4342 } ) ;
43+
44+ // We want the latest version to have its own version AND be the latest/default branch
45+ if ( index === versions . length - 1 ) {
46+ SPEC_MAPPING . push ( {
47+ doc : docId ,
48+ file,
49+ branch : 'latest' ,
50+ } ) ;
51+ }
4452 }
4553}
4654
47- handleResourceVersions ( ) ;
55+ handleAdminAPIv2 ( ) ;
56+ // Output to GH action
4857console . log ( JSON . stringify ( SPEC_MAPPING ) ) ;
0 commit comments