@@ -195,12 +195,12 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor {
195195 // eslint-disable-next-line sonarjs/cognitive-complexity
196196 static convertToInternalSchema (
197197 schema : AsyncAPISchemaInterface | boolean ,
198- alreadyIteratedSchemas : Map < string , AsyncapiV2Schema > = new Map ( )
198+ alreadyIteratedSchemas : Map < string , AsyncapiV2Schema > = new Map ( ) ,
199+ visitedSchemas : WeakSet < object > = new WeakSet ( )
199200 ) : AsyncapiV2Schema | boolean {
200201 if ( typeof schema === 'boolean' ) {
201202 return schema ;
202203 }
203-
204204 let schemaUid = schema . id ( ) ;
205205 //Because the constraint functionality of generators cannot handle -, <, >, we remove them from the id if it's an anonymous schema.
206206 if (
@@ -225,27 +225,40 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor {
225225 convertedSchema . allOf = schema
226226 . allOf ( ) !
227227 . map ( ( item : any ) =>
228- this . convertToInternalSchema ( item , alreadyIteratedSchemas )
228+ this . convertToInternalSchema (
229+ item ,
230+ alreadyIteratedSchemas ,
231+ visitedSchemas
232+ )
229233 ) ;
230234 }
231235 if ( schema . oneOf ( ) ) {
232236 convertedSchema . oneOf = schema
233237 . oneOf ( ) !
234238 . map ( ( item : any ) =>
235- this . convertToInternalSchema ( item , alreadyIteratedSchemas )
239+ this . convertToInternalSchema (
240+ item ,
241+ alreadyIteratedSchemas ,
242+ visitedSchemas
243+ )
236244 ) ;
237245 }
238246 if ( schema . anyOf ( ) ) {
239247 convertedSchema . anyOf = schema
240248 . anyOf ( ) !
241249 . map ( ( item : any ) =>
242- this . convertToInternalSchema ( item , alreadyIteratedSchemas )
250+ this . convertToInternalSchema (
251+ item ,
252+ alreadyIteratedSchemas ,
253+ visitedSchemas
254+ )
243255 ) ;
244256 }
245257 if ( schema . not ( ) ) {
246258 convertedSchema . not = this . convertToInternalSchema (
247259 schema . not ( ) ! ,
248- alreadyIteratedSchemas
260+ alreadyIteratedSchemas ,
261+ visitedSchemas
249262 ) ;
250263 }
251264 if (
@@ -254,37 +267,43 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor {
254267 ) {
255268 convertedSchema . additionalItems = this . convertToInternalSchema (
256269 schema . additionalItems ( ) ,
257- alreadyIteratedSchemas
270+ alreadyIteratedSchemas ,
271+ visitedSchemas
258272 ) ;
259273 }
260274 if ( schema . contains ( ) ) {
261275 convertedSchema . contains = this . convertToInternalSchema (
262276 schema . contains ( ) ! ,
263- alreadyIteratedSchemas
277+ alreadyIteratedSchemas ,
278+ visitedSchemas
264279 ) ;
265280 }
266281 if ( schema . propertyNames ( ) ) {
267282 convertedSchema . propertyNames = this . convertToInternalSchema (
268283 schema . propertyNames ( ) ! ,
269- alreadyIteratedSchemas
284+ alreadyIteratedSchemas ,
285+ visitedSchemas
270286 ) ;
271287 }
272288 if ( schema . if ( ) ) {
273289 convertedSchema . if = this . convertToInternalSchema (
274290 schema . if ( ) ! ,
275- alreadyIteratedSchemas
291+ alreadyIteratedSchemas ,
292+ visitedSchemas
276293 ) ;
277294 }
278295 if ( schema . then ( ) ) {
279296 convertedSchema . then = this . convertToInternalSchema (
280297 schema . then ( ) ! ,
281- alreadyIteratedSchemas
298+ alreadyIteratedSchemas ,
299+ visitedSchemas
282300 ) ;
283301 }
284302 if ( schema . else ( ) ) {
285303 convertedSchema . else = this . convertToInternalSchema (
286304 schema . else ( ) ! ,
287- alreadyIteratedSchemas
305+ alreadyIteratedSchemas ,
306+ visitedSchemas
288307 ) ;
289308 }
290309 if (
@@ -293,21 +312,28 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor {
293312 ) {
294313 convertedSchema . additionalProperties = this . convertToInternalSchema (
295314 schema . additionalProperties ( ) ,
296- alreadyIteratedSchemas
315+ alreadyIteratedSchemas ,
316+ visitedSchemas
297317 ) ;
298318 }
299319 if ( schema . items ( ) ) {
300320 if ( Array . isArray ( schema . items ( ) ) ) {
301321 convertedSchema . items = (
302322 schema . items ( ) as AsyncAPISchemaInterface [ ]
303323 ) . map (
304- ( item ) => this . convertToInternalSchema ( item ) ,
324+ ( item ) =>
325+ this . convertToInternalSchema (
326+ item ,
327+ alreadyIteratedSchemas ,
328+ visitedSchemas
329+ ) ,
305330 alreadyIteratedSchemas
306331 ) ;
307332 } else {
308333 convertedSchema . items = this . convertToInternalSchema (
309334 schema . items ( ) as AsyncAPISchemaInterface ,
310- alreadyIteratedSchemas
335+ alreadyIteratedSchemas ,
336+ visitedSchemas
311337 ) ;
312338 }
313339 }
@@ -320,7 +346,8 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor {
320346 ) ) {
321347 properties [ String ( propertyName ) ] = this . convertToInternalSchema (
322348 propertySchema ,
323- alreadyIteratedSchemas
349+ alreadyIteratedSchemas ,
350+ visitedSchemas
324351 ) ;
325352 }
326353 convertedSchema . properties = properties ;
@@ -337,7 +364,8 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor {
337364 if ( typeof dependency === 'object' && ! Array . isArray ( dependency ) ) {
338365 dependencies [ String ( dependencyName ) ] = this . convertToInternalSchema (
339366 dependency ,
340- alreadyIteratedSchemas
367+ alreadyIteratedSchemas ,
368+ visitedSchemas
341369 ) ;
342370 } else {
343371 dependencies [ String ( dependencyName ) ] = dependency ;
@@ -357,7 +385,11 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor {
357385 schemaPatternProperties
358386 ) ) {
359387 patternProperties [ String ( patternPropertyName ) ] =
360- this . convertToInternalSchema ( patternProperty , alreadyIteratedSchemas ) ;
388+ this . convertToInternalSchema (
389+ patternProperty ,
390+ alreadyIteratedSchemas ,
391+ visitedSchemas
392+ ) ;
361393 }
362394 convertedSchema . patternProperties = patternProperties ;
363395 }
@@ -370,7 +402,8 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor {
370402 ) ) {
371403 definitions [ String ( definitionName ) ] = this . convertToInternalSchema (
372404 definition ,
373- alreadyIteratedSchemas
405+ alreadyIteratedSchemas ,
406+ visitedSchemas
374407 ) ;
375408 }
376409 convertedSchema . definitions = definitions ;
0 commit comments