class Foo
{
[Required]
public string Bar { get; set; }
}
... with a DTO like this ...
class Result<T>
{
public T Item { get; set; }
public bool Success { get; set; }
public string Message { get; set; }
}
... then an OData Action on my controller like this ...
public IActionResult Validate(Foo foo) => Ok(Validate(foo));
I'd like to be able to ask the API "is this instance of a Foo valid?".
The Current Result
In the event that the Foo instance given is not valid the serialization fails in the OData framework after all my code has run and constructed a "valid" Result with the invalid Foo instance in it and a reason why it's invalid (e.g. "Bar was null").
The reuslting failure in the serialization stops the process at the point of a bad property value and so the client receives a repsonse fragment instead of a complete response.
My Preference (expected result)
The more complex real world issue I have with this is when I'm performing "set operations" on a collection of items provided in the body of my post some of which "might be invalid" and I need to inform the caller of the failures on that subset whilst correctly returning a 200 response for the overall call for the successful ones as a IEnumerable<Result> in that scenario.
Summary
If this is considered to be in some way "non standard" or something the ability to mark with an attribute on the action method in the controller that it might return invalid data would be a good way to selective state in metadata that this action may behave in a non-standard way.
That said, I can't find anything in the OData standards that state that the server MUST return data that is valid other than structurally speaking (which I would expect to still fail as it currently does.)
The Scenario
lets say I have an entity like this ...
... with a DTO like this ...
... then an OData Action on my controller like this ...
I'd like to be able to ask the API "is this instance of a Foo valid?".
The Current Result
In the event that the Foo instance given is not valid the serialization fails in the OData framework after all my code has run and constructed a "valid" Result with the invalid Foo instance in it and a reason why it's invalid (e.g. "Bar was null").
The reuslting failure in the serialization stops the process at the point of a bad property value and so the client receives a repsonse fragment instead of a complete response.
My Preference (expected result)
The more complex real world issue I have with this is when I'm performing "set operations" on a collection of items provided in the body of my post some of which "might be invalid" and I need to inform the caller of the failures on that subset whilst correctly returning a 200 response for the overall call for the successful ones as a IEnumerable<Result> in that scenario.
Summary
If this is considered to be in some way "non standard" or something the ability to mark with an attribute on the action method in the controller that it might return invalid data would be a good way to selective state in metadata that this action may behave in a non-standard way. That said, I can't find anything in the OData standards that state that the server MUST return data that is valid other than structurally speaking (which I would expect to still fail as it currently does.)