Skip to content

$ref to another file throws: Circular reference detected while resolving schema #7168

@esd-thg

Description

@esd-thg

What are you generating using Kiota, clients or plugins?

API Client/SDK

In what context or format are you using Kiota?

Nuget tool

Client library/SDK language

Csharp

Describe the bug

Kiota doesn't seems to like nested $refs that point to other files (fragments).
Running kiota with the provided openapi throws this error:

 crit: Kiota.Builder.KiotaBuilder[0]
       error updating the client: Circular reference detected while resolving schema: error.openapi.json#/schemas/ErrorResponse

Expected behavior

Should work

How to reproduce

dotnet kiota generate -l CSharp -d <given openapi>

Open API description file

{
  "openapi": "3.0.1",
  "info": {
    "title": "e-conomic Invoices API",
    "description": "e-conomic REST API for invoice management - Draft invoices, Booked invoices, and Invoice totals",
    "version": "1.0.0"
  },
  "paths": {
    "/foo": {
      "get": {
        "responses": {
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ErrorResponse": {
        "$ref": "error.openapi.json#/schemas/ErrorResponse"
      }
    }
  }
}

error.openapi.json

{
  "schemas": {
    "ErrorResponse": {
      "type": "object",
      "properties": {
        "message": {
          "type": "string",
          "description": "Error message"
        }
      },
      "description": "Error response"
    }
  }
}

Kiota Version

1.29.0

Latest Kiota version known to work for scenario above?(Not required)

No response

Known Workarounds

referencing the fragment directly seems to work, instead of referencing the schema that then references the fragment

{
  "paths": {
    "/foo": {
      "get": {
        "responses": {
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "error.openapi.json#/schemas/ErrorResponse" // <-- direct
                }
              }
            }
          }
        }
      }
    }
  }
}

Configuration

No response

Debug output

Click to expand log ```
</details>


### Other information

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    CsharpPull requests that update .net codestatus:waiting-for-triageAn issue that is yet to be reviewed or assignedtype:bugA broken experience

    Type

    No type

    Projects

    Status

    Needs Triage 🔍

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions