bug: RangeError: Maximum call stack size exceeded
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);
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 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?
@raymondfeng I was able to work around this issue by setting circular: "ignore"
await SwaggerParser.validate("myopenapi.json", { dereference: { circular: "ignore" }, });