Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive recursion #1154

Closed
krystof-k opened this issue Jan 9, 2020 · 22 comments · Fixed by #2072
Closed

False positive recursion #1154

krystof-k opened this issue Jan 9, 2020 · 22 comments · Fixed by #2072

Comments

@krystof-k
Copy link
Contributor

krystof-k commented Jan 9, 2020

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?

@RomanHotsiy
Copy link
Member

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

@StephaneLambert
Copy link

I had the same problem with a string property. It seems to appear with the use of allOf and basic types (integer, string, ...) simultaneously.
In this case, the components/schemas/ seems to be replaced by the basic type and result of a false recursion in Redoc.

m0003r added a commit to m0003r/redoc that referenced this issue Feb 27, 2020
Immediately exit from allOf's children, but use separate refCounter to do not enter into same scheme recursively
Also add pseudo-recursive example
@m-mohr
Copy link
Contributor

m-mohr commented Apr 9, 2020

I have the same issue and can provide another reproduction example, if required.

jlaw90 pushed a commit to jlaw90/redoc that referenced this issue Jul 28, 2020
Immediately exit from allOf's children, but use separate refCounter to do not enter into same scheme recursively
Also add pseudo-recursive example
@remnestal
Copy link

Any news on how this issue is progressing? I could also provide additional examples if needed.

@jlaw90 looks like you may have a solution to the problem in jlaw90@5f23b7a, is this something you're planning to make a PR proposal for anytime soon? Would be greatly appreciated 🎉

@jlaw90
Copy link

jlaw90 commented Aug 19, 2020

@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

@agustin-tecso
Copy link

I have the same problem, I created the issue #1439.

@remnestal
Copy link

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

@agustin-tecso
Copy link

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

@Kerry-at-VIP
Copy link

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.

@aleskovets
Copy link

Same here. Problem still exists

@hotrush
Copy link

hotrush commented Jun 8, 2021

Have a similar issue with a schema that has allOf e.g.

          "Schema1": {
                "title": "Schema1",
                "allOf": [
                    {
                        "$ref": "#/components/schemas/SchemaBase"
                    },
                    {
                        "properties": {
                             "items": {
                                "title": "Items",
                                "properties": {
                                    "items": {
                                        "type": "array",
                                        "items": {
                                            "$ref": "#/components/schemas/Schema2"
                                        }
                                    },
                                    "total": {
                                        "format": "int64",
                                        "example": 1
                                    }
                                },
                                "type": "object"
                            }
                         }

When the second schema Schema2 has the same allOf - SchemaBase

image

@notana
Copy link

notana commented Jul 5, 2021

@RomanHotsiy have you had any time to look into this issue (I saw your comment from earlier)? Or maybe someone else has?

@fmiqbal
Copy link

fmiqbal commented Jul 6, 2021

Is this affecting current version? are there any old version I can use that doesnt have this issue? this is breaking changes for me

@krystof-k
Copy link
Contributor Author

It seems it is at least somehow fixed in the current version. I don't see the recursions anymore.

@bskinner
Copy link

bskinner commented Jul 22, 2021

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

@hotrush
Copy link

hotrush commented Jul 22, 2021

For me issue still persists with the latest version

@safareli
Copy link

safareli commented Sep 6, 2021

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

@RomanHotsiy
Copy link
Member

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 💙.

@salexo
Copy link

salexo commented Jan 26, 2022

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

@krystof-k
Copy link
Contributor Author

krystof-k commented Aug 15, 2022

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

It helped on the 3rd level of nesting, but on the 4th level it still doesn't work.

@AlexVarchuk
Copy link
Collaborator

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

@krystof-k
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.