Repository: cjbooms/fabrikt
Pull request #157 (2023-01-13 17:20:28)

Support responses schema
Resolving https://github.com/cjbooms/fabrikt/issues/156

cjbooms: 👍 
cjbooms: Nice one @ReallyLiri, I will cut a new release for you once merged

Patch:
diff --git a/src/main/kotlin/com/cjbooms/fabrikt/model/SourceApi.kt b/src/main/kotlin/com/cjbooms/fabrikt/model/SourceApi.kt
index 5d6d82e..c66cb0d 100644
--- a/src/main/kotlin/com/cjbooms/fabrikt/model/SourceApi.kt
+++ b/src/main/kotlin/com/cjbooms/fabrikt/model/SourceApi.kt
@@ -41,6 +41,7 @@ data class SourceApi(
         }
         allSchemas = openApi3.schemas.entries.map { it.key to it.value }
             .plus(openApi3.parameters.entries.map { it.key to it.value.schema })
+            .plus(openApi3.responses.entries.flatMap { it.value.contentMediaTypes.entries.map { content -> it.key to content.value.schema } })
             .map { (key, schema) -> SchemaInfo(key, schema) }
     }
 


Test patch:
diff --git a/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt
index d370738..9018042 100644
--- a/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt
+++ b/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt
@@ -43,7 +43,8 @@ class ModelGeneratorTest {
         "requiredReadOnly",
         "validationAnnotations",
         "wildCardTypes",
-        "singleAllOf"
+        "singleAllOf",
+        "responsesSchema"
     )
 
     @BeforeEach
diff --git a/src/test/resources/examples/responsesSchema/api.yaml b/src/test/resources/examples/responsesSchema/api.yaml
new file mode 100644
index 0000000..f7e19eb
--- /dev/null
+++ b/src/test/resources/examples/responsesSchema/api.yaml
@@ -0,0 +1,28 @@
+openapi: 3.0.0
+components:
+  responses:
+    ErrorResponse:
+      description: "Response on error"
+      content:
+        application/json:
+          schema:
+            type: object
+            required:
+              - message
+              - code
+            properties:
+              message:
+                type: string
+              code:
+                type: integer
+    SucccessResponse:
+      description: "Response on success"
+      content:
+        application/json:
+          schema:
+            type: object
+            required:
+              - message
+            properties:
+              message:
+                type: string
diff --git a/src/test/resources/examples/responsesSchema/models/Models.kt b/src/test/resources/examples/responsesSchema/models/Models.kt
new file mode 100644
index 0000000..6450653
--- /dev/null
+++ b/src/test/resources/examples/responsesSchema/models/Models.kt
@@ -0,0 +1,24 @@
+package examples.responsesSchema.models
+
+import com.fasterxml.jackson.annotation.JsonProperty
+import javax.validation.constraints.NotNull
+import kotlin.Int
+import kotlin.String
+
+data class ErrorResponse(
+    @param:JsonProperty("message")
+    @get:JsonProperty("message")
+    @get:NotNull
+    val message: String,
+    @param:JsonProperty("code")
+    @get:JsonProperty("code")
+    @get:NotNull
+    val code: Int
+)
+
+data class SucccessResponse(
+    @param:JsonProperty("message")
+    @get:JsonProperty("message")
+    @get:NotNull
+    val message: String
+)