insomnia: [Bug] Maximum call stack size exceeded

Details

When running the code below with a file specification.yml which is a swagger 2.0 documentation I retrieve the error below. The original file size was ~110kb but I also reduced the size to around ~15kb but it still didn’t work. Someone else encountered this problem also but he didn’t create an issue, the comment can be found here.

const fs = require("fs");
const importers = require("insomnia-importers");

fs.readFile("specification.yml", async (err, data) => {
  if (err) throw err;

  try {
    const output = await importers.convert(data.toString());
    console.log(JSON.stringify(output.data, null, 2));
  } catch (error) {
    console.log("error", error);
  }
});
error RangeError: Maximum call stack size exceeded
    at Array.forEach (<anonymous>)
    at object (/PATH/node_modules/insomnia-importers/src/importers/swagger2.js:300:31)
    at generateParameterExample (/PATH/node_modules/insomnia-importers/src/importers/swagger2.js:332:12)
    at Object.keys.forEach.propertyName (/PATH/node_modules/insomnia-importers/src/importers/swagger2.js:301:33)
    at Array.forEach (<anonymous>)
    at object (/PATH/node_modules/insomnia-importers/src/importers/swagger2.js:300:31)
    at generateParameterExample (/PATH/node_modules/insomnia-importers/src/importers/swagger2.js:332:12)
    at Object.keys.forEach.propertyName (/PATH/node_modules/insomnia-importers/src/importers/swagger2.js:301:33)
    at Array.forEach (<anonymous>)
    at object (/PATH/node_modules/insomnia-importers/src/importers/swagger2.js:300:31)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 49 (12 by maintainers)

Most upvoted comments

Just stumbled upon this myself, e.g. https://github.com/MicrosoftDocs/vsts-rest-api-specs/blob/master/specification/build/5.0/build.json will fail with “Maximum call stack size exceeded”.

Can you provide a sample import file that can be used to reproduce this?

Any big config file will do.

P.S. Same problem with swagger json. P.S.P.S. I have 29k line json for eg.

This bug is back after release 2022.06 till the current beta.

great to hear you fixed it

Hi @xZyph

The fix itself is meant to be implemented inside Insomnia but … you can try to manually modify your specs excluding (deleting) all $ref fields inside the file. I used this simple regex "\$ref.* and it worked but I cannot guarantee the result, you will lose the schema references inside your swagger but it’s a workaround (so, make a backup). You won’t lose them when the fix will be implemented inside Insomnia.

Here is an example of what to do:

Before Example

After Example

It worked for me, I hope it will works for you too.

Hi folks, I think I may have fixed it (or at least one of the root causes of this bug). I can raise a PR if this sounds reasonable, opinions are welcome, anyway I think it’s a step forward.

File used to test:

  1. https://nv-grt.myjetbrains.com/youtrack/api/openapi.json (YouTrack API, provided by @earshinov)
  2. https://github.com/Kong/insomnia/files/6641041/openapi.txt (Camunda API, rename as .json, provided by @tweetybird99)
  3. https://github.com/Kong/insomnia/files/6590757/swagger.json.txt (provided by @CPlusPlus17)

Before: image

After: image image image

Root cause: Circular references were killing the stack, I simply turned them off and it started working again.

How did you fix it?

  try {
    apiDocument = await SwaggerParser.validate(apiDocument, {
      dereference: {
        circular: 'ignore', // Here the new option
      },
    }) as OpenAPIV3.Document;
  } catch (err) {
    console.log('[openapi-3] Import file validation failed', err);
  }

Please, check the SwaggerParser documentation about this specific option: Click here.

Thoughts:

  • I think some people with really huge (i mean, really really huge) file imports may still experience this stack size error but those with a performant system should overcome it.
  • One test specs claimed as “affected by the stack size error” was fine for me, I can only assume you didn’t have enough power to compute them recursively (see @Xetera answer on the thread about vsts-rest-api-specs.json, it was fine for me too.)
  • Indeed there was a problem with circular references

Note:

  • I found another bug while I was fixing this one (completely unrelated to this) and I fixed it too.

great! thanks! if anything along these lines comes up again please don’t hesitate to reach out 😃

Weird, maybe it was fixed then, I’ll try again this weekend with my old file.

The problem occurs while generating examples for an object, calls again the function and the loop never closes

I am also facing the same issue. My finding is - when you have a relation between 2 classes and they have each other as a property then Swagger UI stuck in a loop.