Skip to content

Commit

Permalink
Add MigrateSpringdocCommon recipe (openrewrite#633)
Browse files Browse the repository at this point in the history
* Add MigrateSpringdocCommon recipe

* Apply suggestions from bot

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Fix syntax messed up by bot

* Add MigrateSpringdocCommon recipe

* Apply suggestions from bot

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Fix syntax messed up by bot

* Fix build fail on SpringBoot_1_5

* Fix rebase error

* Move to Spring Boot 2.6 tests, to match inclusion in `spring-boot-26.yml`

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tim te Beek <[email protected]>
  • Loading branch information
3 people committed Nov 26, 2024
1 parent 309250e commit 7989d28
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ dependencies {
"testWithSpringBoot_2_5RuntimeOnly"("org.springframework.boot:spring-boot-actuator:2.5.+")
"testWithSpringBoot_2_5RuntimeOnly"("org.springframework:spring-web:5.3.+")

"testWithSpringBoot_2_6RuntimeOnly"("org.springdoc:springdoc-openapi-common:1.+")
"testWithSpringBoot_2_6RuntimeOnly"("io.swagger.core.v3:swagger-models:2.+")

"testWithSpringBoot_2_7RuntimeOnly"("org.springframework:spring-context:5.3.+")
"testWithSpringBoot_2_7RuntimeOnly"("org.springframework.boot:spring-boot-starter:2.7.+")
"testWithSpringBoot_2_7RuntimeOnly"("org.springframework.boot:spring-boot:2.7.+")
Expand Down
20 changes: 20 additions & 0 deletions src/main/resources/META-INF/rewrite/springdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ tags:
recipeList:
- org.openrewrite.java.springdoc.SwaggerToSpringDoc
- org.openrewrite.java.springdoc.ReplaceSpringFoxDependencies
- org.openrewrite.java.springdoc.MigrateSpringdocCommon

---
type: specs.openrewrite.org/v1beta/recipe
Expand Down Expand Up @@ -151,3 +152,22 @@ recipeList:
groupId: org.springdoc
artifactId: "*"
newVersion: 2.1.x

---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.springdoc.MigrateSpringdocCommon
displayName: Migrate from springdoc-openapi-common to springdoc-openapi-starter-common
description: Migrate from springdoc-openapi-common to springdoc-openapi-starter-common.
tags:
- springdoc
- openapi
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.springdoc.core.customizers.OpenApiCustomiser
newFullyQualifiedTypeName: org.springdoc.core.customizers.OpenApiCustomizer
- org.openrewrite.java.ChangeMethodName:
methodPattern: org.springdoc.core.GroupedOpenApi.Builder addOpenApiCustomiser(..)
newMethodName: addOpenApiCustomizer
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.springdoc.core.GroupedOpenApi
newFullyQualifiedTypeName: org.springdoc.core.models.GroupedOpenApi
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2024 the original author or authors.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* https://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openrewrite.java.springdoc;

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.InMemoryExecutionContext;
import static org.openrewrite.java.Assertions.java;
import org.openrewrite.java.JavaParser;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.TypeValidation;

class MigrateSpringdocCommonTest implements RewriteTest {

@Override
public void defaults(RecipeSpec spec) {
spec.recipeFromResources("org.openrewrite.java.springdoc.MigrateSpringdocCommon")
.parser(JavaParser.fromJavaVersion().classpath(
"springdoc-openapi-common-1.+",
"swagger-models-2.+"
));
}

@Test
@DocumentExample
void fixCustomiserAndGroupedOpenApi() {
// language=java
rewriteRun(
java(
"""
import io.swagger.v3.oas.models.OpenAPI;
import org.springdoc.core.GroupedOpenApi;
import org.springdoc.core.customizers.OpenApiCustomiser;
public class OpenApiConfiguration {
public static void groupedOpenApi() {
GroupedOpenApi.builder()
.group("group")
.pathsToMatch("/api/**")
.addOpenApiCustomiser(new FoobarOpenApiCustomiser())
.build();
}
public static class FoobarOpenApiCustomiser implements OpenApiCustomiser {
@Override
public void customise(OpenAPI openApi) {
}
}
}
""", """
import io.swagger.v3.oas.models.OpenAPI;
import org.springdoc.core.customizers.OpenApiCustomizer;
import org.springdoc.core.models.GroupedOpenApi;
public class OpenApiConfiguration {
public static void groupedOpenApi() {
GroupedOpenApi.builder()
.group("group")
.pathsToMatch("/api/**")
.addOpenApiCustomizer(new FoobarOpenApiCustomiser())
.build();
}
public static class FoobarOpenApiCustomiser implements OpenApiCustomizer {
@Override
public void customise(OpenAPI openApi) {
}
}
}
"""
)
);
}
}

0 comments on commit 7989d28

Please sign in to comment.