Repository: tipsy/javalin
Pull request #882 (2020-02-22 18:23:37)

Bug: OpenApi Plugin missing some boxed types

28Smiles: Should I file a issue?
tipsy: Great work on this and all of the other PRs and issues @28Smiles ! 

It looks like `java.lang.Double::class.java` was already included, did you add it by mistake?

I will look at the rest of the PRs and issues tomorrow, but I think @TobiasWalle and/or @sealedtx should give their opnion, as they are way more familiar with the OpenAPI plugin than I am.
28Smiles: Thanks.
Yes I did this by mistake, fixed.
sealedtx: Hi @tipsy, @28Smiles. I am not sure, but it looks like we should also add those missed types here?
https://github.com/tipsy/javalin/blob/b2319def3256bfaa8858fb011a56225b303bd11f/src/main/java/io/javalin/plugin/openapi/dsl/DocumentedContent.kt#L112-L131
28Smiles: sounds right
28Smiles: I also added double, since it was missing completely
tipsy: Great, thank you @28Smiles !

Patch:
diff --git a/src/main/java/io/javalin/plugin/openapi/dsl/DocumentedContent.kt b/src/main/java/io/javalin/plugin/openapi/dsl/DocumentedContent.kt
index 475606f6..d485ba3b 100644
--- a/src/main/java/io/javalin/plugin/openapi/dsl/DocumentedContent.kt
+++ b/src/main/java/io/javalin/plugin/openapi/dsl/DocumentedContent.kt
@@ -120,8 +120,11 @@ val nonRefTypes = setOf(
         Integer::class.java,
         Double::class.java,
         java.lang.Double::class.java,
+        Float::class.java,
+        java.lang.Float::class.java,
         List::class.java,
         Long::class.java,
+        java.lang.Long::class.java,
         BigDecimal::class.java,
         Date::class.java,
         LocalDate::class.java,
diff --git a/src/main/java/io/javalin/plugin/openapi/external/KotlinOpenApiDsl.kt b/src/main/java/io/javalin/plugin/openapi/external/KotlinOpenApiDsl.kt
index 5d82ae09..b6d17e76 100644
--- a/src/main/java/io/javalin/plugin/openapi/external/KotlinOpenApiDsl.kt
+++ b/src/main/java/io/javalin/plugin/openapi/external/KotlinOpenApiDsl.kt
@@ -116,13 +116,15 @@ internal fun <T> findSchema(clazz: Class<T>): FindSchemaResponse? {
         List::class.java -> FindSchemaResponse(ArraySchema())
         Map::class.java -> FindSchemaResponse(MapSchema())
         Long::class.java -> FindSchemaResponse(IntegerSchema().format("int64"))
+        java.lang.Long::class.java -> FindSchemaResponse(IntegerSchema().format("int64"))
         BigDecimal::class.java -> FindSchemaResponse(IntegerSchema().format(""))
         Date::class.java -> FindSchemaResponse(DateSchema())
         LocalDate::class.java -> FindSchemaResponse(DateSchema())
         LocalDateTime::class.java -> FindSchemaResponse(DateTimeSchema())
-        java.lang.Double::class.java -> FindSchemaResponse(NumberSchema())
         Double::class.java -> FindSchemaResponse(NumberSchema())
+        java.lang.Double::class.java -> FindSchemaResponse(NumberSchema())
         Float::class.java -> FindSchemaResponse(NumberSchema())
+        java.lang.Float::class.java -> FindSchemaResponse(NumberSchema())
         /* BEGIN Custom classes */
         ByteArray::class.java -> FindSchemaResponse(StringSchema().format("binary"))
         /* END Custom classes */


Test patch:
diff --git a/src/test/java/io/javalin/openapi/TestOpenApi.kt b/src/test/java/io/javalin/openapi/TestOpenApi.kt
index 7fcabfb1..2b6c32aa 100644
--- a/src/test/java/io/javalin/openapi/TestOpenApi.kt
+++ b/src/test/java/io/javalin/openapi/TestOpenApi.kt
@@ -366,6 +366,40 @@ class TestOpenApi {
         assertThat(actual.asJsonString()).isEqualTo(defaultOperationExampleJson)
     }
 
+    @Test
+    fun `createSchema works with query param and reified dsl`() {
+        val openApiOptions = OpenApiOptions(
+                Info().title("Example").version("1.0.0")
+        )
+        val app = Javalin.create {
+            it.registerPlugin(OpenApiPlugin(openApiOptions))
+        }
+
+        with(app) {
+            get("/test", documented(document().queryParam<Long>("id")) {})
+        }
+        val actual = JavalinOpenApi.createSchema(app)
+
+        assertThat(actual.asJsonString()).isEqualTo(simpleExampleWithPrimitiveQueryParam)
+    }
+
+    @Test
+    fun `createSchema works with query param and dsl`() {
+        val openApiOptions = OpenApiOptions(
+                Info().title("Example").version("1.0.0")
+        )
+        val app = Javalin.create {
+            it.registerPlugin(OpenApiPlugin(openApiOptions))
+        }
+
+        with(app) {
+            get("/test", documented(document().queryParam("id", Long::class.java)) {})
+        }
+        val actual = JavalinOpenApi.createSchema(app)
+
+        assertThat(actual.asJsonString()).isEqualTo(simpleExampleWithPrimitiveQueryParam)
+    }
+
     @Test
     fun `createSchema applies defaults before actual documentation`() {
         val openApiOptions = OpenApiOptions(
diff --git a/src/test/java/io/javalin/openapi/json.kt b/src/test/java/io/javalin/openapi/json.kt
index 04467c3e..2ceb379c 100644
--- a/src/test/java/io/javalin/openapi/json.kt
+++ b/src/test/java/io/javalin/openapi/json.kt
@@ -108,6 +108,39 @@ val simpleExample = """
   }
 """.formatJson()
 
+@Language("JSON")
+val simpleExampleWithPrimitiveQueryParam = """
+  {
+    "openapi": "3.0.1",
+    "info": {
+      "title": "Example",
+      "version": "1.0.0"
+    },
+    "paths": {
+      "/test": {
+        "get": {
+          "summary": "Get test",
+          "operationId": "getTest",
+          "parameters" : [ {
+            "name" : "id",
+            "in" : "query",
+            "schema" : {
+              "type": "integer",
+              "format": "int64"
+            }
+          } ],
+          "responses" : {
+            "200" : {
+              "description" : "Default response"
+            }
+          }
+        }
+      }
+    },
+    "components": {}
+  }
+""".formatJson()
+
 @Language("JSON")
 val simpleExampleWithMultipleGets = """
   {