Annotation to handle sanitization of field names in open types
Opened this issue · 3 comments
Assemblies affected
ASP.NET Core OData 8.x
Describe the bug
There is no way to handle special characters if present in dynamic properties in OData, causing:
"The property name '01.01' is invalid; property names must not contain any of the reserved characters ':', '.', '@'."
Reproduce steps
in an IDictionary<string, object>, if the key contains a special character, on read it throws this error
Data Model
class Test {
public string Id{ get; set; }
//extradata
public IDictionary<string, object> ExtraData { get; set; }
}
EDM (CSDL) Model
<edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<edmx:DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="RY.Models">
<EntityType Name="Test" OpenType="true">
<Key>
<PropertyRef Name="Id"/>
</Key>
<Property Name="Id" Type="Edm.String" Nullable="false"/>
</EntityType>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Request/Response
N/A
Expected behavior
There needs to be, for the open type annotation, a way to specify that non-compliant field names must be sanitized before sending them out.
Can you create a class implementing the 'IDictionary<string, object>' interface and add the verification codes within the interface method?
I probably can, but I shouldn't have to. It's a specification of a format and in my opinion it's expected for the library to have a facility to do that in open types where there is no other way to do that (besides your option probably, but that means reinventing a lot of the whole wheel). Having the option in the library instead would be way easier to implement, probably just a few lines of code.
If you want, I can try to provide a pull request. Tell me if you'd accept it, though, else it'd be wasted work.
My solve has been a view in the source DB to fix this, currently.
@marcus905 We love to see your contribution.