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

Extend CrudApiPlugin with JMESPath #680

Open
waldekmastykarz opened this issue Apr 28, 2024 · 5 comments
Open

Extend CrudApiPlugin with JMESPath #680

waldekmastykarz opened this issue Apr 28, 2024 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@waldekmastykarz
Copy link
Collaborator

The .NET implementation of JSONPath is limited and only allows us to do basic filtering. In comparison, using JMESPath.net we can use the full power of JMESPath including implementing more complex scenarios such as paging ($top) or changing shape of the response ($select).

Let's switch to JMESPath and update the documentation accordingly.

@waldekmastykarz waldekmastykarz added the enhancement New feature or request label Apr 28, 2024
@waldekmastykarz
Copy link
Collaborator Author

I suggest that we apply this as a breaking change so that we can remove the obsolete Newtonsoft.Json package.

@waldekmastykarz
Copy link
Collaborator Author

It seems like JMESPath and JSONPath aren't equivalent. JMESPath supports retrieving items so from CRUD, supports only R. To support CUD we need to convert the data into an object, such as Newtonsoft JArray which we've got now. Unfortunately, Newtonsoft only supports JSONPath, so we can't replace it with JMESPath. What we could do, is to keep the current functionality based on JSONPath and offer the ability to use JMESPath queries for getOne and getMany operations. It would allow users to have richer select functionality, including paging at the cost of having to write slightly different queries for R than CUD. Thoughts @garrytrinder?

@waldekmastykarz waldekmastykarz added needs discussion needs peer review Issue needs review from other team members and removed work in progress needs discussion labels May 1, 2024
@waldekmastykarz waldekmastykarz changed the title In the CrudApiPlugin replace JSONPath with JMESPath Extend CrudApiPlugin with JMESPath May 16, 2024
@garrytrinder
Copy link
Contributor

I'm not a fan of mixing concepts, to me it would feel odd constructing a query one way for one action and another way for another.

We could look into using https://github.com/jdevillard/JmesPath.Net which is a fully compliant JMESPath library that uses Newtonsoft as an alternative way of parsing and extracting items from JSON documents.

@waldekmastykarz
Copy link
Collaborator Author

We decided to:

  1. Research if we can manipulate nodes through AST
  2. If 1 is not possible, we'll introduce a new configuration property named advancedQuery that overrides whatever is specified in the query property and uses JMESPath to describe the query

@waldekmastykarz waldekmastykarz removed the needs peer review Issue needs review from other team members label May 22, 2024
@waldekmastykarz
Copy link
Collaborator Author

It turns out that AST only applies to expressions not JSON. While the parser supports JTokens, this way of work is deprecated and the returned nodes are disconnected from the source document so it's not suitable for what we need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants