redoc: False positive recursion

Hello there, wrestling following issue.

Imagine I want to reuse some schema, let’s say ID – I have following in ./helpers/id.yaml:

properties:
  id:
    type: number
required:
  - id

And here is a simple OpenAPI, which should result in a simple structure of three nested objects, which all wants to reference the id helper.

openapi: 3.0.0
info:
  title: False positive recursion
  version: '3.0'
paths:
  /documents:
    get:
      summary: Example
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                allOf:
                  - $ref: ./helpers/id.yaml
                  - properties:
                      second:
                        allOf:
                          - $ref: ./helpers/id.yaml
                          - properties:
                              third:
                                allOf:
                                  - $ref: ./helpers/id.yaml
                                  - properties:
                                      something:
                                        type: string

Whereas the first and second object are correctly rendered with required id attribute, the third object is flagged as recursive:

image

Any idea? Is it a bug or am I missing something?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 15
  • Comments: 22 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Short update on this ages-old issue 🙈. I found some time to work on this and looks like I have a solution. I need some time to clean it up and add tests. Thank you all for your examples here, it will definitely help with the test cases 💙.

Same here. Problem still exists

Any updates on this issue? I’m also still struggling with this

It is a bug. I will investigate it when I have time

This is the simplest reproduction code:

A:
  type: object
  properties:
    A: { type: string }

AB:
  allOf:
    - $ref: "#/components/schemas/A"
    - type: object
      properties:
        B: { $ref: "#/components/schemas/A" }
Screenshot 2021-09-07 at 00 39 21

It works fine if you inline A in one of the references

For me issue still persists with the latest version

Also encountering this issue. Example very similar to original poster’s, but in my case Recursive is being rendered on the 2nd level repeated nested object being included with allOf, and not the 3rd.

Looks like this might not be a problem anymore with the latest version of redoc-cli shrug

I tried it whith the latest version 0.10.1 and there is still the problem

Looks like this might not be a problem anymore with the latest version of redoc-cli 🤷

OK, I don’t understand, but it seems all right now. Maybe some cache. Sorry… Thanks for the fix!

Unfortunately, it is still happening in our live docs. I’ll try to further reproduce.

Please, provide steps to reproduce. It works for me. Screenshot 2022-08-15 at 15 40 39

I’m running into this issue as well using a schema with the below structure. ReDoc will correctly display the TopLevelSchema, but tags the subobjects array as recursive.

BaseSchema:
  type: object
  properties:
    id:
      type: String
TopLevelSchema:
  allOf:
    - $ref: '#/BaseSchema'
    - type: object
      properties:
        subobjects:
          type: array
          items:
            $ref: "#/BaseSchema"

My dependencies are currently using the following versions:

"dependencies": {
  "@redocly/openapi-cli": "v1.0.0-beta.54",
  "redoc": "2.0.0-rc.55",
  "redoc-cli": "~0.12.2"
}

The issue is present when the docs are presented using both openapi-cli preview-docs and redoc-cli serve. Below is a minimal example OpenAPI 3 document which demonstrates the issue.

openapi: 3.0.3
info:
  title: Recursion False Positive
  version: '3.0'
paths:
  /path:
    get:
      summary: Demonstrates a false positive recursion identification
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TopLevelSchema'
components:
  schemas:
    BaseSchema:
      type: object
      properties:
        id:
          type: String
    TopLevelSchema:
      allOf:
        - $ref: '#/components/schemas/BaseSchema'
        - type: object
          properties:
            subobjects:
              type: array
              items:
                $ref: '#/components/schemas/BaseSchema'

Screen Shot 2021-07-22 at 11 29 41

@remnestal I just rebased the commit from #1186 to see if it fixed the problem for us but it didn’t - I haven’t had time to investigate further unfortunately