11'use strict' ; 
22
3- const  { writeMainOpenAPISpec,  writePaths,  writeComponents,  sanitizeFileName}  =  require ( './../utils/split' ) ; 
4- const  of  =  require ( './../openapi-format' ) ; 
3+ const  { writeFile}  =  require ( './../utils/file' ) ; 
4+ const  { 
5+   writeSplitOpenAPISpec, 
6+   writePaths, 
7+   writeComponents, 
8+   sanitizeFileName, 
9+   convertComponentsToRef
10+ }  =  require ( './../utils/split' ) ; 
511const  { describe,  it,  expect}  =  require ( '@jest/globals' ) ; 
612const  path  =  require ( 'path' ) ; 
7- const  { writeFile}  =  require ( './../utils/file' ) ; 
8- const  { convertComponentsToRef}  =  require ( '../utils/split' ) ; 
13+ const  fs  =  require ( 'node:fs' ) ; 
914
1015jest . mock ( './../utils/file' ,  ( )  =>  ( { 
1116  writeFile : jest . fn ( ) 
1217} ) ) ; 
1318
19+ jest . mock ( 'node:fs' ,  ( )  =>  ( { 
20+   mkdirSync : jest . fn ( ) 
21+ } ) ) ; 
22+ 
1423describe ( 'openapi-format CLI splits tests' ,  ( )  =>  { 
1524  const  options  =  { 
1625    outputDir : '/fake/output/dir' , 
17-     someOtherOption : true 
26+     format : 'yaml' , 
27+     output : 'openapi.yaml' 
1828  } ; 
1929
2030  const  openapiDoc  =  { 
@@ -40,7 +50,7 @@ describe('openapi-format CLI splits tests', () => {
4050  } ) ; 
4151
4252  it ( 'should split and write main openapi spec with $refs' ,  async  ( )  =>  { 
43-     await  writeMainOpenAPISpec ( openapiDoc ,  options ) ; 
53+     await  writeSplitOpenAPISpec ( openapiDoc ,  options ) ; 
4454
4555    // Assert that the main openapi.yaml file is written with $refs 
4656    expect ( writeFile ) . toHaveBeenCalledWith ( 
@@ -71,7 +81,7 @@ describe('openapi-format CLI splits tests', () => {
7181    // Assert that each path is written to its own file 
7282    expect ( writeFile ) . toHaveBeenCalledWith ( 
7383      path . join ( options . outputDir ,  'paths' ,  'example_foo_{id}.yaml' ) , 
74-       { '/example/foo/{id}' :  paths [ '/example/foo/{id}' ] } , 
84+       paths [ '/example/foo/{id}' ] , 
7585      options 
7686    ) ; 
7787  } ) ; 
@@ -84,7 +94,7 @@ describe('openapi-format CLI splits tests', () => {
8494    // Assert that each component is written to its own file 
8595    expect ( writeFile ) . toHaveBeenCalledWith ( 
8696      path . join ( options . outputDir ,  'components/schemas' ,  'ExampleSchema.yaml' ) , 
87-       { ExampleSchema :  components . schemas . ExampleSchema } , 
97+       components . schemas . ExampleSchema , 
8898      options 
8999    ) ; 
90100  } ) ; 
@@ -111,10 +121,8 @@ describe('openapi-format CLI splits tests', () => {
111121      } 
112122    } ; 
113123
114-     const  ext  =  'yaml' ; 
115- 
116124    // Call convertComponentsToRef without mocking traverse 
117-     const  result  =  convertComponentsToRef ( components ,  ext ) ; 
125+     const  result  =  convertComponentsToRef ( components ,  'yaml' ,   '.' ) ; 
118126
119127    // Assert that the $ref is converted correctly 
120128    expect ( result . schemas . ExampleSchema . properties . related . $ref ) . toBe ( 'components/schemas/RelatedSchema.yaml' ) ; 
@@ -142,10 +150,8 @@ describe('openapi-format CLI splits tests', () => {
142150      } 
143151    } ; 
144152
145-     const  ext  =  'yaml' ; 
146- 
147153    // Call convertComponentsToRef to check nested $ref conversion 
148-     const  result  =  convertComponentsToRef ( components ,  ext ) ; 
154+     const  result  =  convertComponentsToRef ( components ,  'yaml' ,   '.' ) ; 
149155
150156    // Assert that the deeply nested $ref is converted 
151157    expect ( result . schemas . NestedSchema . properties . nested . properties . deep . $ref ) . toBe ( 
0 commit comments