From 52a425a5d2b05fe6326471742d01173845734bac Mon Sep 17 00:00:00 2001 From: Ryan Brink <5607577+unredundant@users.noreply.github.com> Date: Thu, 10 Feb 2022 08:34:02 -0500 Subject: [PATCH] fix: bumped swagger version + minor playground fix (#191) --- CHANGELOG.md | 18 ++++++++++++------ gradle.properties | 2 +- .../io/bkbn/kompendium/core/routes/Swagger.kt | 6 +++--- .../kompendium/playground/AuthPlayground.kt | 8 +++++++- .../kompendium/playground/BasicPlayground.kt | 11 ++++++++++- .../playground/ConstraintPlayground.kt | 8 +++++++- .../playground/ExceptionPlayground.kt | 8 +++++++- .../kompendium/playground/GenericPlayground.kt | 8 +++++++- .../playground/LocationPlayground.kt | 8 +++++++- .../playground/PolymorphicPlayground.kt | 8 +++++++- .../playground/RecursionPlayground.kt | 8 +++++++- .../kompendium/playground/SwaggerPlayground.kt | 8 +++++++- 12 files changed, 82 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 336b550ba..f04ef99e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,17 @@ ## Unreleased +### Added + +### Changed + +### Remove + +--- + +## Released + +## [2.0.4] - February 10th, 2022 ### Added - Custom Type example to playground @@ -9,12 +20,7 @@ - Cleaned up and broke out handlers into separate classes - Serializer cleanup - Tests now run against Jackson, Gson and kotlinx on every run - -### Remove - ---- - -## Released +- Swagger UI bumped from v3 to v4 ## [2.0.3] - February 7th, 2022 ### Changed diff --git a/gradle.properties b/gradle.properties index 88f47a5a3..819d9e4ae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Kompendium -project.version=2.0.3 +project.version=2.0.4 # Kotlin kotlin.code.style=official # Gradle diff --git a/kompendium-core/src/main/kotlin/io/bkbn/kompendium/core/routes/Swagger.kt b/kompendium-core/src/main/kotlin/io/bkbn/kompendium/core/routes/Swagger.kt index baa18c867..4c417d7f4 100644 --- a/kompendium-core/src/main/kotlin/io/bkbn/kompendium/core/routes/Swagger.kt +++ b/kompendium-core/src/main/kotlin/io/bkbn/kompendium/core/routes/Swagger.kt @@ -36,7 +36,7 @@ fun Routing.swagger(pageTitle: String = "Docs", specUrl: String = "/openapi.json content = "width=device-width, initial-scale=1" } link { - href = "https://unpkg.com/swagger-ui-dist@3.12.1/swagger-ui.css" + href = "https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui.css" rel = "stylesheet" } } @@ -45,10 +45,10 @@ fun Routing.swagger(pageTitle: String = "Docs", specUrl: String = "/openapi.json id = "swagger-ui" } script { - src = "https://unpkg.com/swagger-ui-dist@3.12.1/swagger-ui-standalone-preset.js" + src = "https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui-standalone-preset.js" } script { - src = "https://unpkg.com/swagger-ui-dist@3.12.1/swagger-ui-bundle.js" + src = "https://unpkg.com/swagger-ui-dist@4.5.0/swagger-ui-bundle.js" } unsafe { +""" diff --git a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/AuthPlayground.kt b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/AuthPlayground.kt index e9236bb63..e86b96d7e 100644 --- a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/AuthPlayground.kt +++ b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/AuthPlayground.kt @@ -7,6 +7,7 @@ import io.bkbn.kompendium.core.Notarized.notarizedGet import io.bkbn.kompendium.core.metadata.ResponseInfo import io.bkbn.kompendium.core.metadata.method.GetInfo import io.bkbn.kompendium.core.routes.redoc +import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule import io.bkbn.kompendium.playground.AuthPlaygroundToC.simpleAuthenticatedGet import io.bkbn.kompendium.playground.util.Util import io.ktor.application.Application @@ -23,6 +24,7 @@ import io.ktor.serialization.json import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json /** * Application entrypoint. Run this and head on over to `localhost:8081/docs` @@ -39,7 +41,11 @@ fun main() { // Application Module private fun Application.mainModule() { install(ContentNegotiation) { - json() + json(Json { + serializersModule = KompendiumSerializersModule.module + encodeDefaults = true + explicitNulls = false + }) } install(Kompendium) { spec = Util.baseSpec diff --git a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/BasicPlayground.kt b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/BasicPlayground.kt index 60b8226c0..0584572d2 100644 --- a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/BasicPlayground.kt +++ b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/BasicPlayground.kt @@ -15,6 +15,8 @@ import io.bkbn.kompendium.core.metadata.method.DeleteInfo import io.bkbn.kompendium.core.metadata.method.GetInfo import io.bkbn.kompendium.core.metadata.method.PostInfo import io.bkbn.kompendium.core.routes.redoc +import io.bkbn.kompendium.core.routes.swagger +import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule import io.bkbn.kompendium.playground.BasicModels.BasicParameters import io.bkbn.kompendium.playground.BasicModels.BasicRequest import io.bkbn.kompendium.playground.BasicModels.BasicResponse @@ -37,6 +39,7 @@ import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json import java.util.UUID /** @@ -55,7 +58,11 @@ fun main() { private fun Application.mainModule() { // Installs Simple JSON Content Negotiation install(ContentNegotiation) { - json() + json(Json { + serializersModule = KompendiumSerializersModule.module + encodeDefaults = true + explicitNulls = false + }) } // Installs the Kompendium Plugin and sets up baseline server metadata install(Kompendium) { @@ -66,6 +73,8 @@ private fun Application.mainModule() { // This adds ReDoc support at the `/docs` endpoint. // By default, it will point at the `/openapi.json` created by Kompendium redoc(pageTitle = "Simple API Docs") + // You can also use swagger! + swagger(pageTitle = "Swaggerlicious") // Kompendium infers the route path from the Ktor Route. This will show up as the root path `/` notarizedGet(simpleGetExample) { call.respond(HttpStatusCode.OK, BasicResponse(c = UUID.randomUUID().toString())) diff --git a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/ConstraintPlayground.kt b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/ConstraintPlayground.kt index bbe7369b4..6f412549e 100644 --- a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/ConstraintPlayground.kt +++ b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/ConstraintPlayground.kt @@ -23,6 +23,7 @@ import io.bkbn.kompendium.core.metadata.ResponseInfo import io.bkbn.kompendium.core.metadata.method.GetInfo import io.bkbn.kompendium.core.metadata.method.PostInfo import io.bkbn.kompendium.core.routes.redoc +import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule import io.bkbn.kompendium.playground.ConstrainedModels.ConstrainedParams import io.bkbn.kompendium.playground.ConstrainedModels.ConstrainedRequest import io.bkbn.kompendium.playground.ConstrainedModels.ConstrainedResponse @@ -40,6 +41,7 @@ import io.ktor.serialization.json import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonElement fun main() { @@ -54,7 +56,11 @@ fun main() { private fun Application.mainModule() { // Installs Simple JSON Content Negotiation install(ContentNegotiation) { - json() + json(Json { + serializersModule = KompendiumSerializersModule.module + encodeDefaults = true + explicitNulls = false + }) } // Installs the Kompendium Plugin and sets up baseline server metadata install(Kompendium) { diff --git a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/ExceptionPlayground.kt b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/ExceptionPlayground.kt index ec0dda8c9..f23564030 100644 --- a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/ExceptionPlayground.kt +++ b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/ExceptionPlayground.kt @@ -6,6 +6,7 @@ import io.bkbn.kompendium.core.metadata.ExceptionInfo import io.bkbn.kompendium.core.metadata.ResponseInfo import io.bkbn.kompendium.core.metadata.method.GetInfo import io.bkbn.kompendium.core.routes.redoc +import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule import io.bkbn.kompendium.playground.ExceptionPlaygroundToC.simpleGetExample import io.bkbn.kompendium.playground.util.Util import io.ktor.application.Application @@ -21,6 +22,7 @@ import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty import kotlin.reflect.typeOf import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json import java.time.LocalDateTime // Application Entrypoint @@ -36,7 +38,11 @@ fun main() { private fun Application.mainModule() { // Installs Simple JSON Content Negotiation install(ContentNegotiation) { - json() + json(Json { + serializersModule = KompendiumSerializersModule.module + encodeDefaults = true + explicitNulls = false + }) } // Installs the Kompendium Plugin and sets up baseline server metadata install(Kompendium) { diff --git a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/GenericPlayground.kt b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/GenericPlayground.kt index d9dc487bb..d08d36623 100644 --- a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/GenericPlayground.kt +++ b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/GenericPlayground.kt @@ -5,6 +5,7 @@ import io.bkbn.kompendium.core.Notarized.notarizedGet import io.bkbn.kompendium.core.metadata.ResponseInfo import io.bkbn.kompendium.core.metadata.method.GetInfo import io.bkbn.kompendium.core.routes.redoc +import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule import io.bkbn.kompendium.playground.GenericPlaygroundToC.simpleGenericGet import io.bkbn.kompendium.playground.util.Util import io.ktor.application.Application @@ -18,6 +19,7 @@ import io.ktor.serialization.json import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json /** * Application entrypoint. Run this and head on over to `localhost:8081/docs` @@ -35,7 +37,11 @@ fun main() { private fun Application.mainModule() { // Installs Simple JSON Content Negotiation install(ContentNegotiation) { - json() + json(Json { + serializersModule = KompendiumSerializersModule.module + encodeDefaults = true + explicitNulls = false + }) } // Installs the Kompendium Plugin and sets up baseline server metadata install(Kompendium) { diff --git a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/LocationPlayground.kt b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/LocationPlayground.kt index adb16a4c9..e69337b5c 100644 --- a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/LocationPlayground.kt +++ b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/LocationPlayground.kt @@ -7,6 +7,7 @@ import io.bkbn.kompendium.core.metadata.ResponseInfo import io.bkbn.kompendium.core.metadata.method.GetInfo import io.bkbn.kompendium.core.routes.redoc import io.bkbn.kompendium.locations.NotarizedLocation.notarizedGet +import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule import io.bkbn.kompendium.playground.LocationsToC.ohBoiUCrazy import io.bkbn.kompendium.playground.LocationsToC.testLocation import io.bkbn.kompendium.playground.LocationsToC.testNestLocation @@ -24,6 +25,7 @@ import io.ktor.serialization.json import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json /** * Application entrypoint. Run this and head on over to `localhost:8081/docs` @@ -39,7 +41,11 @@ fun main() { private fun Application.mainModule() { install(ContentNegotiation) { - json() + json(Json { + serializersModule = KompendiumSerializersModule.module + encodeDefaults = true + explicitNulls = false + }) } install(Kompendium) { spec = Util.baseSpec diff --git a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/PolymorphicPlayground.kt b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/PolymorphicPlayground.kt index 669e19ee5..155769404 100644 --- a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/PolymorphicPlayground.kt +++ b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/PolymorphicPlayground.kt @@ -5,6 +5,7 @@ import io.bkbn.kompendium.core.Notarized.notarizedGet import io.bkbn.kompendium.core.metadata.ResponseInfo import io.bkbn.kompendium.core.metadata.method.GetInfo import io.bkbn.kompendium.core.routes.redoc +import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule import io.bkbn.kompendium.playground.PolymorphicPlaygroundToC.polymorphicExample import io.bkbn.kompendium.playground.util.Util import io.ktor.application.Application @@ -18,6 +19,7 @@ import io.ktor.serialization.json import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json /** * Application entrypoint. Run this and head on over to `localhost:8081/docs` @@ -34,7 +36,11 @@ fun main() { private fun Application.mainModule() { // Installs Simple JSON Content Negotiation install(ContentNegotiation) { - json() + json(Json { + serializersModule = KompendiumSerializersModule.module + encodeDefaults = true + explicitNulls = false + }) } // Installs the Kompendium Plugin and sets up baseline server metadata install(Kompendium) { diff --git a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/RecursionPlayground.kt b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/RecursionPlayground.kt index 7132aa612..28b0a2116 100644 --- a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/RecursionPlayground.kt +++ b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/RecursionPlayground.kt @@ -6,6 +6,7 @@ import io.bkbn.kompendium.core.Notarized.notarizedGet import io.bkbn.kompendium.core.metadata.ResponseInfo import io.bkbn.kompendium.core.metadata.method.GetInfo import io.bkbn.kompendium.core.routes.redoc +import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule import io.bkbn.kompendium.playground.util.Util import io.ktor.application.Application import io.ktor.application.call @@ -19,6 +20,7 @@ import io.ktor.serialization.json import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json enum class ColumnMode { NULLABLE, @@ -58,7 +60,11 @@ fun main() { private fun Application.mainModule() { install(ContentNegotiation) { - json() + json(Json { + serializersModule = KompendiumSerializersModule.module + encodeDefaults = true + explicitNulls = false + }) } install(Kompendium) { spec = Util.baseSpec diff --git a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/SwaggerPlayground.kt b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/SwaggerPlayground.kt index 11a72632a..a7affc8ec 100644 --- a/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/SwaggerPlayground.kt +++ b/kompendium-playground/src/main/kotlin/io/bkbn/kompendium/playground/SwaggerPlayground.kt @@ -3,6 +3,7 @@ package io.bkbn.kompendium.playground import io.bkbn.kompendium.core.Kompendium import io.bkbn.kompendium.core.Notarized.notarizedGet import io.bkbn.kompendium.core.routes.swagger +import io.bkbn.kompendium.oas.serialization.KompendiumSerializersModule import io.bkbn.kompendium.playground.util.Util import io.ktor.application.Application import io.ktor.application.call @@ -15,6 +16,7 @@ import io.ktor.serialization.json import io.ktor.server.engine.embeddedServer import io.ktor.server.netty.Netty import io.ktor.webjars.Webjars +import kotlinx.serialization.json.Json import java.util.UUID /** @@ -33,7 +35,11 @@ fun main() { private fun Application.mainModule() { // Installs Simple JSON Content Negotiation install(ContentNegotiation) { - json() + json(Json { + serializersModule = KompendiumSerializersModule.module + encodeDefaults = true + explicitNulls = false + }) } install(Webjars) // Installs the Kompendium Plugin and sets up baseline server metadata