Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Optional body parameters no longer work since upgrading to .NET Core 2.0 #6920

@ben-foster-cko

Description

@ben-foster-cko

I have an action filter that automatically checks ModelState and returns 400 if it's not valid.

We have a few actions that have optional body parameters, for example:

        // POST api/values
        [HttpPost]
        public IActionResult Post([FromBody]SomeClass request = null)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            return Ok();
        }

Specifying the default value of null used to be enough to mark them as optional. Since upgrading to ASP.NET Core 2.0 I get the following response:

{
  "": [
    "A non-empty request body is required."
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions