diff --git a/src/main/java/org/openrewrite/openapi/swagger/MigrateApiParamSchemaValue.java b/src/main/java/org/openrewrite/openapi/swagger/MigrateApiParamSchemaValue.java index e443e4f..4a58465 100644 --- a/src/main/java/org/openrewrite/openapi/swagger/MigrateApiParamSchemaValue.java +++ b/src/main/java/org/openrewrite/openapi/swagger/MigrateApiParamSchemaValue.java @@ -44,7 +44,7 @@ class MigrateApiParamSchemaValue extends JavaIsoVisitor { @Override public Annotation visitAnnotation(Annotation annotation, ExecutionContext ctx) { J.Annotation a = super.visitAnnotation(annotation, ctx); - if (!PARAMETER_ANNOTATION_MATCHER.matches(a)) { + if (!PARAMETER_ANNOTATION_MATCHER.matches(a) || a.getArguments() == null) { return a; } diff --git a/src/test/java/org/openrewrite/openapi/swagger/SwaggerToOpenAPITest.java b/src/test/java/org/openrewrite/openapi/swagger/SwaggerToOpenAPITest.java index ca81612..5eea157 100644 --- a/src/test/java/org/openrewrite/openapi/swagger/SwaggerToOpenAPITest.java +++ b/src/test/java/org/openrewrite/openapi/swagger/SwaggerToOpenAPITest.java @@ -198,6 +198,56 @@ class Example { ); } + @Test + void migrateApiParamWithoutArguments() { + rewriteRun( + //language=java + java( + """ + import io.swagger.annotations.ApiParam; + + class Example { + @ApiParam + private Integer foo; + } + """, + """ + import io.swagger.v3.oas.annotations.Parameter; + + class Example { + @Parameter + private Integer foo; + } + """ + ) + ); + } + + @Test + void migrateApiParamWithoutArgumentsOnMethodParameter() { + rewriteRun( + //language=java + java( + """ + import io.swagger.annotations.ApiParam; + + class Example { + void create(@ApiParam Integer foo) { + } + } + """, + """ + import io.swagger.v3.oas.annotations.Parameter; + + class Example { + void create(@Parameter Integer foo) { + } + } + """ + ) + ); + } + /** * * Same test as {@link #migrateApiParam()} making sure the order of the annotation properties doesn't break the logic