OpenAPI generation leads to invalid openapi.json file #59496
Labels
area-minimal
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
feature-openapi
✔️ Resolution: Duplicate
Resolved as a duplicate of another issue
Status: Resolved
Is there an existing issue for this?
Describe the bug
Consider the following minimal example:
This leads to the following openapi.json (relevant section):
Note that links1 looks correct, while links2 is different and leads to an error when viewing it in swagger UI ("Semantic error at components.schemas.Post.properties.links2.items.$ref - $ref values must be RFC3986-compliant percent-encoded URIs")
Removing links1 fixes the ref for links2, so it appears that when you have two properties with the same type, the openapi generation is being smart and encoding a ref to the first property, however swagger UI doesn't seem to support it, at least in this scenario.
Expected Behavior
I would expect .NET 9's openapi generation generates JSON files that are valid according to swagger UI.
Steps To Reproduce
I included most of a code example above. I think the behaviour here is probably intentional, but seems incompatible with swagger UI, so I'm assuming a complete repro repo isn't needed. If it would be helpful, let me know and I can create one.
Exceptions (if any)
No response
.NET Version
9.0.101
Anything else?
Brand new
dotnet new webapi
from .net 9.0.101; assumingdotnet --info
isn't relevant here.edit: this issue also seems to break the NSwagTypeScript code generator, with basically the same error message
System.InvalidOperationException: Could not resolve the path '#/components/schemas/#/properties/links/items'.
The text was updated successfully, but these errors were encountered: