openrewrite / openrewrite/rewrite-spring
ChangeSpringPropertyKey incorrectly copies top level comments and does not preserve initial format for yml property files
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 403
- Forks
- 149
- Avg merge
- 2h 33m
- Merged PRs (30d)
- 10
Description
We noticed a few issues with org.openrewrite.java.spring.ChangeSpringPropertyKey recipe pertaining to YAML config files.
- YAML structure is not preserved and rewritten properties are added as single line format.
- Comments are incorrectly copied for multi-document yaml files. See example below
I tested using the following recipes to rewrite 2 properties.
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: spring.sleuth.enabled
newPropertyKey: management.tracing.enabled
- org.openrewrite.java.spring.ChangeSpringPropertyKey:
oldPropertyKey: spring.sleuth.sampler.probability
newPropertyKey: management.tracing.sampling.probability
Application config before apply ChangeSpringPropertyKey recipe
# comment 1
spring:
application:
name: testapp
sleuth:
sampler:
probability: 0.1
enabled: true
---
# overrides for staging
spring:
config:
activate:
on-profile: staging
sleuth:
sampler:
probability: 1.0
Application config after applying ChangeSpringPropertyKey recipe. As we can see the original format is not preserved causing the order of the properties to be appended to the end of the document. Also for multi-document sections, it incorrectly copies top level comments to the rewritten property.
# comment 1
spring:
application:
name: testapp
management.tracing.enabled: true
management.tracing.sampling.probability: 0.1
---
# overrides for staging
spring:
config:
activate:
on-profile: staging
# overrides for staging
management.tracing.sampling.probability: 1.0
--------- Expected Behavior ------------------
- original YAML format is preserved
- Multi-document sections have consistent property copying logic
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 the org.openrewrite.java.spring.ChangeSpringPropertyKey recipe and reproduce the two property rewrites against the YAML example in this issue. Compare the before and after documents; done means nested YAML structure and original formatting are preserved, with top-level comments not duplicated across multi-document sections.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100