-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Admin API v2] PoC for a field projection mechanism #41128
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
base: feature/admin-api-v2
Are you sure you want to change the base?
[Admin API v2] PoC for a field projection mechanism #41128
Conversation
|
Currently I use the query parameter |
562be58 to
aadbf3f
Compare
|
@thomasdarimont Can you please rebase? |
vmuzikar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall IMHO this approach makes sense.
Just to note, this purely benefits the network/client side, not the server side as we're still fetching all fields (which might underneath do some unnecessary JOINs, etc.). But wa could quite easily detect the fields in the query param and reflect them when fetching from the model, if needed.
3266164 to
057eeb4
Compare
|
I rebased the branch as discussed. |
266bb90 to
d207105
Compare
|
@thomasdarimont Sorry, another rebase is needed. |
mabartos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomasdarimont Looks good to me from the first sight.
Just a consideration:
- We could even support to exclude some fields as providing
fields=!clientId,!authwould return the whole representation without theclientIdandauthfields.
WDYT?
02245d9 to
17e8407
Compare
The projection works on the Jackson ObjectMapper level and uses a SimpleBeanPropertyFilter (FieldProjectionFilter) to control the properties during JSON marshalling. Consumers can select the desired result fields with a `fields` query parameter. Note that the selection only works with top-level object properties. There is currently no support for nested property selection. Currently, all representations inheriting from BaseRepresentation support this filtering via the JsonFilter annotation. JAX-RS resource methods which declare a `@QueryParam(Projections.PARAM) Projections projections` become eligible for projections. The explicit parameter declaration ensures that the projection parameter can be inferred for the OpenAPI metadata. A request without the fields parameter will return the full resource: ``` curl -v -H "Authorization: Bearer $KC_ACCESS_TOKEN" \ http://localhost:8081/auth/admin/api/v2/realms/adminapiv2/clients/custom-client1 | jq -C ``` A request with the included filter: ``` curl -v -H "Authorization: Bearer $KC_ACCESS_TOKEN" \ http://localhost:8081/auth/admin/api/v2/realms/adminapiv2/clients/custom-client1?fields=clientId,displayName ``` Will only return the selected fields. Signed-off-by: Thomas Darimont <[email protected]> (cherry picked from commit 3266164) (cherry picked from commit 057eeb4)
057eeb4 to
3aa72d8
Compare
Specifying exclusions via |
|
@thomasdarimont I would say it is either all included fields or all excluded fields but not a combination of both. |
|
I am wondering if the projection mechanism actually means all fields become optional in the OpenAPI spec (at least when reading from the server). |
PoC for a field selection / projection mechanism
The projection works on the Jackson ObjectMapper level and uses a SimpleBeanPropertyFilter (FieldProjectionFilter) to control the properties during JSON marshalling. Consumers can select the desired result fields with a
fieldsquery parameter. Note that the selection only works with top-level object properties. There is currently no support for nested property selection.Currently, all representations inheriting from BaseRepresentation support this filtering via the JsonFilter annotation.
JAX-RS resource methods which declare a
@QueryParam(Projections.PARAM) Projections projectionsbecome eligible for projections.The explicit parameter declaration ensures that the projection parameter can be inferred for the OpenAPI metadata.
A request without the fields parameter will return the full resource:
A request with the included filter:
will only return the selected fields.
Yields:
[ { "clientId": "account" }, { "clientId": "account-console" }, { "clientId": "admin-api" }, { "clientId": "admin-cli" }, { "clientId": "broker" }, { "clientId": "custom-client1" }, { "clientId": "realm-management" }, { "clientId": "security-admin-console" } ]