Skip to content

Commit b617884

Browse files
authored
Merge pull request #99 from apiaddicts/fix/95/maximum_call_stack
fix: solving call stack issue
2 parents 988aea1 + 5a92f02 commit b617884

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

src/parser/openapi3/body.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const _ = require('lodash')
77
module.exports = function() {
88

99
const MAX_DEPTH_LEVEL = 20;
10-
10+
let seenSchemas = new WeakSet();
11+
1112
return function get(verb, path, bodyResponse) {
1213
if (!_.isObject(global.definition.paths)) {
1314
require('../../utils/error.js')('paths is required')
@@ -110,6 +111,17 @@ module.exports = function() {
110111
}
111112

112113
function replaceAllOfs(schema){
114+
if (!_.isObject(schema)) return schema;
115+
116+
// Detectar ciclos por identidad
117+
if (seenSchemas.has(schema)) {
118+
return {
119+
type: "string",
120+
description: "Circular schema avoided"
121+
};
122+
}
123+
seenSchemas.add(schema);
124+
113125
let result = {}
114126
for (let i in schema) {
115127
if (i === 'allOf' && _.isArray(schema[i])){

src/parser/swagger2/body.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
const _ = require('lodash');
66

77
module.exports = function() {
8+
9+
let seenSchemas = new WeakSet();
10+
811

912
return function get(verb, path, bodyResponse) {
1013
if (!_.isObject(global.definition.paths)) {
@@ -38,6 +41,18 @@ module.exports = function() {
3841
};
3942

4043
function replaceRefs(schema){
44+
45+
if (!_.isObject(schema)) return schema;
46+
47+
// Detectar ciclos por identidad
48+
if (seenSchemas.has(schema)) {
49+
return {
50+
type: "string",
51+
description: "Circular schema avoided"
52+
};
53+
}
54+
seenSchemas.add(schema);
55+
4156
let result = {};
4257
for (let i in schema) {
4358
if (i === '$ref'){

src/parser/swagger2/pathParameters.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const _ = require('lodash');
66

77
module.exports = function() {
8+
let seenSchemas = new WeakSet();
89

910
return function get(verb,path){
1011
if (!_.isObject(global.definition.paths)) {
@@ -23,6 +24,17 @@ module.exports = function() {
2324
}
2425

2526
function replaceRefs(schema){
27+
if (!_.isObject(schema)) return schema;
28+
29+
// Detectar ciclos por identidad
30+
if (seenSchemas.has(schema)) {
31+
return {
32+
type: "string",
33+
description: "Circular schema avoided"
34+
};
35+
}
36+
seenSchemas.add(schema);
37+
2638
let result = {};
2739
for (let i in schema) {
2840
if (i === '$ref'){

src/swagger2json/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,22 @@ const _ = require('lodash');
77
module.exports = function() {
88

99
return function get(swagger, name, parent,index){
10+
if (typeof swagger !== 'object' || swagger === null) {
11+
swagger = { type: 'string' };
12+
}
1013

11-
if (!swagger.type && swagger.properties){
12-
swagger.type = 'object';
13-
} else if (swagger.oneOf) {
14-
swagger.type = 'oneOf';
15-
} else if (swagger.anyOf) {
16-
swagger.type = 'anyOf';
14+
if (!swagger.type) {
15+
if (swagger.properties) {
16+
swagger.type = 'object';
17+
} else if (swagger.items) {
18+
swagger.type = 'array';
19+
} else if (swagger.oneOf) {
20+
swagger.type = 'oneOf';
21+
} else if (swagger.anyOf) {
22+
swagger.type = 'anyOf';
23+
} else {
24+
swagger.type = 'string';
25+
}
1726
}
1827

1928
let wrongParam = false;

0 commit comments

Comments
 (0)