-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
OpenAPI documentation is incorrect when using custom TryParse() binding with Minimal APIs #58318
Comments
@marcominerva Thanks for filing this issue! I believe that this was a regression that was introduced in the model binding layer in this commit although I'll have to debug a little further. I'm a little surprised that our AddsFromRouteParameterAsPathWithCustomClassWithTryParse test didn't catch this although the actual issue might be something else. It seems like you also reproed this with .NET 9 and Swashbuckle? If so, that would point more towards it being an ApiExplorer problem as opposed to a something in the |
Yes @captainsafia, it seems that the issue happens also with the latest version of Swashbuckle.AspNetCore: domaindrivendev/Swashbuckle.AspNetCore#3105. Thank you for your support! |
@captainsafia I noticed that the issue is solved only if I don't use // Will correcly report a student as a query string parameter
app.MapPost("/enroll", (Student student) => Results.NoContent());
// Will report a student as a query string parameter and as the request body
app.MapPost("/enroll-withaccepts", (Student student) => Results.NoContent())
.Accepts<Student>("application/json");
// Will correctly report the parameter as a string
app.MapGet("/student/{student}", (Student student) => $"Hi {student.Name}");
// Will correctly report the parameter as a string and a the request body
app.MapGet("/student-withaccepts/{student}", (Student student) => $"Hi {student.Name}")
.Accepts<Student>("application/json");
app.Run();
public record Student(string Name)
{
public static bool TryParse(string value, out Student? result)
{
if (value is null)
{
result = null;
return false;
}
result = new Student(value);
return true;
}
} I have updated the repo at https://github.com/marcominerva/TryParseOpenApiIssue with this new scenarios. |
Is there an existing issue for this?
Describe the bug
I have used the same title of #36412 because the same issue happens today using the new OpenAPI documentation generator that is built-in in .NET 9.0.
With this code:
OpenAPI documentation is wrongly created as the following:
Expected Behavior
Parameters that use a
TryParse
custom binding should be configured as string in theopenapi/v1.json
file:Steps To Reproduce
Minimal repro: https://github.com/marcominerva/TryParseOpenApiIssue
Exceptions (if any)
No response
.NET Version
9.0.0-rc.2.24474.3
Anything else?
No response
The text was updated successfully, but these errors were encountered: