diff --git a/src/main/kotlin/com/cjbooms/fabrikt/model/SourceApi.kt b/src/main/kotlin/com/cjbooms/fabrikt/model/SourceApi.kt index 5d6d82ef..c66cb0d5 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) } } diff --git a/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt b/src/test/kotlin/com/cjbooms/fabrikt/generators/ModelGeneratorTest.kt index d3707386..90180422 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 00000000..f7e19eb0 --- /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 00000000..64506531 --- /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 +)