Skip to content

Commit 523c7d0

Browse files
committed
fix: solving call stack issue
1 parent 793f931 commit 523c7d0

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-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/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)