Skip to content
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

MergeYaml snippet recipe not working #4736

Closed
ashutoshk2206 opened this issue Dec 3, 2024 · 3 comments
Closed

MergeYaml snippet recipe not working #4736

ashutoshk2206 opened this issue Dec 3, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@ashutoshk2206
Copy link

ashutoshk2206 commented Dec 3, 2024

I am trying to use MergeYaml recipe of open-rewrite following the example shared here - https://docs.openrewrite.org/recipes/yaml/mergeyaml
But this is not working and I keep getting error mentioned below

What version of OpenRewrite are you using?

I am using

  • Maven plugin v5.46.1

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

			<plugin>
				<groupId>org.openrewrite.maven</groupId>
				<artifactId>rewrite-maven-plugin</artifactId>
				<version>5.46.1</version>
				<configuration>
					<exportDatatables>true</exportDatatables>
					<activeRecipes>
						<recipe>com.yourorg.CreateYamlFileExample</recipe>
					</activeRecipes>
				</configuration>
			</plugin>

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

Below is the content of my rewrite.yml

---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.MergeYamlExample
displayName: Merge YAML snippet example
recipeList:
  - org.openrewrite.yaml.MergeYaml:
      key: $.spec
      yaml:
        lastName: kumar
      acceptTheirs: false
      filePattern: test.yml

And this is my test.yml (where the recipe would run and make changes adding lastName: kumar at the end of the file)

apiVersion: storage.cnrm.cloud.google.com/v1beta1
kind: StorageBucket
spec:
  bucketPolicyOnly: true

What did you expect to see?

apiVersion: storage.cnrm.cloud.google.com/v1beta1
kind: StorageBucket
spec:
  bucketPolicyOnly: true
  lastName: kumar

What did you see instead?

I see below error

[INFO] Using active recipe(s) [com.yourorg.MergeYamlExample]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[ERROR] Recipe validation error in org.openrewrite.yaml.MergeYaml: Unable to load Recipe: java.lang.IllegalArgumentException: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
 at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: org.openrewrite.yaml.MergeYaml["yaml"])
[ERROR] Recipe validation errors detected as part of one or more activeRecipe(s). Execution will continue regardless.

Are you interested in contributing a fix to OpenRewrite?

@ashutoshk2206 ashutoshk2206 added the bug Something isn't working label Dec 3, 2024
@ashutoshk2206
Copy link
Author

Got it working by using yaml folded style. Can someone please confirm if the documentation needs to be corrected. I will be more than happy to open a PR.

---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.MergeYamlExample
displayName: Merge YAML snippet example
recipeList:
  - org.openrewrite.yaml.MergeYaml:
      key: $.spec
      yaml: >
        lastName: kumar
      acceptTheirs: false
      filePattern: test.yml

@timtebeek
Copy link
Contributor

Thanks for pointing that out @ashutoshk2206 ! We generate that part of the docs and it did not account for newlines, but does now. Thanks!

@ashutoshk2206
Copy link
Author

Thanks @timtebeek.
If you could fix the MarkdownGenerator for CreateYaml example as well for this PR - openrewrite/rewrite-docs#328

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

2 participants