Repository: jooby-project/jooby
Pull request #2021 (2020-09-26 22:21:31)

OpenAPI: document example on Data? class used as arguments
example for #2004 

@imeszaros can you review?

Thanks


Patch:
diff --git a/modules/jooby-openapi/pom.xml b/modules/jooby-openapi/pom.xml
index 2527f7623..af659c697 100644
--- a/modules/jooby-openapi/pom.xml
+++ b/modules/jooby-openapi/pom.xml
@@ -73,6 +73,13 @@
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>3.11</version>
+      <scope>test</scope>
+    </dependency>
+
     <dependency>
       <groupId>org.jacoco</groupId>
       <artifactId>org.jacoco.agent</artifactId>


Test patch:
diff --git a/modules/jooby-openapi/src/test/java/issues/i2004/Issue2004.java b/modules/jooby-openapi/src/test/java/issues/i2004/Issue2004.java
new file mode 100644
index 000000000..9c0b55c41
--- /dev/null
+++ b/modules/jooby-openapi/src/test/java/issues/i2004/Issue2004.java
@@ -0,0 +1,54 @@
+package issues.i2004;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import io.jooby.openapi.OpenAPIResult;
+import io.jooby.openapi.OpenAPITest;
+import kt.issues.i2004.App2004;
+
+public class Issue2004 {
+  @OpenAPITest(value = App2004.class)
+  public void shouldGenerateDocForParameter(OpenAPIResult result) {
+    assertEquals("openapi: 3.0.1\n"
+        + "info:\n"
+        + "  title: 2004 API\n"
+        + "  description: 2004 API description\n"
+        + "  version: \"1.0\"\n"
+        + "paths:\n"
+        + "  /issues/2004:\n"
+        + "    get:\n"
+        + "      summary: Get all companies\n"
+        + "      description: Find all companies defined by the search parameters\n"
+        + "      operationId: getAllCompanies\n"
+        + "      requestBody:\n"
+        + "        content:\n"
+        + "          application/json:\n"
+        + "            schema:\n"
+        + "              $ref: '#/components/schemas/CompanyRequest'\n"
+        + "        required: true\n"
+        + "      responses:\n"
+        + "        \"200\":\n"
+        + "          description: Success\n"
+        + "          content:\n"
+        + "            application/json:\n"
+        + "              schema:\n"
+        + "                type: string\n"
+        + "components:\n"
+        + "  schemas:\n"
+        + "    CompanyRequest:\n"
+        + "      type: object\n"
+        + "      properties:\n"
+        + "        baseYear:\n"
+        + "          type: integer\n"
+        + "          format: int32\n"
+        + "        naceCode:\n"
+        + "          type: array\n"
+        + "          items:\n"
+        + "            type: string\n"
+        + "        region:\n"
+        + "          type: string\n"
+        + "          description: blablabla\n"
+        + "          example: HEY\n"
+        + "      description: This is a company request\n", result.toYaml());
+  }
+}
diff --git a/modules/jooby-openapi/src/test/kotlin/kt/issues/i2004/App2004.kt b/modules/jooby-openapi/src/test/kotlin/kt/issues/i2004/App2004.kt
new file mode 100644
index 000000000..56bc13d7c
--- /dev/null
+++ b/modules/jooby-openapi/src/test/kotlin/kt/issues/i2004/App2004.kt
@@ -0,0 +1,9 @@
+package kt.issues.i2004
+
+import io.jooby.Kooby
+
+class App2004 : Kooby({
+
+  mvc(Controller2004())
+
+})
diff --git a/modules/jooby-openapi/src/test/kotlin/kt/issues/i2004/Controller2004.kt b/modules/jooby-openapi/src/test/kotlin/kt/issues/i2004/Controller2004.kt
new file mode 100644
index 000000000..3ba88b78b
--- /dev/null
+++ b/modules/jooby-openapi/src/test/kotlin/kt/issues/i2004/Controller2004.kt
@@ -0,0 +1,27 @@
+package kt.issues.i2004
+
+import io.jooby.annotations.GET
+import io.jooby.annotations.Path
+import io.jooby.annotations.QueryParam
+import io.swagger.v3.oas.annotations.Operation
+import io.swagger.v3.oas.annotations.media.Schema
+
+@Schema(description = "This is a company request")
+data class CompanyRequest(
+    val baseYear: Int,
+    val naceCode: List<String>,
+    @get:Schema(required = false, description = "blablabla", example = "HEY")
+    val region: String
+)
+
+@Path("/issues/2004")
+class Controller2004 {
+  @Operation(
+      summary = "Get all companies",
+      description = "Find all companies defined by the search parameters"
+  )
+  @GET
+  fun getAllCompanies(companyRequest: CompanyRequest): String {
+    return companyRequest.toString()
+  }
+}