@@ -237,90 +237,99 @@ class SchemaPack {
237237 return callback ( new OpenApiErr ( 'The schema must be validated before attempting conversion' ) ) ;
238238 }
239239
240- // this cannot be attempted before validation
241- componentsAndPaths = {
242- components : this . openapi . components ,
243- paths : this . openapi . paths
244- } ;
240+ parse . resolveRemoteRefs ( this . openapi , options , ( err ) => {
241+ if ( err ) {
242+ return callback ( null , {
243+ result : false ,
244+ reason : err . name + ': ' + err . message
245+ } ) ;
246+ }
245247
246- // create and sanitize basic spec
247- openapi = this . openapi ;
248- openapi . servers = _ . isEmpty ( openapi . servers ) ? [ { url : '/' } ] : openapi . servers ;
249- openapi . securityDefs = _ . get ( openapi , 'components.securitySchemes' , { } ) ;
250- openapi . baseUrl = _ . get ( openapi , 'servers.0.url' , '{{baseURL}}' ) ;
248+ // this cannot be attempted before validation
249+ componentsAndPaths = {
250+ components : this . openapi . components ,
251+ paths : this . openapi . paths
252+ } ;
251253
252- // TODO: Multiple server variables need to be saved as environments
253- openapi . baseUrlVariables = _ . get ( openapi , 'servers.0.variables' ) ;
254+ // create and sanitize basic spec
255+ openapi = this . openapi ;
256+ openapi . servers = _ . isEmpty ( openapi . servers ) ? [ { url : '/' } ] : openapi . servers ;
257+ openapi . securityDefs = _ . get ( openapi , 'components.securitySchemes' , { } ) ;
258+ openapi . baseUrl = _ . get ( openapi , 'servers.0.url' , '{{baseURL}}' ) ;
254259
255- // Fix {scheme} and {path} vars in the URL to :scheme and :path
256- openapi . baseUrl = schemaUtils . fixPathVariablesInUrl ( openapi . baseUrl ) ;
260+ // TODO: Multiple server variables need to be saved as environments
261+ openapi . baseUrlVariables = _ . get ( openapi , 'servers.0.variables' ) ;
257262
258- // Creating a new instance of a Postman collection
259- // All generated folders and requests will go inside this
260- generatedStore . collection = new sdk . Collection ( {
261- info : {
262- name : _ . get ( openapi , 'info.title' , COLLECTION_NAME )
263- }
264- } ) ;
263+ // Fix {scheme} and {path} vars in the URL to :scheme and :path
264+ openapi . baseUrl = schemaUtils . fixPathVariablesInUrl ( openapi . baseUrl ) ;
265+
266+ // Creating a new instance of a Postman collection
267+ // All generated folders and requests will go inside this
268+ generatedStore . collection = new sdk . Collection ( {
269+ info : {
270+ name : _ . get ( openapi , 'info.title' , COLLECTION_NAME )
271+ }
272+ } ) ;
265273
266- if ( openapi . security ) {
267- authHelper = schemaUtils . getAuthHelper ( openapi , openapi . security ) ;
268- if ( authHelper ) {
269- generatedStore . collection . auth = authHelper ;
274+ if ( openapi . security ) {
275+ authHelper = schemaUtils . getAuthHelper ( openapi , openapi . security ) ;
276+ if ( authHelper ) {
277+ generatedStore . collection . auth = authHelper ;
278+ }
270279 }
271- }
272- // ---- Collection Variables ----
273- // adding the collection variables for all the necessary root level variables
274- // and adding them to the collection variables
275- schemaUtils . convertToPmCollectionVariables (
276- openapi . baseUrlVariables ,
277- 'baseUrl' ,
278- openapi . baseUrl
279- ) . forEach ( ( element ) => {
280- generatedStore . collection . variables . add ( element ) ;
281- } ) ;
280+ // ---- Collection Variables ----
281+ // adding the collection variables for all the necessary root level variables
282+ // and adding them to the collection variables
283+ schemaUtils . convertToPmCollectionVariables (
284+ openapi . baseUrlVariables ,
285+ 'baseUrl' ,
286+ openapi . baseUrl
287+ ) . forEach ( ( element ) => {
288+ generatedStore . collection . variables . add ( element ) ;
289+ } ) ;
282290
283- generatedStore . collection . describe ( schemaUtils . getCollectionDescription ( openapi ) ) ;
291+ generatedStore . collection . describe ( schemaUtils . getCollectionDescription ( openapi ) ) ;
284292
285- // Only change the stack limit if the optimizeConversion option is true
286- if ( options . optimizeConversion ) {
287- // Deciding stack limit based on size of the schema, number of refs and number of paths.
288- analysis = schemaUtils . analyzeSpec ( openapi ) ;
293+ // Only change the stack limit if the optimizeConversion option is true
294+ if ( options . optimizeConversion ) {
295+ // Deciding stack limit based on size of the schema, number of refs and number of paths.
296+ analysis = schemaUtils . analyzeSpec ( openapi ) ;
289297
290- // Update options on the basis of analysis.
291- options = schemaUtils . determineOptions ( analysis , options ) ;
292- }
298+ // Update options on the basis of analysis.
299+ options = schemaUtils . determineOptions ( analysis , options ) ;
300+ }
293301
294302
295- // ---- Collection Items ----
296- // Adding the collection items from openapi spec based on folderStrategy option
297- // For tags, All operations are grouped based on respective tags object
298- // For paths, All operations are grouped based on corresponding paths
299- try {
300- if ( options . folderStrategy === 'tags' ) {
301- schemaUtils . addCollectionItemsUsingTags ( openapi , generatedStore , componentsAndPaths , options , schemaCache ) ;
303+ // ---- Collection Items ----
304+ // Adding the collection items from openapi spec based on folderStrategy option
305+ // For tags, All operations are grouped based on respective tags object
306+ // For paths, All operations are grouped based on corresponding paths
307+ try {
308+ if ( options . folderStrategy === 'tags' ) {
309+ schemaUtils . addCollectionItemsUsingTags ( openapi , generatedStore , componentsAndPaths , options , schemaCache ) ;
310+ }
311+ else {
312+ schemaUtils . addCollectionItemsUsingPaths ( openapi , generatedStore , componentsAndPaths , options , schemaCache ) ;
313+ }
302314 }
303- else {
304- schemaUtils . addCollectionItemsUsingPaths ( openapi , generatedStore , componentsAndPaths , options , schemaCache ) ;
315+ catch ( e ) {
316+ return callback ( e ) ;
305317 }
306- }
307- catch ( e ) {
308- return callback ( e ) ;
309- }
310318
311- collectionJSON = generatedStore . collection . toJSON ( ) ;
319+ collectionJSON = generatedStore . collection . toJSON ( ) ;
312320
313- // this needs to be deleted as even if version is not specified to sdk,
314- // it returns a version property with value set as undefined
315- // this fails validation against v2.1 collection schema definition.
316- delete collectionJSON . info . version ;
321+ // this needs to be deleted as even if version is not specified to sdk,
322+ // it returns a version property with value set as undefined
323+ // this fails validation against v2.1 collection schema definition.
324+ delete collectionJSON . info . version ;
317325
318- return callback ( null , {
319- result : true ,
320- output : [ {
321- type : 'collection' ,
322- data : collectionJSON
323- } ]
326+ return callback ( null , {
327+ result : true ,
328+ output : [ {
329+ type : 'collection' ,
330+ data : collectionJSON
331+ } ]
332+ } ) ;
324333 } ) ;
325334 }
326335
0 commit comments