-
Notifications
You must be signed in to change notification settings - Fork 10.3k
[Critical] ASP.NET Core 9.0: AddOpenApi duplicates schema with a number suffix #59427
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
Comments
Please provide the repro as a GitHub repository, not a ZIP file. |
sure, will do within next 30 min |
@martincostello: Updated the original issue with the link as well. |
Issue seems to be here:
{
"type": "array",
"items": {
"type": "object",
"properties": {
"location": {
"type": "object",
"properties": {
"address": {
"type": "object",
"properties": {
"relatedLocation": {
"type": "object",
"properties": {
"address": {
"$ref": "#/items/properties/location/properties/address",
"x-schema-id": "AddressDto"
}
},
"x-schema-id": "LocationDto"
}
},
"x-schema-id": "AddressDto"
}
},
"x-schema-id": "LocationDto"
}
},
"x-schema-id": "WeatherForecast"
}
}
{
"type": "object",
"properties": {
"address": {
"$ref": "#/items/properties/location/properties/address",
"x-schema-id": "AddressDto"
}
},
"x-schema-id": "LocationDto"
}
{
"type": "object",
"properties": {
"address": {
"type": "object",
"properties": {
"relatedLocation": {
"type": "object",
"properties": {
"address": {
"$ref": "#/items/properties/location/properties/address",
"x-schema-id": "AddressDto"
}
},
"x-schema-id": "LocationDto"
}
},
"x-schema-id": "AddressDto"
}
},
"x-schema-id": "LocationDto"
} Should the OpenApiSchema for {
"type": "object",
"properties": {
"location": {
"type": "object",
"properties": {
"address": {
"type": "object",
"properties": {
"relatedLocation": {
"type": "object",
"properties": {
"address": {
"$ref": "#/items/properties/location/properties/address",
"x-schema-id": "AddressDto"
}
},
// added
"$ref": "#/items/properties/location",
"x-schema-id": "LocationDto"
}
},
"x-schema-id": "AddressDto"
}
},
"x-schema-id": "LocationDto"
}
},
"x-schema-id": "WeatherForecast"
} |
Updated the repro with minimal APIs, WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();
WebApplication app = builder.Build();
app.MapOpenApi();
app.UseSwaggerUI(x =>
{
x.SwaggerEndpoint("/openapi/v1.json", "My API");
});
app.UseHttpsRedirection();
app.MapGet("/weatherforecast", () =>
{
return Enumerable.Empty<WeatherForecast>();
})
.Produces<IEnumerable<WeatherForecast>>()
.WithName("GetWeatherForecasts");
app.MapPost("/weatherforecast", (WeatherForecast weatherForecast) =>
{
return weatherForecast;
})
.Produces<WeatherForecast>()
.WithName("CreateWeatherForecast");
app.Run();
public class WeatherForecast
{
public LocationDto Location { get; set; }
}
public class LocationDto
{
public AddressDto Address { get; set; }
}
public class AddressDto
{
public LocationDto RelatedLocation { get; set; }
} |
Duplicate issue: #58968 |
@martincostello Lots of additional reproductions and information in the issue @jankaltenecker just linked. It really looks like openapi is dead on arrival in dotnet9. It cannot even support quite trivial schemas given this duplication issue. |
@jankaltenecker, thanks for linking the issue. @akamor, completely agree. |
Closing in favor of #58968. See update at #58968 (comment). |
@captainsafia, Thanks Safia! |
Is there an existing issue for this?
Describe the bug
I was migrating an ASP.NET Core Web API from
.NET 8.0
to.NET 9.0
.As part of the migration, I was replacing
AddSwaggerGen()
withAddOpenApi()
and seeing this critical issue. This basically inserts duplicated schema to OpenAPI specification. Solid OpenAPI specification is critical when integrating with services like APIM and hence subject is marked with Critical.Consider the following minimal reproducible example.
csproj
Startup.cs
Program.cs
WeatherForecastController.cs
Up to here, it's pretty standard.
Now carefully review the following
WeatherForecast
type.When I run this:

Note the highlighted schema.
OpenAPI specification
Expected Behavior
Under
components.schemas
, there should be only 3 schemasSteps To Reproduce
https://github.com/jaliyaudagedara/aspnetcore-minimal-repros/tree/main/openapi-dup-schemas
Exceptions (if any)
N/A
.NET Version
9.0.200-preview.0.24575.35
Anything else?
N/A
The text was updated successfully, but these errors were encountered: