@@ -7,7 +7,8 @@ const _ = require('lodash')
77module . 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 ] ) ) {
@@ -151,11 +163,11 @@ module.exports = function() {
151163 }
152164 result = _ . merge ( result , merged )
153165 } else if ( _ . isArray ( schema [ i ] ) && i !== 'required' ) {
154- const arrayResult = [ ]
155- for ( let k in schema [ i ] ) {
156- arrayResult . push ( replaceAllOfs ( schema [ i ] [ k ] ) )
166+ if ( schema [ i ] . every ( v => ! _ . isObject ( v ) ) ) {
167+ result [ i ] = [ ...schema [ i ] ] ;
168+ } else {
169+ result [ i ] = schema [ i ] . map ( item => replaceAllOfs ( item ) ) ;
157170 }
158- result [ i ] = arrayResult
159171 } else if ( _ . isObject ( schema [ i ] ) && i !== 'required' ) {
160172 // result.type = 'object';
161173 result [ i ] = _ . merge ( result [ i ] , replaceAllOfs ( schema [ i ] ) )
0 commit comments