8000 shows what patching logic should look like by shawkins · Pull Request #40450 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

shows what patching logic should look like - #40450

Merged
vmuzikar merged 2 commits into
keycloak:feature/admin-api-v2from
shawkins:v2-patch
Jun 25, 2025
Merged

vmuzikar merged 2 commits into
keycloak:feature/admin-api-v2from
shawkins:v2-patch

Conversation

@shawkins
@shawkins shawkins commented Jun 12, 2025 •
Copy link
Copy Markdown
Contributor

also shows basic field validation

Reopening against the right branch...

@vmuzikar @mabartos @Pepo48 this shows roughly what json merge patch support looks like - there is very little we need to do as Jackson has support already baked in. There are several TODOs - moving field validation to a common spot, using a common objectmapper, agreeing on the response codes, etc.

The server side method to allow for other patch types has the payload typed as JsonNode (if that doesn't work, then we'd just use String).

From a rest client perspective you could have a typed method. The user will do something like:

ClientRepresentation rep = new ClientRepresentation();
rep.setEnabled(false);
rep.setAdditionalField("description", null); // remove description

clients.getClient("id").patchClient(rep, FieldValidation.Strict);

@mabartos suggested adding a convienence method instead of using a direct put - we can certainly do that. In general we'll need to make sure the additional field stuff is well documented as to when / why you would do that. For all the known fields you can even regular methods like "rep.unsetDescription()" as was shown in the defaults pr. However we still do need to expose the general map / set method for additional scenarios.

From the initial / incorrect pr:

Is there any intention to store metadata in the additional fields?

No. At this point it is strictly for cross-version compatibility and for having a typed object model for creating json merge patches that can remove values. If we want a general metadata facility, like ObjectMeta in Kuberentes, that would need to be it's own construct and properly stored.

also shows basic field validation

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
@vmuzikar vmuzikar added the team/admin-api-wg Admin API v2 Working Group label Jun 13, 2025
@PUT
@Consumes("application/merge-patch+json")
@Produces(MediaType.APPLICATION_JSON)
ClientRepresentation patchClient(JsonNode patch, @PathParam("fieldValidation") FieldValidation fieldValidation);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field validation might need a better name not to be confused with regular validations (from semantic perspective etc.). Possibly something like unknownFieldsPolicy but not sure.

Also should we really give the power to set this policy to the user? Shouldn't it rather be a global server option? In other words, do we really want to set this per request?

@shawkins shawkins Jun 16, 2025 •
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field validation might need a better name not to be confused with regular validations (from semantic perspective etc.)

It is possible to tie this to "optional" semantic validation - for example in kubernetes the handling of the StatefulSet serviceName - it is not required unless fieldValidation=Strict.

Possibly something like unknownFieldsPolicy but not sure.

Yes the naming can be whatever we want.

Also should we really give the power to set this policy to the user? Shouldn't it rather be a global server option? In other words, do we really want to set this per request?

You would probably want control per request yes. You can certainly make a case for session or server level control as well.

@vmuzikar vmuzikar Jun 24, 2025 •
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the naming can be whatever we want.

Thinking about that more, maybe fieldNameValidation would be better? WDYT?

You would probably want control per request yes. You can certainly make a case for session or server level control as well.

Ok. We can add the server level one as a follow-up.

if (!allowUpdate) {
throw new ServiceException("Client already exists", Response.Status.CONFLICT);
}
// TODO: make sure that removal is the best way to do this
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably not. Just from the top of my head, we might accidentally delete some entities with foreign keys. But there might be more caveats.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as the overlay of the model state is complete, we won't need to use a delete - based upon the current mapper prototype there will need to be some changes to support that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. But we can tackle that as a follow-up.

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
@shawkins
Copy link
Copy Markdown
Contributor Author

@vmuzikar made some initial updates based upon the reivew. I'll see about starting some kind of unit / integration tests as well.

@vmuzikar
Copy link
Copy Markdown
Contributor

made some initial updates based upon the reivew.

Thanks.

I'll see about starting some kind of unit / integration tests as well.

Do you want to address it in this PR, or in a follow-up. If the former, we can merge from my PoV.

@shawkins
shawkins marked this pull request as ready for review June 25, 2025 12:39
@shawkins
shawkins requested a review from a team as a code owner June 25, 2025 12:39
@shawkins
Copy link
Copy Markdown
Contributor Author

Do you want to address it in this PR, or in a follow-up. If the former, we can merge from my PoV.

Sorry, I haven't gotten to this yet. Let's go ahead an merge so that we don't have more conflicts later.

@vmuzikar
vmuzikar merged commit 48e5e73 into keycloak:feature/admin-api-v2 Jun 25, 2025
mabartos pushed a commit to mabartos/keycloak that referenced this pull request Jul 11, 2025
* shows what patching logic should look like

also shows basic field validation

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

* updates based upon review comments

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

---------

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
mabartos pushed a commit that referenced this pull request Jul 22, 2025
* shows what patching logic should look like

also shows basic field validation

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

* updates based upon review comments

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

---------

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
mabartos pushed a commit that referenced this pull request Aug 5, 2025
* shows what patching logic should look like

also shows basic field validation

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

* updates based upon review comments

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

---------

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
mabartos pushed a commit that referenced this pull request Sep 5, 2025
* shows what patching logic should look like

also shows basic field validation

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

* updates based upon review comments

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

---------

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
vmuzikar pushed a commit to vmuzikar/keycloak that referenced this pull request Oct 14, 2025
* shows what patching logic should look like

also shows basic field validation

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

* updates based upon review comments

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

---------

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
vmuzikar pushed a commit to vmuzikar/keycloak that referenced this pull request Nov 3, 2025
* shows what patching logic should look like

also shows basic field validation

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

* updates based upon review comments

Signed-off-by: Steve Hawkins <shawkins@redhat.com>

---------

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team/admin-api-wg Admin API v2 Working Group

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0