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

Broken mutual recursion #2135

Closed
tiopid opened this issue Aug 17, 2022 · 2 comments · Fixed by #2143
Closed

Broken mutual recursion #2135

tiopid opened this issue Aug 17, 2022 · 2 comments · Fixed by #2143

Comments

@tiopid
Copy link

tiopid commented Aug 17, 2022

Describe the bug
After this fix -

fix: rewrite recursive checks

i got the problem with mutual recursion object, because here https://github.com/Redocly/redoc/blob/master/src/services/OpenAPIParser.ts#L12
only the previous $ref is checked

components:
  schemas:
    A:
      type: array
      items:
          $ref: '#/components/schemas/B'
    B:
      allOf:
        - $ref: '#/components/schemas/C'
        - $ref: '#/components/schemas/D'
    C:
      type: object
      required:
        - value
      properties:
        value:
          $ref: '#/components/schemas/A'
    D:
      type: object
@AlexVarchuk
Copy link
Collaborator

Hi @tiopid, thanks for your issue.
I tried to check your case using definition:

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:
                $ref: "#/components/schemas/A"
components:
  schemas:
    A:
      type: array
      items:
          $ref: '#/components/schemas/B'
    B:
      allOf:
        - $ref: '#/components/schemas/C'
        - $ref: '#/components/schemas/D'
    C:
      type: object
      required:
        - value
      properties:
        value:
          $ref: '#/components/schemas/A'
    D:
      type: object
                                                

But on commits:
before changes 992099
on changes 2970f9
rc-74
rc-75

I had the same result.
Screenshot 2022-08-18 at 15 27 23

Please provide more clear steps to reproduce and expected behavior.

Thanks

@AlexVarchuk AlexVarchuk self-assigned this Aug 18, 2022
@tiopid
Copy link
Author

tiopid commented Aug 18, 2022

sorry, this is correct example
somesing like this compiled by speccy from different files

openapi: 3.0.1
info:
  title: False positive recursion
  version: '3.0'
paths:
  /documents:
    get:
      summary: Example
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                allOf:
                  - type: object
                    required:
                      - "@relations"
                    properties:
                      "@relations":
                        type: object
                        properties:
                          A:
                            type: object
                            description: Description
                            properties:
                              B:
                                type: array
                                items:
                                  oneOf:
                                    - type: object
                                    - title: tableLookup
                                      type: object
                                      properties:
                                        fallback:
                                          type: array
                                          default: []
                                          items:
                                            $ref: "#/paths/~1documents/get/responses/200/content/application~1json/schema/allOf/0/properties/%40relations/properties/A/properties/B"
                  - type: object
                    required:
                      - "@relations"
                    properties:
                      "@relations":
                        type: object
                        properties:
                          A:
                            $ref: "#/paths/~1documents/get/responses/200/content/application~1json/schema/allOf/0/properties/%40relations/properties/A"
      

I noticed that the error occurs because both objects in allOf the properties are called A, and B items with oneOf

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.

2 participants