microsoft / microsoft/OpenAPI.NET

Circular references in external documents create an infinite recursion

Open
#1,985 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
1.6k
Forks
286
Avg merge
6h 38m
Merged PRs (30d)
35

Description

Describe the bug
Open api documents that contain circular references create an infinite recursion because each external document is loaded into a new root workspace rather than the initial document loader workspace.

OpenApi File To Reproduce
In order to reproduce, you need two files that reference each other. I've put a circular reference in the schemas section of the below specs (this is not the exact problem I'm seeing with real documents, but it's close enough to reproduce). The references are hard coded to a mount directory because I'm using kiota as a driver, so you may need to update the paths if you run against a different location.

pet.json
pets2.json

Expected behavior
I believe external documents should all be loaded into the same workspace for reference resolution.

Screenshots/Code Snippets

docker run --rm `
    -v "${PWD}\output:/app/output" `
    -v "${PWD}\specs:/app/specs" `
    -u root `
    mcr.microsoft.com/openapi/kiota generate --language csharp -n MyCode --openapi ./specs/pet.json --log-level trace

I have encountered the problem in open api documents from large enterprise software providers, so I've attached a patch file that contains my work around for an internal fork of the document loader libraries. Adding external documents to the root workspace created by the initial document load appears to resolve the problem, though I'm not sure if the external references are being resolved correctly.

This patch includes the changes I was required to make in order to resolve locally.
circular_ref.patch

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the recursion with the linked pet.json and pets2.json files using the provided Kiota Docker command, then trace how external documents are loaded into workspaces during reference resolution. Compare the attached circular_ref.patch with the current behavior; done means mutually referencing external documents resolve without infinite recursion while remaining in the intended workspace.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.