Redocly / redoc

📘 OpenAPI/Swagger-generated API Reference Documentation
https://redocly.github.io/redoc/
MIT License
23.58k stars 2.3k forks source link

Combination of allOf and anyOf leads to Maximum call stack size exceeded #1124

Closed Vasfed closed 2 years ago

Vasfed commented 4 years ago

This valid schema:

openapi: "3.0.2"
info:
  title: Recursive
  version: 0.0.1

paths:
  /somepath:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Article'
                  - required: [ foo ]
components:
  schemas:
    Article:
      type: object
      properties:
        similar:
          allOf:
            - $ref: '#/components/schemas/Article'
            - required: [ bar ]
      anyOf:
        - required: [ foo ]
        - required: [ bar ]

causes stack overflow:

(Warning) Not exited reference: #/components/schemas/Article 
    in Context.Consumer (created by Operation)
    in Operation (created by OperationItem)
    in OperationItem (created by ContentItem)
    in ContentItem (created by ContentItems)
    in ContentItems (created by Redoc)
    in Redoc

OpenAPIParser.ts:255 Uncaught RangeError: Maximum call stack size exceeded
    at Array.map (<anonymous>)
    at OpenAPIParser.mergeAllOf (OpenAPIParser.ts:255)
    at new SchemaModel (Schema.ts:41)
    at new FieldModel (Field.ts:59)
    at eval (Schema.ts:215)
    at Array.map (<anonymous>)
    at buildFields (Schema.ts:206)
    at SchemaModel.init (Schema.ts:108)
    at new SchemaModel (Schema.ts:42)
    at eval (Schema.ts:135)

tested on master @ dc5430e53def780a81612d269cc3aea3f8785eea

ameinhardt commented 4 years ago

similar issue with direct allOf / oneOf combination as in schema:

Node: {
  type:       'object',
  properties: {
  },
  allOf: [{
    oneOf: [{
      properties: {
        typeId: {
          $ref: '#/components/schemas/Id'
        }
      }
    }, {
      properties: {
        type: {
          $ref: '#/components/schemas/NodeType'
        }
      }
    }]
  }, {
    oneOf: [{
      properties: {
        parentId: {
          $ref: '#/components/schemas/Id'
        }
      }
    }, {
      properties: {
        parent: {
          $ref: '#/components/schemas/Node'
        }
      }
    }]
  }]
},