openrewrite / openrewrite/rewrite
ChangePropertyKey does not construct nested YAML structure, inserts flat keys instead
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.7k
- Forks
- 570
- Avg merge
- 13h 12m
- Merged PRs (30d)
- 261
Description
What version of OpenRewrite are you using?
I am using rewrite - v8.47.4
What is the smallest, simplest way to reproduce the problem?
@Test
void test() {
rewriteRun(
spec -> spec.recipe(new ChangePropertyKey(
"management.server.accesslog.prefix",
"management.server.jetty.accesslog.prefix",
true,
null,
null
)),
yaml(
"""
management:
server:
accesslog:
prefix: logs
""",
"""
management:
server:
jetty:
accesslog:
prefix: logs
""",
spec -> spec.path("src/main/resources/application.yml")
)
);
}
We encountered an issue when using org.openrewrite.yaml.ChangePropertyKey to move keys in a .yaml file. The expected behavior is for the recipe to move a YAML block and construct a proper nested structure. However, it results in a flat key instead of creating a properly nested YAML hierarchy.
Input YAML:
management:
server:
accesslog:
prefix: logs
What did you expect to see?
management:
server:
jetty:
accesslog:
prefix: logs
What did you see instead?
management:
server:
jetty.accesslog.prefix: logs
Analysis:
Looking closely at the implementation of org.openrewrite.yaml.ChangePropertyKey, the issue appears to be with the behavior of the InsertSubpropertyVisitor.
The subproperty is being treated as a literal scalar key — the InsertSubpropertyVisitor does not split the subproperty key (e.g., jetty.accesslog.prefix) into nested keys based on the dots (.). This results in a flat key rather than a properly nested structure.
Are you interested in contributing a fix to OpenRewrite?
Yes, I would be happy to give it a try with some guidance or feedback from the maintainers.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with rewrite-yaml/src/main/java/org/openrewrite/yaml/ChangePropertyKey.java, especially InsertSubpropertyVisitor around lines 234-313. Use the supplied rewriteRun example and YAML input as the regression case. Done means changing the property key produces nested jetty, accesslog, and prefix mappings rather than the flat jetty.accesslog.prefix key.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100