diff --git a/CHANGELOG.md b/CHANGELOG.md index e76183402..9380c7cd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [1.9.2] - October 24th, 2021 + +### Changed + +- Jackson ObjectMapper passed by parameter to openapi module +- Added serializable annotation to ExceptionResponse + ## [1.9.1] - October 17th, 2021 ### Changed diff --git a/README.md b/README.md index e030f2d1b..f8b409768 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,29 @@ suggestions on better implementations are welcome 🤠 Under the hood, Kompendium uses Jackson to serialize the final api spec. However, this implementation detail does not leak to the actual API, meaning that users are free to choose the serialization library of their choice. +Added the possibility to add your own ObjectMapper for Jackson. + +Added a default parameter with the following configuration: + +```kotlin +ObjectMapper() + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .enable(SerializationFeature.INDENT_OUTPUT) +``` + +If you want to change this default configuration and use your own ObjectMapper you only need to pass it as a second argument to the openApi module: + +```kotlin +routing { + openApi(oas, objectMapper) + route("/potato/spud") { + notarizedGet(simpleGetInfo) { + call.respond(HttpStatusCode.OK) + } + } +} +``` + ### Route Handling > ⚠️ Warning: Custom route handling is almost definitely an indication that either a new selector should be added to kompendium-core or that kompendium is in need of another module to handle a new ktor companion module. If you have encountered a route selector that is not already handled, please consider opening an [issue](https://github.com/bkbnio/kompendium/issues/new) diff --git a/gradle.properties b/gradle.properties index 970b0cd2c..26cbe2ba7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Kompendium -project.version=1.9.1 +project.version=1.9.2 # Kotlin kotlin.code.style=official # Gradle diff --git a/kompendium-core/src/main/kotlin/io/bkbn/kompendium/routes/OpenApiRoute.kt b/kompendium-core/src/main/kotlin/io/bkbn/kompendium/routes/OpenApiRoute.kt index 56d1fba92..298010c24 100644 --- a/kompendium-core/src/main/kotlin/io/bkbn/kompendium/routes/OpenApiRoute.kt +++ b/kompendium-core/src/main/kotlin/io/bkbn/kompendium/routes/OpenApiRoute.kt @@ -13,14 +13,19 @@ import io.ktor.routing.route /** * Provides an out-of-the-box route to return the generated [OpenApiSpec] * @param oas spec that is returned + * @param om provider for Jackson */ -fun Routing.openApi(oas: OpenApiSpec) { - val om = ObjectMapper() - .setSerializationInclusion(JsonInclude.Include.NON_NULL) - .enable(SerializationFeature.INDENT_OUTPUT) +fun Routing.openApi( + oas: OpenApiSpec, + om: ObjectMapper = objectMapper +) { route("/openapi.json") { get { call.respondText { om.writeValueAsString(oas) } } } } + +private val objectMapper = ObjectMapper() + .setSerializationInclusion(JsonInclude.Include.NON_NULL) + .enable(SerializationFeature.INDENT_OUTPUT) diff --git a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/Models.kt b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/Models.kt index d677d5050..83fdf60dd 100644 --- a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/Models.kt +++ b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/Models.kt @@ -4,6 +4,7 @@ import io.bkbn.kompendium.annotations.KompendiumField import io.bkbn.kompendium.annotations.KompendiumParam import io.bkbn.kompendium.annotations.ParamType import io.bkbn.kompendium.annotations.UndeclaredField +import kotlinx.serialization.Serializable import org.joda.time.DateTime data class ExampleParams( @@ -27,6 +28,7 @@ data class ExampleRequest( val aaa: List ) +@Serializable data class ExampleResponse(val c: String) data class ExceptionResponse(val message: String)