OData / WebApi

OData Web API: A server library built upon ODataLib and WebApi
https://docs.microsoft.com/odata
Other
853 stars 476 forks source link

Case sensitivity of request bodies in OData #1677

Open jimmy3912msncom opened 5 years ago

jimmy3912msncom commented 5 years ago

I followed the instructions on https://blogs.msdn.microsoft.com/odatateam/2018/07/03/asp-net-core-odata-now-available/ exactly and noticed that when exercising one of the cases to create a book, when I sent a request body with the CLR casing of a property name like "Id" it worked fine but if I changed it to "id" it wouldn't work. Is there a way to allow case insensitivity for request bodies?

Assemblies affected

I am using the packages referenced in the example posted in https://blogs.msdn.microsoft.com/odatateam/2018/07/03/asp-net-core-odata-now-available/ except the version of Microsoft.AspNetCore.OData is 7.0.1 vs 7.0.0.

<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="7.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.1.4" />

Reproduce steps

  1. Follow the instructions to setup your project from https://blogs.msdn.microsoft.com/odatateam/2018/07/03/asp-net-core-odata-now-available/
  2. Make a request to create a book like so and it will work:
    
    POST http://localhost:5000/odata/Books
    Content-Type: application/json

{ "Id":10, "ISBN":"82-917-7192-5", "Title":"Hary Potter", "Author":"J. K. Rowling", "Price":199.99, "Location":{ "City":"Shanghai", "Street":"Zhongshan RD" } }

3. Now make a request to create a book with the casing slightly differently like this:

POST http://localhost:5000/odata/Books Content-Type: application/json

{ "id":11, "iSBN":"82-917-7192-5", "ritle":"Hary Potter", "author":"J. K. Rowling", "price":199.99, "location":{ "city":"Shanghai", "street":"Zhongshan RD" } }


### Expected result

I would expect this to work

### Actual result

It fails. In the controller the book is null and the ModelState is invalid with the exception message "Does not support untyped value in non-open type."

### Additional detail
raheph commented 5 years ago

@jimmy3912msncom So far, ODL doesn't support case insensitive in the payload content. Does the model alias work for you?

jimmy3912msncom commented 5 years ago

@raheph Can you explain further what you mean by model alias?

jimmy3912msncom commented 5 years ago

Also the interesting thing is this seems to only apply for non-function and non-action methods as those work fine to be case-insensitive. not sure why it is case-sensitive for routes that take in entities