8000 task: better document property mapping by shawkins · Pull Request #40873 · keycloak/keycloak · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

task: better document property mapping #40873

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

shawkins
Copy link
Contributor
@shawkins shawkins commented Jul 2, 2025

closes: #40872

@mabartos this isn't quite a diagram, but it might be helpful. Additionally, more javadocs could be added to the builder methods.

closes: keycloak#40872

Signed-off-by: Steve Hawkins <shawkins@redhat.com>
Comment on lines +102 to +118
/**
* This is the heart of the property mapping logic. In preference order we are looking for:
* <ul>
* <li>the "from" value (the property is directly specified)
* <li>the mapFrom (the property is inferred from another value)
* <li>the default
* </ul>
*
* <p>
* If we did not find a value, we simply move on in the interceptor chain.
* <p>
* If we found a value, it needs to be transformed via {@link #transformValue(String, ConfigValue, ConfigSourceInterceptorContext, boolean)}. If the mapFrom value is being used or the name matches "to", the
* either the parentMapper (from {@link PropertyMapper.Builder} mapFrom methods), or the mapper (from {@link PropertyMapper.Builder} transformer methods) is applied.
* <p>
* Finally the returned {@link ConfigValue} is made to match what was requested - with the name, value, rawValue, and ordinal set appropriately.
* <p>
*/
Copy link
Contributor
@mabartos mabartos Jul 3, 2025

Choose a reason for hiding this comment

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

8000

@shawkins Thanks for creating this PR!

Suggested change
/**
* This is the heart of the property mapping logic. In preference order we are looking for:
* <ul>
* <li>the "from" value (the property is directly specified)
* <li>the mapFrom (the property is inferred from another value)
* <li>the default
* </ul>
*
* <p>
* If we did not find a value, we simply move on in the interceptor chain.
* <p>
* If we found a value, it needs to be transformed via {@link #transformValue(String, ConfigValue, ConfigSourceInterceptorContext, boolean)}. If the mapFrom value is being used or the name matches "to", the
* either the parentMapper (from {@link PropertyMapper.Builder} mapFrom methods), or the mapper (from {@link PropertyMapper.Builder} transformer methods) is applied.
* <p>
* Finally the returned {@link ConfigValue} is made to match what was requested - with the name, value, rawValue, and ordinal set appropriately.
* <p>
*/
/**
* This is the heart of the property mapping logic. In the first step, we need to find the value of the property and then transform it into a form of our needs.
* <p>
*
* <b>1. Find value</b>
* <p>
* In preference order we are looking for:
* <pre>
* [ {@link #from} ] ---> [ {@link #mapFrom} ] ---> [ default ] ---> [try other external]
* (explicit) (derived) (fallback)
* </pre>
* <ul>
* <li>the {@link #from} value (the property is directly specified)
* <li>the {@link #mapFrom} value (the property is inferred from another value)
* <li>the default
* <li>If we did not find a value, we simply move on in the interceptor chain.
* </ul>
* <p>
*
* <b>2. Transform found value</b>
* <p>
* If we found a value for the attribute name, it needs to be transformed via {@link #transformValue} method. How to transform it?
* <pre>
* [ name = {@link #from} ? ] ---> [ name = {@link #to} ? ] ---> [ value from parent ? ]
* | y | y | y
* | | |
* value transform(value) parent.transform(value)
* </pre>
* <ul>
* <li>If the name matches {@link #to}, we use the {@link #mapper} from the {@link PropertyMapper.Builder#transformer} method.
* <li>If we found the value on the parent side ({@link #mapFrom}), we use the {@link #parentMapper} specified either via {@link PropertyMapper.Builder#mapFrom(Option, ValueMapper)} method or parent's {@link PropertyMapper.Builder#transformer} method.
* </ul>
* <p>
* Finally the returned {@link ConfigValue} is made to match what was requested - with the name, value, rawValue, and ordinal set appropriately.
*/

I took it a little bit further to provide at least some illustration of the process to make it more understandable.

Here how it looks like in my IDE with all these formatting:

image

@shawkins WDYT? And please check if the info is valid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks good, but I'd say that the transformValue logic would be better described as:

if name == from || value from parent then apply applicable mapper

Alternatively it might be better to just refer to that method here and add some docs there.

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

Successfully merging this pull request may close these issues.

Better document property mapping
2 participants
0