@@ -41,6 +41,153 @@ describe('bundle files method - 3.1', function () {
4141 expect ( JSON . stringify ( JSON . parse ( res . output . data [ 0 ] . bundledContent ) , null , 2 ) ) . to . be . equal ( expected ) ;
4242 } ) ;
4343
44+ it ( 'Should bundle and convert OpenAPI 3.1 multifile spec with pathItems (type: json)' , function ( done ) {
45+ let contentRootFile = fs . readFileSync ( pathItem31 + '/root.yaml' , 'utf8' ) ,
46+ user = fs . readFileSync ( pathItem31 + '/path.yaml' , 'utf8' ) ,
47+ input = {
48+ type : 'multiFile' ,
49+ specificationVersion : '3.1' ,
50+ rootFiles : [
51+ {
52+ path : '/root.yaml'
53+ }
54+ ] ,
55+ data : [
56+ {
57+ path : '/root.yaml' ,
58+ content : contentRootFile
59+ } ,
60+ {
61+ path : '/path.yaml' ,
62+ content : user
63+ }
64+ ] ,
65+ options : { } ,
66+ bundleFormat : 'JSON'
67+ } ;
68+
69+ // Step 1: Bundle the spec
70+ Converter . bundle ( input ) . then ( ( bundleRes ) => {
71+ expect ( bundleRes ) . to . not . be . empty ;
72+ expect ( bundleRes . result ) . to . be . true ;
73+ expect ( bundleRes . output . specification . version ) . to . equal ( '3.1' ) ;
74+
75+ const bundledContent = bundleRes . output . data [ 0 ] . bundledContent ;
76+ const bundledSpec = JSON . parse ( bundledContent ) ;
77+
78+ // Step 2: Convert the bundled spec with type 'json'
79+ Converter . convertV2WithTypes (
80+ { type : 'json' , data : bundledSpec } ,
81+ { schemaFaker : true , includeWebhooks : true } ,
82+ ( err , conversionResult ) => {
83+ expect ( err ) . to . be . null ;
84+ expect ( conversionResult . result ) . to . be . true ;
85+ expect ( conversionResult . output . length ) . to . equal ( 1 ) ;
86+ expect ( conversionResult . output [ 0 ] . type ) . to . equal ( 'collection' ) ;
87+
88+ const collection = conversionResult . output [ 0 ] . data ;
89+ expect ( collection ) . to . have . property ( 'info' ) ;
90+ expect ( collection ) . to . have . property ( 'item' ) ;
91+
92+ // Verify that items are not empty (pathItems should be resolved)
93+ expect ( collection . item . length ) . to . be . greaterThan ( 0 ) ;
94+
95+ // Count total requests to ensure pathItems were resolved
96+ let requestCount = 0 ;
97+
98+ /**
99+ * Recursively count requests in collection items
100+ * @param {Array } items - Collection items to count
101+ * @returns {undefined }
102+ */
103+ function countRequests ( items ) {
104+ items . forEach ( ( item ) => {
105+ if ( item . request ) { requestCount ++ ; }
106+ if ( item . item ) { countRequests ( item . item ) ; }
107+ } ) ;
108+ }
109+ countRequests ( collection . item ) ;
110+
111+ expect ( requestCount ) . to . be . greaterThan ( 0 ) ;
112+ done ( ) ;
113+ }
114+ ) ;
115+ } ) . catch ( done ) ;
116+ } ) ;
117+
118+ it ( 'Should bundle and convert OpenAPI 3.1 multifile spec with pathItems (type: string)' , function ( done ) {
119+ let contentRootFile = fs . readFileSync ( pathItem31 + '/root.yaml' , 'utf8' ) ,
120+ user = fs . readFileSync ( pathItem31 + '/path.yaml' , 'utf8' ) ,
121+ input = {
122+ type : 'multiFile' ,
123+ specificationVersion : '3.1' ,
124+ rootFiles : [
125+ {
126+ path : '/root.yaml'
127+ }
128+ ] ,
129+ data : [
130+ {
131+ path : '/root.yaml' ,
132+ content : contentRootFile
133+ } ,
134+ {
135+ path : '/path.yaml' ,
136+ content : user
137+ }
138+ ] ,
139+ options : { } ,
140+ bundleFormat : 'JSON'
141+ } ;
142+
143+ // Step 1: Bundle the spec
144+ Converter . bundle ( input ) . then ( ( bundleRes ) => {
145+ expect ( bundleRes ) . to . not . be . empty ;
146+ expect ( bundleRes . result ) . to . be . true ;
147+ expect ( bundleRes . output . specification . version ) . to . equal ( '3.1' ) ;
148+
149+ const bundledContentString = bundleRes . output . data [ 0 ] . bundledContent ;
150+
151+ // Step 2: Convert the bundled spec with type 'string' (no parsing)
152+ Converter . convertV2WithTypes (
153+ { type : 'string' , data : bundledContentString } ,
154+ { schemaFaker : true , includeWebhooks : true } ,
155+ ( err , conversionResult ) => {
156+ expect ( err ) . to . be . null ;
157+ expect ( conversionResult . result ) . to . be . true ;
158+ expect ( conversionResult . output . length ) . to . equal ( 1 ) ;
159+ expect ( conversionResult . output [ 0 ] . type ) . to . equal ( 'collection' ) ;
160+
161+ const collection = conversionResult . output [ 0 ] . data ;
162+ expect ( collection ) . to . have . property ( 'info' ) ;
163+ expect ( collection ) . to . have . property ( 'item' ) ;
164+
165+ // Verify that items are not empty (pathItems should be resolved)
166+ expect ( collection . item . length ) . to . be . greaterThan ( 0 ) ;
167+
168+ // Count total requests to ensure pathItems were resolved
169+ let requestCount = 0 ;
170+
171+ /**
172+ * Recursively count requests in collection items
173+ * @param {Array } items - Collection items to count
174+ * @returns {undefined }
175+ */
176+ function countRequests ( items ) {
177+ items . forEach ( ( item ) => {
178+ if ( item . request ) { requestCount ++ ; }
179+ if ( item . item ) { countRequests ( item . item ) ; }
180+ } ) ;
181+ }
182+ countRequests ( collection . item ) ;
183+
184+ expect ( requestCount ) . to . be . greaterThan ( 0 ) ;
185+ done ( ) ;
186+ }
187+ ) ;
188+ } ) . catch ( done ) ;
189+ } ) ;
190+
44191 it ( 'Should return bundled file as json - webhook object' , async function ( ) {
45192 let contentRootFile = fs . readFileSync ( webhookItem31 + '/root.yaml' , 'utf8' ) ,
46193 user = fs . readFileSync ( webhookItem31 + '/webhook.yaml' , 'utf8' ) ,
0 commit comments