Skip to content

Commit 4483384

Browse files
OpenRewrite recipe best practices
Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.recipes.rewrite.OpenRewriteRecipeBestPractices?organizationId=QUxML01vZGVybmUvTW9kZXJuZSArIE9wZW5SZXdyaXRl Co-authored-by: Moderne <team@moderne.io>
1 parent 9e150ab commit 4483384

File tree

3 files changed

+95
-3
lines changed

3 files changed

+95
-3
lines changed

src/main/java/org/openrewrite/java/spring/SeparateApplicationYamlByProfile.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.openrewrite.java.spring;
1717

1818
import lombok.Getter;
19-
import lombok.Value;
2019
import org.openrewrite.*;
2120
import org.openrewrite.internal.ListUtils;
2221
import org.openrewrite.yaml.DeleteProperty;

src/main/java/org/openrewrite/java/spring/security5/ConvertSecurityMatchersToSecurityMatcher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
5656
J.MethodInvocation mi = super.visitMethodInvocation(method, ctx);
5757

5858
// Match antMatchers/mvcMatchers/regexMatchers whose select is requestMatchers() on HttpSecurity
59-
if ((ANT_MATCHERS.matches(mi) || MVC_MATCHERS.matches(mi) || REGEX_MATCHERS.matches(mi))
60-
&& mi.getSelect() instanceof J.MethodInvocation) {
59+
if ((ANT_MATCHERS.matches(mi) || MVC_MATCHERS.matches(mi) || REGEX_MATCHERS.matches(mi)) &&
60+
mi.getSelect() instanceof J.MethodInvocation) {
6161
J.MethodInvocation selectMi = (J.MethodInvocation) mi.getSelect();
6262
if (REQUEST_MATCHERS.matches(selectMi) && selectMi.getSelect() != null) {
6363
// Build method type for securityMatcher on HttpSecurity

src/main/resources/META-INF/rewrite/examples.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5044,6 +5044,45 @@ examples:
50445044
language: java
50455045
---
50465046
type: specs.openrewrite.org/v1beta/example
5047+
recipeName: org.openrewrite.java.spring.security5.ConvertSecurityMatchersToSecurityMatcher
5048+
examples:
5049+
- description: '`ConvertSecurityMatchersToSecurityMatcherTest#requestMatchersAntMatchersToSecurityMatcher`'
5050+
sources:
5051+
- before: |
5052+
import org.springframework.context.annotation.Bean;
5053+
import org.springframework.context.annotation.Configuration;
5054+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
5055+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
5056+
import org.springframework.security.web.SecurityFilterChain;
5057+
5058+
@Configuration
5059+
@EnableWebSecurity
5060+
class SecurityConfig {
5061+
@Bean
5062+
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
5063+
http.requestMatchers().antMatchers("/oidc/*", "/events/syncs**");
5064+
return http.build();
5065+
}
5066+
}
5067+
after: |
5068+
import org.springframework.context.annotation.Bean;
5069+
import org.springframework.context.annotation.Configuration;
5070+
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
5071+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
5072+
import org.springframework.security.web.SecurityFilterChain;
5073+
5074+
@Configuration
5075+
@EnableWebSecurity
5076+
class SecurityConfig {
5077+
@Bean
5078+
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
5079+
http.securityMatcher("/oidc/*", "/events/syncs**");
5080+
return http.build();
5081+
}
5082+
}
5083+
language: java
5084+
---
5085+
type: specs.openrewrite.org/v1beta/example
50475086
recipeName: org.openrewrite.java.spring.security5.RenameNimbusdsJsonObjectPackageName
50485087
examples:
50495088
- description: '`RenameNimbusdsJsonObjectPackageNameTest#renamePackage`'
@@ -5865,6 +5904,31 @@ examples:
58655904
language: java
58665905
---
58675906
type: specs.openrewrite.org/v1beta/example
5907+
recipeName: org.openrewrite.java.springdoc.CleanupRemainingSpringfox
5908+
examples:
5909+
- description: '`CleanupRemainingSpringfoxTest#removeOrphanedPrivateMethodsWithSpringfoxTypes`'
5910+
sources:
5911+
- before: |
5912+
import springfox.documentation.service.ApiInfo;
5913+
5914+
class SwaggerConfig {
5915+
5916+
public void publicMethod() {
5917+
}
5918+
5919+
private ApiInfo appInfo() {
5920+
return new ApiInfo("My API", "Description", "1.0", "", "", "", "");
5921+
}
5922+
}
5923+
after: |
5924+
class SwaggerConfig {
5925+
5926+
public void publicMethod() {
5927+
}
5928+
}
5929+
language: java
5930+
---
5931+
type: specs.openrewrite.org/v1beta/example
58685932
recipeName: org.openrewrite.java.springdoc.MigrateSpringdocCommon
58695933
examples:
58705934
- description: '`MigrateSpringdocCommonTest#fixCustomiserAndGroupedOpenApi`'
@@ -5914,6 +5978,35 @@ examples:
59145978
language: java
59155979
---
59165980
type: specs.openrewrite.org/v1beta/example
5981+
recipeName: org.openrewrite.java.springdoc.SpringFoxToSpringDoc
5982+
examples:
5983+
- description: '`SpringFoxToSpringDocJsonTypesTest#addTodoCommentToJsonSerializerConstructor`'
5984+
sources:
5985+
- before: |
5986+
import springfox.documentation.spring.web.json.JacksonModuleRegistrar;
5987+
import springfox.documentation.spring.web.json.JsonSerializer;
5988+
import java.util.List;
5989+
5990+
class SwaggerConfig {
5991+
5992+
public JsonSerializer jsonSerializer(List<JacksonModuleRegistrar> registrars) {
5993+
return new JsonSerializer(registrars);
5994+
}
5995+
}
5996+
after: |
5997+
import springfox.documentation.spring.web.json.JacksonModuleRegistrar;
5998+
import springfox.documentation.spring.web.json.JsonSerializer;
5999+
import java.util.List;
6000+
6001+
class SwaggerConfig {
6002+
6003+
public JsonSerializer jsonSerializer(List<JacksonModuleRegistrar> registrars) {
6004+
return /* TODO: springfox.documentation.spring.web.json types have no SpringDoc equivalent. Remove this Springfox-internal code and use Jackson ObjectMapper directly if JSON serialization is still needed. See https://springdoc.org/migrating-from-springfox.html for guidance. */ new JsonSerializer(registrars);
6005+
}
6006+
}
6007+
language: java
6008+
---
6009+
type: specs.openrewrite.org/v1beta/example
59176010
recipeName: org.openrewrite.java.springdoc.UpgradeSpringDoc_2
59186011
examples:
59196012
- description: '`UpgradeSpringDoc2Test#upgradeMaven`'

0 commit comments

Comments
 (0)