Redoc: False positive recursion detection from version 2.0.0-alpha.13

Created on 31 Oct 2018  路  7Comments  路  Source: Redocly/redoc

From version 2.0.0-alpha.13 is broken recursion detection as it detects recursion where is no recursion. Things worsened from 2.0.0-alpha.29 up to latest version.

Reduced test case (click)

openapi: 3.0.0
info:
  version: 1.2.3
  title: api

paths:
  /api:
    post:
      summary: api
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Data'
      responses:
        200:
          description: Ok

components:
  schemas:
    D:
      type: object
      properties:
        d:
          type: string

    C:
      type: object
      properties:
        type:
          type: string
        c:
          allOf:
            - $ref: '#/components/schemas/D'

    B1:
      allOf:
        - $ref: '#/components/schemas/C'
      type: object
      properties:
        b1:
          type: string

    B2:
      allOf:
        - $ref: '#/components/schemas/C'
      type: object
      properties:
        b2:
          type: string


    A1:
      allOf:
        - $ref: '#/components/schemas/C'
        - $ref: '#/components/schemas/B1'
      type: object
      properties:
        a1:
          type: string


    A2:
      allOf:
        - $ref: '#/components/schemas/C'
        - $ref: '#/components/schemas/B2'
      type: object
      properties:
        a2:
          type: string

    Abc:
      type: array
      items:
        oneOf:
          - $ref: '#/components/schemas/A1'
          - $ref: '#/components/schemas/A2'
        discriminator:
          propertyName: type
          mapping:
            a1: '#/components/schemas/A1'
            a2: '#/components/schemas/A2'

    Data:
      allOf:
        - type: object
          properties:
            abc:
              allOf:
                - $ref: '#/components/schemas/Abc'



With versions from 2.0.0-alpha.29 to 2.0.0-alpha.41 it looks like this:
screen shot 2018-10-31 at 21 37 53

Versions from 2.0.0-alpha.13 to 2.0.0-alpha.28:
screen shot 2018-10-31 at 21 39 39

How it should look correctly (2.0.0-alpha.12):
screen shot 2018-10-31 at 21 40 26

There is no recursion here is graph of objects, it is simple linear flow:
screen shot 2018-10-31 at 22 00 58

graph LR;
    Data-->Abc;
    Abc-->A1;
    Abc-->A2;
    A1-->C;
    A1-->B1;
    A2-->C;
    A2-->B2;
    B1-->C;
    B2-->C;
    C-->D;

bug

Most helpful comment

Seems this fix is already published because when I tested original example it showed no recursion.

But I am afraid I found counterexample:

openapi: 3.0.0
info:
  version: 1.2.3
  title: api

paths:
  /api:
    post:
      summary: api
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Data'
      responses:
        200:
          description: Ok

components:
  schemas:
    B:
      type: object
      properties:
        b:
          type: string
    A1:
      type: object
      properties:
        a:
          type: array
          items:
            $ref: '#/components/schemas/B'
    A2:
      type: object
      properties:
        a:
          type: array
          items:
            $ref: '#/components/schemas/B'
    Data:
      allOf:
        - $ref: '#/components/schemas/A1'
        - $ref: '#/components/schemas/A2'

With https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js

Screenshot 2019-10-01 at 21 15 57

With https://unpkg.com/[email protected]/bundles/redoc.standalone.js

Screenshot 2019-10-01 at 21 16 16

Seems something does not propagate well through arrays.

Also why was alpha 12 without such issues? I see that also there is recursion detection and seems it works well when I intentionally create some recursion and seems it has no false positives.

All 7 comments

Thanks for the super detailed issue report 馃憤 !

I am aware of this issue and I think I have a fix locally.
Still testing it.

Any news on that? We're experiencing a similar issue.

Here is my minimal test case:

openapi: "3.0.1"
info:
  version: "1.0.0"
paths:
  /:
    get:
      responses:
        200:
          content:
            application/json:
              schema:
                allOf:
                - properties:
                    u:
                      $ref: "#/components/schemas/B"
                  type: "object"
components:
  schemas:
    A:
      type: "object"
    B:
      allOf:
      - $ref: "#/components/schemas/A"
      - $ref: "#/components/schemas/C"
    C:
      properties:
        x:
          $ref: "#/components/schemas/A"

I am also encountering false recursion detection in redoc. It works correctly in Swagger-UI.

Should be fixed by faa74d60

Will be available in the new release.

Seems this fix is already published because when I tested original example it showed no recursion.

But I am afraid I found counterexample:

openapi: 3.0.0
info:
  version: 1.2.3
  title: api

paths:
  /api:
    post:
      summary: api
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Data'
      responses:
        200:
          description: Ok

components:
  schemas:
    B:
      type: object
      properties:
        b:
          type: string
    A1:
      type: object
      properties:
        a:
          type: array
          items:
            $ref: '#/components/schemas/B'
    A2:
      type: object
      properties:
        a:
          type: array
          items:
            $ref: '#/components/schemas/B'
    Data:
      allOf:
        - $ref: '#/components/schemas/A1'
        - $ref: '#/components/schemas/A2'

With https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js

Screenshot 2019-10-01 at 21 15 57

With https://unpkg.com/[email protected]/bundles/redoc.standalone.js

Screenshot 2019-10-01 at 21 16 16

Seems something does not propagate well through arrays.

Also why was alpha 12 without such issues? I see that also there is recursion detection and seems it works well when I intentionally create some recursion and seems it has no false positives.

Yes, it still fails with 2.0.0-rc.23, regardless whether common model is reused within array or as a single-value property.

Another code example

openapi: 3.0.0

info:
  title: Test spec
  description: Test spec for ReDoc bug
  version: v1

paths:
  /distro:
    post:
      requestBody:
        $ref: "#/components/requestBodies/Distro"
      responses:
        200:
          description: Success
          content:
            application/json:
              example: { "message": "ok" }

components:
  schemas:

    Version:
      properties:
        major:
          type: integer
        minor:
          type: integer

    Library:
      allOf:
        - properties:
            name:
              type: string
        - $ref: "#/components/schemas/Version"

    App:
      properties:
        name:
          type: string
        dependencies:
          type: array
          items:      # rendered as recursive
            $ref: "#/components/schemas/Library"
        executable:   # rendered as recursive
            $ref: "#/components/schemas/Library"

    Bundle:
      allOf:
        - $ref: "#/components/schemas/Version"
        - $ref: "#/components/schemas/App"

  requestBodies:
    Distro:
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Bundle"
Was this page helpful?
0 / 5 - 0 ratings

Related issues

JonKohler picture JonKohler  路  3Comments

gavinkalika picture gavinkalika  路  3Comments

dvh picture dvh  路  3Comments

martnst picture martnst  路  3Comments

zmes50416 picture zmes50416  路  3Comments