openrewrite / openrewrite/rewrite-spring

DeleteSpringProperty - glob / properties with children don't work as expected

Open
#582 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
403
Forks
149
Avg merge
2h 33m
Merged PRs (30d)
10

Description

What version of OpenRewrite are you using?

I am using main

How are you running OpenRewrite?

unit tests

What is the smallest, simplest way to reproduce the problem?

    @Test
    void deleteParentProperty_properties() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie")),
          //language=properties
          properties(
            """
              some=value
              server.servlet.session.cookie.name=fred
              server.servlet.session.cookie.path=/cookie-monster
              other=value
              """,
            """
              some=value
              other=value
              """
          )
        );
    }

    @Test
    void deleteParentProperty_yaml() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie")),
          //language=yaml
          yaml(
            """
              some: value
              server:
                servlet:
                  session:
                    cookie:
                      name: fred
                      path: /cookie-monster
              other: value
              """,
            """
              some: value
              other: value
              """
          )
        );
    }

    @Test
    void deleteParentProperty_yamlCoalesced() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie")),
          //language=yaml
          yaml(
            """
              some: value
              server.servlet.session.cookie.name: fred
              server.servlet.session.cookie.path: /cookie-monster
              other: value
              """,
            """
              some: value
              other: value
              """
          )
        );
    }

    @Test
    void deleteParentPropertyViaGlob_properties() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie.*")),
          //language=properties
          properties(
            """
              some=value
              server.servlet.session.cookie.name=fred
              server.servlet.session.cookie.path=/cookie-monster
              other=value
              """,
            """
              some=value
              other=value
              """
          )
        );
    }

    @Test
    void deleteParentPropertyViaGlob_yaml() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie.*")),
          //language=yaml
          yaml(
            """
              some: value
              server:
                servlet:
                  session:
                    cookie:
                      name: fred
                      path: /cookie-monster
              other: value
              """,
            """
              some: value
              other: value
              """
          )
        );
    }

    @Test
    void deleteParentPropertyViaGlob_yamlCoalesced() {
        rewriteRun(
          spec -> spec.recipe(new DeleteSpringProperty("server.servlet.session.cookie.*")),
          //language=yaml
          yaml(
            """
              some: value
              server.servlet.session.cookie.name: fred
              server.servlet.session.cookie.path: /cookie-monster
              other: value
              """,
            """
              some: value
              other: value
              """
          )
        );
    }

What did you expect to see?

one of those two sets of tests (either using glob or not using glob) to pass, given that the recipe advertises glob support:

@Option(displayName = "Property key",
        description = "The property key to delete. Supports glob expressions",
        example = "management.endpoint.configprops.*")
    String propertyKey;

What did you see instead?

A mix of success and failure for both approaches:

  • fail: deleteParentProperty_properties
  • pass: deleteParentProperty_yaml
  • fail: deleteParentProperty_yamlCoalesced
  • pass: deleteParentPropertyViaGlob_properties
  • fail: deleteParentPropertyViaGlob_yaml
  • fail: deleteParentPropertyViaGlob_yamlCoalesced

What is the full stack trace of any errors you encountered?

no stack traces; failing test cases all failed with no changes

Are you interested in contributing a fix to OpenRewrite?

I think if we go fix #581, then for this issue we could mostly port the "targeting" logic over from ChangeSpringPropertyKey.
and similar to 581, I've got some time this week and will probably play with it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the six deleteParentProperty and deleteParentPropertyViaGlob tests shown in the issue, then inspect DeleteSpringProperty and compare its targeting behavior with ChangeSpringPropertyKey. Done means the properties and YAML cases, including coalesced keys and glob patterns, produce the expected output without changes left behind.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.