diff --git a/build.gradle.kts b/build.gradle.kts index f11125d0e..d9bde17bb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -113,18 +113,20 @@ recipeDependencies { val rewriteVersion = rewriteRecipe.rewriteVersion.get() dependencies { - implementation("org.openrewrite:rewrite-java:${rewriteVersion}") - implementation("org.openrewrite:rewrite-xml:${rewriteVersion}") - implementation("org.openrewrite:rewrite-properties:${rewriteVersion}") - implementation("org.openrewrite:rewrite-yaml:${rewriteVersion}") - implementation("org.openrewrite:rewrite-gradle:${rewriteVersion}") - implementation("org.openrewrite:rewrite-maven:${rewriteVersion}") + implementation(platform("org.openrewrite:rewrite-bom:${rewriteVersion}")) + implementation("org.openrewrite:rewrite-java") + implementation("org.openrewrite:rewrite-xml") + implementation("org.openrewrite:rewrite-properties") + implementation("org.openrewrite:rewrite-yaml") + implementation("org.openrewrite:rewrite-gradle") + implementation("org.openrewrite:rewrite-maven") implementation("org.openrewrite.recipe:rewrite-java-dependencies:${rewriteVersion}") implementation("org.openrewrite.gradle.tooling:model:${rewriteVersion}") - runtimeOnly("org.openrewrite:rewrite-java-17:$rewriteVersion") + runtimeOnly("org.openrewrite:rewrite-java-17") runtimeOnly("org.openrewrite.recipe:rewrite-hibernate:$rewriteVersion") runtimeOnly("org.openrewrite.recipe:rewrite-migrate-java:$rewriteVersion") + runtimeOnly("org.openrewrite.recipe:rewrite-openapi:${rewriteVersion}") runtimeOnly("org.openrewrite.recipe:rewrite-testing-frameworks:$rewriteVersion") testRuntimeOnly("ch.qos.logback:logback-classic:1.+") @@ -136,7 +138,7 @@ dependencies { // for generating properties migration configurations testImplementation("io.github.classgraph:classgraph:latest.release") - testImplementation("org.openrewrite:rewrite-java-17:${rewriteVersion}") + testImplementation("org.openrewrite:rewrite-java-17") testImplementation("org.openrewrite.recipe:rewrite-migrate-java:$rewriteVersion") testImplementation("org.openrewrite.recipe:rewrite-testing-frameworks:$rewriteVersion") diff --git a/src/main/resources/META-INF/rewrite/springdoc.yml b/src/main/resources/META-INF/rewrite/springdoc.yml new file mode 100644 index 000000000..49ee55704 --- /dev/null +++ b/src/main/resources/META-INF/rewrite/springdoc.yml @@ -0,0 +1,114 @@ +# +# Copyright 2024 the original author or authors. +#
+# 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 +#
+# https://www.apache.org/licenses/LICENSE-2.0 +#
+# 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. +# + +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.springdoc.SwaggerToSpringDoc +displayName: Migrate from Swagger to SpringDoc and OpenAPI +description: Migrate from Swagger to SpringDoc and OpenAPI. +tags: + - swagger + - springdoc + - openapi +recipeList: + - org.openrewrite.openapi.swagger.SwaggerToOpenAPI + - org.openrewrite.java.springdoc.UpgradeSpringDoc_2 + - org.openrewrite.java.spring.DeleteSpringProperty: + propertyKey: swagger.title + - org.openrewrite.java.spring.DeleteSpringProperty: + propertyKey: swagger.description + - org.openrewrite.java.spring.DeleteSpringProperty: + propertyKey: swagger.contact + - org.openrewrite.maven.RemoveDependency: + groupId: io.swagger.core.v3 + artifactId: swagger-annotations + +--- +type: specs.openrewrite.org/v1beta/recipe +name: org.openrewrite.java.springdoc.UpgradeSpringDoc_2 +displayName: Upgrade SpringDoc +description: Upgrade to SpringDoc v2. +tags: + - springdoc +recipeList: + # https://springdoc.org/#migrating-from-springdoc-v1 + - org.openrewrite.java.dependencies.UpgradeDependencyVersion: + groupId: org.springdoc + artifactId: "*" + newVersion: 2.3.x + # "classes/annotations changes" + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springdoc.core.SpringDocUtils + newFullyQualifiedTypeName: org.springdoc.core.utils.SpringDocUtils + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springdoc.api.annotations.ParameterObject + newFullyQualifiedTypeName: org.springdoc.core.annotations.ParameterObject + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springdoc.core.GroupedOpenApi + newFullyQualifiedTypeName: org.springdoc.core.models.GroupedOpenApi + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springdoc.core.customizers.OpenApiCustomiser + newFullyQualifiedTypeName: org.springdoc.core.customizers.OpenApiCustomizer + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springdoc.core.Constants + newFullyQualifiedTypeName: org.springdoc.core.utils.Constants + - org.openrewrite.java.ChangeType: + oldFullyQualifiedTypeName: org.springdoc.core.SwaggerUiConfigParameters + newFullyQualifiedTypeName: org.springdoc.core.properties.SwaggerUiConfigParameters + # "The following table describes the main modules changes" + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springdoc + oldArtifactId: springdoc-openapi-common + newArtifactId: springdoc-openapi-starter-common + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springdoc + oldArtifactId: springdoc-openapi-data-rest + newArtifactId: springdoc-openapi-starter-common + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springdoc + oldArtifactId: springdoc-openapi-groovy + newArtifactId: springdoc-openapi-starter-common + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springdoc + oldArtifactId: springdoc-openapi-hateoas + newArtifactId: springdoc-openapi-starter-common + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springdoc + oldArtifactId: springdoc-openapi-javadoc + newArtifactId: springdoc-openapi-starter-common + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springdoc + oldArtifactId: springdoc-openapi-kotlin + newArtifactId: springdoc-openapi-starter-common + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springdoc + oldArtifactId: springdoc-openapi-security + newArtifactId: springdoc-openapi-starter-common + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springdoc + oldArtifactId: springdoc-openapi-webmvc-core + newArtifactId: springdoc-openapi-starter-webmvc-api + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springdoc + oldArtifactId: springdoc-openapi-webflux-core + newArtifactId: springdoc-openapi-starter-webflux-api + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springdoc + oldArtifactId: springdoc-openapi-ui + newArtifactId: springdoc-openapi-starter-webmvc-ui + - org.openrewrite.java.dependencies.ChangeDependency: + oldGroupId: org.springdoc + oldArtifactId: springdoc-openapi-webflux-ui + newArtifactId: springdoc-openapi-starter-webflux-ui diff --git a/src/test/java/org/openrewrite/java/springdoc/SwaggerToSpringDocTest.java b/src/test/java/org/openrewrite/java/springdoc/SwaggerToSpringDocTest.java new file mode 100644 index 000000000..5241ef6e8 --- /dev/null +++ b/src/test/java/org/openrewrite/java/springdoc/SwaggerToSpringDocTest.java @@ -0,0 +1,80 @@ +/* + * Copyright 2024 the original author or authors. + *
+ * 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 + *
+ * https://www.apache.org/licenses/LICENSE-2.0 + *
+ * 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.test.RecipeSpec;
+import org.openrewrite.test.RewriteTest;
+
+import java.util.regex.Pattern;
+
+import static org.openrewrite.maven.Assertions.pomXml;
+
+class SwaggerToSpringDocTest implements RewriteTest {
+ @Override
+ public void defaults(RecipeSpec spec) {
+ spec.recipeFromResources("org.openrewrite.java.springdoc.SwaggerToSpringDoc");
+ }
+
+ @Test
+ @DocumentExample
+ void upgradeMaven() {
+ rewriteRun(
+ // language=xml
+ pomXml(
+ """
+