OData / OData/AspNetCoreOData

Feature ask: Need the have ability to set custom query validator into SelectExpandQueryValidator

Open
#767 0 comments 0 reactions 1 assignee View on GitHub

@xuzhg is already working on this.

Since Dec 13, 2022.

  • #795 by @xuzhg — merged
bug
Dominant language
C#
Stars
505
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Assemblies affected
Which assemblies and versions are known to be affected e.g.: ASP.NET Core OData 8.x

Describe the bug
@xuzhg, based on our discussion, I am just listing three issues which I hope we can improve:

  1. Can't set custom query validator into SelectExpandQueryValidator, e.g.: The construct directly create the FilterQueryValidator, rather than expose as parameter, so customer can use DI or explicitly set it. Source code link.
  2. Even SelectExpandQueryValidator allow us pass custom FilterQueryValidator via constructor, it will still not work due to the current code does some kind of hack) to create an internal virtual method to allow SelectExpandQueryValidator to set local properties like defaultValidationSetting. So even I create my custom filter query validator, I still can't set these fields and it will cause null reference issue eventually.
  3. In the current FilterQueryValidator, if customer doesn't register EDM model, the validation will not honor the model bound filter attribute due to we don't set property and structured type if no ODataPath, source code is [here](https://github.com/OData/AspNetCoreOData/blob/3db5e5fb94df2968b1b354bc37a47907b89892be/src/Microsoft.AspNetCore.OData/Query/Validator/FilterQueryValidator.cs#:~:text=if%20(filterQueryOption.,%7D), but if people use filter under expand clause, then the model bound filter attribute start working due to it invoke the hacky internal method which I mentioned in 2nd issue, and the internal method will set the property and structured type based on navigation property. So, it is not consistent.

Reproduce steps
The simplest set of steps to reproduce the issue. If possible, reference a commit that demonstrates the issue.

Data Model
Please share your Data model, for example, your C# class.

EDM (CSDL) Model
Please share your Edm model, for example, CSDL file.
You can send $metadata to get a CSDL XML content.

Request/Response
Please share your request Uri, head or the request body
Please share your response head, body.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Please share your call stack or any error message
Add any other context about the problem here.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.