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

Incorrect OpenAPI Schema Generation for Recursive Types #61139

Open
1 task done
sorcerb opened this issue Mar 24, 2025 · 0 comments
Open
1 task done

Incorrect OpenAPI Schema Generation for Recursive Types #61139

sorcerb opened this issue Mar 24, 2025 · 0 comments
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-openapi

Comments

@sorcerb
Copy link

sorcerb commented Mar 24, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

We encountered an issue where ASP.NET Core incorrectly generates OpenAPI json schema for recursive types. Specifically, the generated schema for a recursive model (Nav) is valid, but when attempting to define a separate object (Nav2) that references an array of items, it incorrectly resolves the $ref path.

Expected Behavior

The generated OpenAPI schema should correctly resolve $ref references for recursive types, ensuring Nav2.children.items properly refers to the Nav schema.

Steps To Reproduce

app.MapPost("/a", (Nav n) => "Hello World!");
app.MapPost("/b", (List<Nav> n) => "Hello World!");

public class Nav
{
    public long Id { get; set; }
    public List<Nav> Children { get; set; } = [];
}
"Nav": {
  "type": "object",
  "properties": {
	"id": {
	  "type": "integer",
	  "format": "int64"
	},
	"children": {
	  "type": "array",
	  "items": {
		"$ref": "#/components/schemas/Nav"
	  }
	}
  }
},
"Nav2": {
  "type": "object",
  "properties": {
	"id": {
	  "type": "integer",
	  "format": "int64"
	},
	"children": {
	  "type": "array",
	  "items": {
		"$ref": "#/components/schemas/#/items"   // <--- this should refers to the Nav, but actually, 
                                                         // this Nav2 is the same as Nav, so it won't be generated
	  }
	}
  }
},

Exceptions (if any)

No response

.NET Version

9.0.3

Related issues

Recursive data models inside collections yield invalid schema references #59879
.NET 9 OpenAPI produces lots of duplicate schemas for the same object #58968

@gfoidl gfoidl added feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-web-frameworks labels Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-openapi
Projects
None yet
Development

No branches or pull requests

2 participants