From 597bc6efecf064695d65bc64377357b851cecc07 Mon Sep 17 00:00:00 2001 From: "robin.bygrave" Date: Wed, 13 Sep 2023 17:07:02 +1200 Subject: [PATCH] #285 BigInteger support for path parameter --- .../io/avaje/http/generator/core/TypeMap.java | 2 +- .../http/generator/core/TypeMapTest.java | 16 ++++++++++ .../src/main/resources/public/openapi.json | 2 +- .../java/org/example/web/HelloController.java | 7 +++++ .../src/main/resources/public/openapi.json | 31 +++++++++++++++++++ .../java/org/example/HelloController.java | 5 +++ 6 files changed, 61 insertions(+), 2 deletions(-) diff --git a/http-generator-core/src/main/java/io/avaje/http/generator/core/TypeMap.java b/http-generator-core/src/main/java/io/avaje/http/generator/core/TypeMap.java index 35fa5a6cb..c81938cf8 100644 --- a/http-generator-core/src/main/java/io/avaje/http/generator/core/TypeMap.java +++ b/http-generator-core/src/main/java/io/avaje/http/generator/core/TypeMap.java @@ -34,7 +34,7 @@ private static void add(TypeHandler h) { add(new UuidHandler()); add(new BigDecimalHandler()); - add(new BigDecimalHandler()); + add(new BigIntegerHandler()); add(new LocalDateHandler()); add(new LocalTimeHandler()); add(new LocalDateTimeHandler()); diff --git a/http-generator-core/src/test/java/io/avaje/http/generator/core/TypeMapTest.java b/http-generator-core/src/test/java/io/avaje/http/generator/core/TypeMapTest.java index 5f4b9ac7c..ead716fd3 100644 --- a/http-generator-core/src/test/java/io/avaje/http/generator/core/TypeMapTest.java +++ b/http-generator-core/src/test/java/io/avaje/http/generator/core/TypeMapTest.java @@ -53,4 +53,20 @@ void get_Float() { assertThat(handler.asMethod()).isEqualTo("asFloat("); assertFalse(handler.isPrimitive()); } + + @Test + void get_BigDecimal() { + TypeHandler handler = TypeMap.get("java.math.BigDecimal"); + assertThat(handler).isInstanceOf(TypeMap.BigDecimalHandler.class); + assertThat(handler.asMethod()).isEqualTo("asBigDecimal("); + assertFalse(handler.isPrimitive()); + } + + @Test + void get_BigInt() { + TypeHandler handler = TypeMap.get("java.math.BigInteger"); + assertThat(handler).isInstanceOf(TypeMap.BigIntegerHandler.class); + assertThat(handler.asMethod()).isEqualTo("asBigInteger("); + assertFalse(handler.isPrimitive()); + } } diff --git a/tests/test-javalin-jsonb/src/main/resources/public/openapi.json b/tests/test-javalin-jsonb/src/main/resources/public/openapi.json index 9fc694f3f..26783f108 100644 --- a/tests/test-javalin-jsonb/src/main/resources/public/openapi.json +++ b/tests/test-javalin-jsonb/src/main/resources/public/openapi.json @@ -1,7 +1,7 @@ { "openapi" : "3.0.1", "info" : { - "title" : "Example service showing off the Path extension method of controller", + "title" : "Example service", "description" : "Example Javalin controllers with Java and Maven", "version" : "" }, diff --git a/tests/test-jex/src/main/java/org/example/web/HelloController.java b/tests/test-jex/src/main/java/org/example/web/HelloController.java index a630fa209..9745b9e32 100644 --- a/tests/test-jex/src/main/java/org/example/web/HelloController.java +++ b/tests/test-jex/src/main/java/org/example/web/HelloController.java @@ -9,6 +9,8 @@ import io.avaje.http.api.Valid; import io.avaje.jex.Context; +import java.math.BigInteger; + // @Roles(AppRoles.BASIC_USER) @Controller @Path("/") @@ -58,4 +60,9 @@ String splat2(String name, String nam0, String nam1) { void put(HelloDto dto) { dto.hashCode(); } + + @Get("/bigInt/{val}") + String testBigInt(BigInteger val) { + return "hi|" + val; + } } diff --git a/tests/test-jex/src/main/resources/public/openapi.json b/tests/test-jex/src/main/resources/public/openapi.json index 0a2817d9f..00da28583 100644 --- a/tests/test-jex/src/main/resources/public/openapi.json +++ b/tests/test-jex/src/main/resources/public/openapi.json @@ -48,6 +48,37 @@ } } }, + "/bigInt/{val}" : { + "get" : { + "tags" : [ + + ], + "summary" : "", + "description" : "", + "parameters" : [ + { + "name" : "val", + "in" : "path", + "required" : true, + "schema" : { + "type" : "number" + } + } + ], + "responses" : { + "200" : { + "description" : "", + "content" : { + "application/json" : { + "schema" : { + "type" : "string" + } + } + } + } + } + } + }, "/other/{name}" : { "get" : { "tags" : [ diff --git a/tests/test-nima-jsonb/src/main/java/org/example/HelloController.java b/tests/test-nima-jsonb/src/main/java/org/example/HelloController.java index c9f7c495a..95d7ea403 100644 --- a/tests/test-nima-jsonb/src/main/java/org/example/HelloController.java +++ b/tests/test-nima-jsonb/src/main/java/org/example/HelloController.java @@ -148,4 +148,9 @@ String form(String name, String email, String url) { String formBean(MyForm form) { return form.name + "|" + form.email + "|" + form.url; } + +// @Get("/bigInt/{val}") +// String testBigInt(BigInteger val) { +// return "hi|" + val; +// } }