postmanlabs / openapi-to-postman

Plugin for converting OpenAPI 3.0 specs to the Postman Collection (v2) format
Apache License 2.0
928 stars 200 forks source link

Fixed issue where collection generation took very large time. #735

Closed VShingala closed 1 year ago

VShingala commented 1 year ago

Overview

This PR fixes issue where certain definition were taking very large amount of time to generate collection. Specifically this was happening when parametersResolution option is set to Schema. When set to Schema conversion was taking >4 mins or so, meanwhile using example only took ~4 sec to convert.

RCA

Upon further debugging, I found out that all time taken was by json-schema-faker library. And also, that too when corresponding schema that was being faked contained uniqueItems: true constraint.

When uniqueItems set to true, json-schema-faker library goes through faked data and tries to compare all items in array and only adds unique items to array. And in cases of very large and complex arrays, this process of comparison takes large amount of times especially when Schema as value to the option parametersResolution is used because essentially all items in array would be same and this comparison has to go through all data in the array.

As for Example value this process doesn't take long because at very starting of any array, some value will be unique due to random faked data. So process doesn't go through all elements of item.

Fix

We'll be not going through the process of determining all items to be unique in case when parametersResolution is set to Schema.