swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

bug: RangeError: Maximum call stack size exceeded

Open raymondfeng opened this issue 5 years ago • 3 comments

The following code throws RangeError: Maximum call stack size exceeded due to infinite recursion. If we remove description next to $ref, it works.

const json = {
  openapi: '3.0.0',
  info: {
    version: '1.0.0',
    title: 'Token',
    description: 'Token',
    license: {
      name: 'Apache 2.0',
      url: 'https://www.apache.org/licenses/LICENSE-2.0.html',
    },
  },
  servers: [
    {url: 'https://localhost:3000', description: 'Local laptop testing'},
  ],
  tags: [{name: 'Token', description: 'Token resource'}],
  paths: {
    '/token': {
      get: {
        tags: ['Token'],
        description: 'Get token',
        operationId: 'getToken',
        responses: {
          '200': {
            description: 'customer response',
            content: {
              'application/json': {
                schema: {
                  $ref: '#/components/schemas/Token',
                  'description': 'ABC'
                },
              },
            },
          },
        },
      },
    },
  },
  components: {
    schemas: {
      Token: {
        type: 'array',
        items: {
          $ref: '#/components/schemas/Token',
          'description': 'ABC'
        },
      },
    },
  },
};

const parser = require('swagger-parser');
parser.dereference(json);

raymondfeng avatar Jun 03 '20 16:06 raymondfeng

Thanks for reporting this. And especially for providing a full code sample! 🙏 I'll add it to the test suite so we can determine the cause

JamesMessinger avatar Jul 11 '20 07:07 JamesMessinger

@JamesMessinger I'm also running into the same problem when I use the bundle() method of the parser. Is there any workaround that you suggest other than editing the file to get rid of refs?

jaishirole avatar Nov 19 '20 08:11 jaishirole

@raymondfeng I was able to work around this issue by setting circular: "ignore"

await SwaggerParser.validate("myopenapi.json", { dereference: { circular: "ignore" }, });

gautam-borkar avatar Dec 05 '20 00:12 gautam-borkar