Skip to content

Commit

Permalink
Fix MigrateApiImplicitParam syntax error when args after schema (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
SiBorea authored Jan 15, 2025
1 parent fa6ca0f commit 913c9a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct

StringBuilder tpl = new StringBuilder();
StringBuilder schemaTpl = new StringBuilder();
List<Expression> schemaArgs = new ArrayList<>();
List<Expression> args = new ArrayList<>();
for (Expression exp : anno.getArguments()) {
if (isDataTypeClass(exp)) {
Expression expression = ((J.Assignment) exp).getAssignment();
addSchema(schemaTpl, "implementation");
args.add(expression);
schemaArgs.add(expression);
} else if (isDefaultValue(exp)) {
Expression expression = ((J.Assignment) exp).getAssignment();
addSchema(schemaTpl, "defaultValue");
args.add(expression);
schemaArgs.add(expression);
} else {
tpl.append("#{any()}, ");
args.add(exp);
Expand All @@ -86,6 +87,7 @@ public J.Annotation visitAnnotation(J.Annotation annotation, ExecutionContext ct
}
schemaTpl.append(")");
tpl.append(", ").append(schemaTpl);
args.addAll(schemaArgs);
}
anno = JavaTemplate.builder(tpl.toString())
.imports(FQN_SCHEMA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void migrateApiImplicitParam() {
import io.swagger.annotations.ApiImplicitParam;
class Example {
@ApiImplicitParam(name = "foo", value = "Foo object", required = true, dataTypeClass = Example.class, defaultValue = "example")
@ApiImplicitParam(name = "Foo", value = "Bar", required = true, allowEmptyValue = false, paramType = "Hi", dataTypeClass = String.class, example = "Example")
public void create(Example foo) {
}
}
Expand All @@ -146,7 +146,7 @@ public void create(Example foo) {
import io.swagger.v3.oas.annotations.media.Schema;
class Example {
@Parameter(name = "foo", description = "Foo object", required = true, schema = @Schema(implementation = Example.class, defaultValue = "example"))
@Parameter(name = "Foo", description = "Bar", required = true, allowEmptyValue = false, example = "Example", schema = @Schema(implementation = String.class))
public void create(Example foo) {
}
}
Expand Down

0 comments on commit 913c9a2

Please sign in to comment.