Web API OData v2 Ignore Additional Client Properties

I'm curious what options are available for me to ignore the extra property sent from the client-side user interface ( OpenUI5 ) to my internal API ( ASP.NET Web API OData v1 -3 ).


Problem

OpenUI5 always sends an additional property along with a request that calls a null parameter (where I usually had Delta<Models.Item> patch) and a BadRequest response:

{
    "error": {
        "code":"",
        "message":{
            "lang":"en-US","value":"The request is invalid."
        },
        "innererror":{
            "message":"patch : The property '__metadata' does not exist on type 'Models.Item'. Make sure to only use property names that are defined by the type.",
            "type":"",
            "stacktrace":""
        }
    }
}

(server side) /Item.cs models

public partial class Application
{
    public string Property1 { get; set; }
    public string Property2 { get; set; }
    public string Property3 { get; set; }
}

My client library HTTP MERGEonly sends with a few properties changed, so we can use the WebAPI Delta<T>.

, (. API OpenUI5 ). , (, Property1 Property2 ):

MERGE http://my-api.com/odata/Items(3)

{
    "Property1": "ABC",
    "Property2": "DEF",
    "__metadata": { 
        "id": "http://my-api.com/odata/Items(3)",
        "uri": "http://my-api.com/odata/Items(3)",
        "type": "Models.Item"
    }
}

, , __metadata. , ( OData v4) - DynamicProperties (qaru.site/questions/1626222/...). , UI5, v2.


MessageHandler, ModelBinder __metadata - - ? , MessageHandler , ModelBinder - , MERGE/PATCH, Delta<T>. ValueProvider , .

+4
1

OData, OData. _request.

var MyModel = ODataModel.extend("sap.ui.model.rest.MyModel",{
  constructor : function(sServiceUrl, mParameters) {
    ODataModel.apply(this, arguments);
  }
});
MyModel.prototype._request = function(oRequest, fnSuccess, fnError) {
  if (oRequest.data) {
    if (oRequest.data.__metadata) {
      delete oRequest.data.__metadata;
    }
  }
  return ODataModel.prototype._request.apply(this, [oRequest, fnSuccess, fnError]);
};
+1

Source: https://habr.com/ru/post/1626219/


All Articles