Implicit "required" not applied to FromQuery parameters in Microsoft.AspNetCore.OpenAPI
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
In a controller-based API project, having a `[FromQuery] MyClass request` parameter on a method will not have it's parameters labelled as `"required": true` in the generated OpenAPI Schema - even though it will fail model validation if that parameter is not required.
```cs
[ApiController]
[Route("[controller]")]
public class MyController : ControllerBase
{
[HttpGet]
public IActionResult Get([FromQuery] MyClass request)
{
// ...
}
}
public class MyClass {
public required string City { get; init: ]
}
```
### Expected Behavior
Parameters in an OpenAPI Schema should have `"required": true` when they are required in model binding.
### Steps To Reproduce
https://github.com/sohcah/openapi-parameter-bug
Information in the README.md
### Exceptions (if any)
_No response_
### .NET Version
10.0.100-rc.1.25451.107
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.