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

Add MigrateSpringdocCommon recipe #20

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-engine:latest.release")

testRuntimeOnly("io.swagger:swagger-annotations:1.6.13")
testRuntimeOnly("org.springdoc:springdoc-openapi-common:1.6.8")
testRuntimeOnly("io.swagger.core.v3:swagger-annotations:2.2.20")

testRuntimeOnly("org.gradle:gradle-tooling-api:latest.release")
Expand Down
33 changes: 33 additions & 0 deletions src/main/resources/META-INF/rewrite/springdoc-common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# 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.
#

type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.openapi.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,89 @@
/*
* 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.openapi.swagger;

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import static org.openrewrite.java.Assertions.java;

class MigrateSpringdocCommonTest implements RewriteTest {
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.TypeValidation;

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

@DocumentExample
void fixCustomiserAndGroupedOpenApi() {
public void fixCustomiserAndGroupedOpenApi() {
// language=java
rewriteRun(
spec -> spec.afterTypeValidationOptions(TypeValidation.none()),
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) {
}
}
}
"""
));
}
}