Skip to content

[Bug]: Required nested properties are marked required even if outer property is optional #3534

@drauch

Description

@drauch

Describe the bug

Consider the following model:

public record Model ( Inner? inner, [Required] string other );
public record Inner ( [Required] string prop );

The model is used in an ASP.NET Core action like this:

public IActionResult MyAction ( [FromForm, Required] Model model )

It translates the nested models to a flattened representation of dot-concatenated properties, i.e., inner.prop - unfortunately, this property is set to required which is not true.

Expected behavior

The property should be optional.

Actual behavior

The property is marked as required.

Steps to reproduce

See description.

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

8

.NET Version

8

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp-wantedA change up for grabs for contributions from the community

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions