Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation to handle sanitization of field names in open types #1269

Open
marcus905 opened this issue Jun 25, 2024 · 3 comments
Open

Annotation to handle sanitization of field names in open types #1269

marcus905 opened this issue Jun 25, 2024 · 3 comments
Assignees

Comments

@marcus905
Copy link

marcus905 commented Jun 25, 2024

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.

@marcus905 marcus905 added the bug Something isn't working label Jun 25, 2024
@xuzhg xuzhg self-assigned this Jun 25, 2024
@xuzhg xuzhg added followup feature and removed bug Something isn't working labels Jun 25, 2024
@xuzhg
Copy link
Member

xuzhg commented Jul 1, 2024

Can you create a class implementing the 'IDictionary<string, object>' interface and add the verification codes within the interface method?

@marcus905
Copy link
Author

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.

@xuzhg
Copy link
Member

xuzhg commented Jul 1, 2024

@marcus905 We love to see your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants