Skip to content

Commit

Permalink
Support responses schema (#157)
Browse files Browse the repository at this point in the history
Co-authored-by: ReallyLiri <[email protected]>
  • Loading branch information
ReallyLiri and ReallyLiri authored Jan 13, 2023
1 parent 3bbb22f commit b0a8733
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/kotlin/com/cjbooms/fabrikt/model/SourceApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class ModelGeneratorTest {
"requiredReadOnly",
"validationAnnotations",
"wildCardTypes",
"singleAllOf"
"singleAllOf",
"responsesSchema"
)

@BeforeEach
Expand Down
28 changes: 28 additions & 0 deletions src/test/resources/examples/responsesSchema/api.yaml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions src/test/resources/examples/responsesSchema/models/Models.kt
Original file line number Diff line number Diff line change
@@ -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
)

0 comments on commit b0a8733

Please sign in to comment.