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

openapi3: implement circular reference backtracking #970

Merged
merged 6 commits into from
Jun 26, 2024

Conversation

AnatolyRugalev
Copy link
Contributor

@AnatolyRugalev AnatolyRugalev commented Jun 25, 2024

This PR adds a test scenario that leads to failure of resolving recursive references.

After troubleshooting for a while, I realized that current reference tracking algorithm in not perfect and will always have some edge cases, so I decided to try fixing that for good.

During reference resolution, we keep track of all previous references, and if we find out that the reference is already being resolved, we register a backtracking callback that will assign a pointer to the resolved schema once it's done.

This guarantees that schema will always be resolved regardless of the depth.

@AnatolyRugalev AnatolyRugalev changed the title test: add failure scenario for recursion feat(loader): implement circular reference backtracking Jun 26, 2024
@AnatolyRugalev AnatolyRugalev marked this pull request as ready for review June 26, 2024 13:22
@AnatolyRugalev
Copy link
Contributor Author

@fenollp I updated the PR description and its contents :)

This should solve circular references resolution for good. Let me know if you have any questions or concerns

Copy link
Collaborator

@fenollp fenollp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi & thanks for taking the time to look into this!

Mostly LGTM, just: I see you're not using the visitref utils you're introducing in these two places and it feels like this was fogotten?

  • func (loader *Loader) resolveLinkRef(doc *T, component *LinkRef, documentPath *url.URL) (err error)
  • func (loader *Loader) resolvePathItemRef(doc *T, pathItem *PathItem, documentPath *url.URL) (err error)
    Could you comment on or fix that please?

openapi3/loader.go Outdated Show resolved Hide resolved
openapi3/loader.go Outdated Show resolved Hide resolved
openapi3/loader.go Outdated Show resolved Hide resolved
openapi3/loader.go Outdated Show resolved Hide resolved
openapi3/loader.go Outdated Show resolved Hide resolved
@AnatolyRugalev
Copy link
Contributor Author

Thanks for a quick review! I indeed missed a couple of functions. It's ready for re-review

Copy link
Collaborator

@fenollp fenollp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@fenollp fenollp changed the title feat(loader): implement circular reference backtracking openapi3: implement circular reference backtracking Jun 26, 2024
@fenollp fenollp merged commit fe47dca into getkin:master Jun 26, 2024
5 checks passed
@AnatolyRugalev AnatolyRugalev deleted the issue/circular-reference-bug branch June 26, 2024 16:52
AnatolyRugalev added a commit to AnatolyRugalev/kin-openapi that referenced this pull request Jun 27, 2024
* feat(loader): implement reference back-tracking

* update docs

* address review comments

* update docs and readme

* fix inconsistency

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

Successfully merging this pull request may close these issues.

None yet

2 participants