joukevandermaas / saule

JSON API library for ASP.Net Web API 2.
https://joukevandermaas.github.io/saule
MIT License
76 stars 37 forks source link

When I have parameter [FromBody] I get status code 400 no content #166

Closed tomasjurasek closed 7 years ago

tomasjurasek commented 7 years ago

Hi,

I have simple controller method like this:

        [HttpPost]
        [Route("test")]
        [ReturnsResource(typeof(TestModelResource))]
        public async Task<TestViewModel> Test([FromBody] TestViewModel model)
        {
            return new TestViewModel();
        }

ResourceModel

  public class TestModelResource : ApiResource
    {
        public TestModelResource()
        {
            WithId(nameof(TestViewModel.Id));
            Attribute(nameof(TestViewModel.Name));
        }
    }

I get 400 status no content. But if I set attribute [FromUri], it works. Its a bug? I need [FromBody]

Thanks Tomas

tomasjurasek commented 7 years ago

When I set Content-Type: application/vnd.api+json image

joukevandermaas commented 7 years ago

I think [FromBody] does some weird stuff sometimes. Have you tried without any attribute on the parameter?

tomasjurasek commented 7 years ago

I tried it, but the same issue. Here is screen from swagger: image

Postman has the same issue 400(Invalid JSON API request content)

joukevandermaas commented 7 years ago

But that is not valid JSON API content. It should be like:

{
  "data": {
    "id": "22",
    "type": "mymodel",
    "attributes": {
      "name": "string"
    }
  }
}