Skip to content

Implicit "required" not applied to FromQuery parameters in Microsoft.AspNetCore.OpenAPI #63669

@sohcah

Description

@sohcah

Is there an existing issue for this?

  • 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.

[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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions