Skip to content

Commit dc96e71

Browse files
committed
#55 - Support client generation with @client and @Client.Import
Tidy imports
1 parent 69144c8 commit dc96e71

File tree

7 files changed

+18
-15
lines changed

7 files changed

+18
-15
lines changed

http-api/src/main/java/io/avaje/http/api/PathTypeConversion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static long asLong(String value) {
6464
public static double asDouble(String value) {
6565
checkNull(value);
6666
try {
67-
return Double.valueOf(value);
67+
return Double.parseDouble(value);
6868
} catch (RuntimeException e) {
6969
throw new InvalidPathArgumentException(e);
7070
}
@@ -76,7 +76,7 @@ public static double asDouble(String value) {
7676
public static float asFloat(String value) {
7777
checkNull(value);
7878
try {
79-
return Float.valueOf(value);
79+
return Float.parseFloat(value);
8080
} catch (RuntimeException e) {
8181
throw new InvalidPathArgumentException(e);
8282
}

http-api/src/test/java/io/avaje/http/api/PathTypeConversionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void asInt_when_invalid() {
4242

4343
@Test
4444
public void asLong() {
45-
assertEquals(42L, PathTypeConversion.asInt("42"));
45+
assertEquals(42L, PathTypeConversion.asLong("42"));
4646
}
4747

4848
@Test

http-generator-client/src/main/java/io/avaje/http/generator/client/ClientMethodWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ void write() {
6060
PathSegments pathSegments = method.getPathSegments();
6161
Set<PathSegments.Segment> segments = pathSegments.getSegments();
6262

63+
writeHeaders();
6364
writePaths(segments);
6465
writeQueryParams(pathSegments);
6566
writeFormParams();
66-
writeHeaders();
6767
writeBody();
6868

6969
WebMethod webMethod = method.getWebMethod();

http-generator-client/src/main/java/io/avaje/http/generator/client/ClientWriter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
*/
1515
class ClientWriter extends BaseControllerWriter {
1616

17-
private static final String PATH_CONVERSION = "io.avaje.http.client.PathConversion.toPath";
1817
private static final String HTTP_CLIENT_CONTEXT = "io.avaje.http.client.HttpClientContext";
1918
private static final String AT_GENERATED = "@Generated(\"avaje-http-client-generator\")";
2019

@@ -23,7 +22,6 @@ class ClientWriter extends BaseControllerWriter {
2322
ClientWriter(ControllerReader reader, ProcessingContext ctx) throws IOException {
2423
super(reader, ctx, "$httpclient");
2524
reader.addImportType(HTTP_CLIENT_CONTEXT);
26-
reader.addStaticImportType(PATH_CONVERSION);
2725
readMethods();
2826
}
2927

http-generator-core/src/main/java/io/avaje/http/generator/core/Constants.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ class Constants {
55
static final String OPENAPIDEFINITION = "io.swagger.v3.oas.annotations.OpenAPIDefinition";
66

77
static final String SINGLETON = "jakarta.inject.Singleton";
8-
static final String GENERATED = "io.avaje.http.api.Generated";
98

109
static final String IMPORT_PATH_TYPE_CONVERT = "import static io.avaje.http.api.PathTypeConversion.*;";
1110

12-
static final String IMPORT_CONTROLLER = "io.avaje.http.api.*";
11+
static final String IMPORT_HTTP_API = "io.avaje.http.api.*";
1312
static final String VALIDATOR = "io.avaje.http.api.Validator";
1413

1514
}

http-generator-core/src/main/java/io/avaje/http/generator/core/ControllerReader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,12 @@ public ControllerReader(TypeElement beanType, ProcessingContext ctx) {
6161
this.interfaces = initInterfaces();
6262
this.interfaceMethods = initInterfaceMethods();
6363
this.roles = Util.findRoles(beanType);
64-
importTypes.add(Constants.GENERATED);
6564
if (ctx.isOpenApiAvailable()) {
6665
docHidden = initDocHidden();
6766
}
6867
includeValidator = initIncludeValidator();
6968
importTypes.add(Constants.SINGLETON);
70-
importTypes.add(Constants.IMPORT_CONTROLLER);
69+
importTypes.add(Constants.IMPORT_HTTP_API);
7170
importTypes.add(beanType.getQualifiedName().toString());
7271
if (includeValidator) {
7372
importTypes.add(Constants.VALIDATOR);

tests/test-client/src/main/java/org/example/Simple.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,39 @@
33

44
import io.avaje.http.api.*;
55

6+
import javax.validation.Valid;
7+
import java.net.URL;
68
import java.net.http.HttpResponse;
79
import java.time.LocalDate;
8-
import java.time.LocalTime;
910
import java.util.List;
1011

1112
@Client
13+
@Path("moo")
1214
public interface Simple {
1315

1416
// UUID goo, Boolean option,
15-
@Get("{uid}")
16-
HttpResponse<String> byId(long uid, LocalTime forT, @QueryParam("my-dat") LocalDate dt);
17+
@Get("{uid}/{date}")
18+
HttpResponse<String> byIdg(long uid, LocalDate date, @Header URL access, @QueryParam("my-dat") LocalDate dt);
1719

1820
@Get("users/{user}/repos")
1921
List<Repo> listRepos(String user, String other);
2022

2123
@Post
22-
void save(Repo bean);
24+
Id save(Repo bean);
2325

24-
@Post
26+
@Post("/register")
2527
@Form
2628
void register(MyForm myForm);
2729

2830
@Post("other")
2931
@Form
3032
void registerOther(String myName, String email);
3133

34+
class Id {
35+
public long id;
36+
}
37+
38+
@Valid
3239
class MyForm {
3340

3441
String name;

0 commit comments

Comments
 (0)