$ref to another file throws: Circular reference detected while resolving schema
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 333
- Avg merge
- 16h 29m
- Merged PRs (30d)
- 116
Description
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_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided dotnet kiota generate -l CSharp -d <given openapi> command with the two OpenAPI files and trace nested $ref resolution. The fix is complete when the external fragment referenced through #/components/schemas/ErrorResponse no longer raises a circular-reference error and C# client generation succeeds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100