From 66ed37077f917e28a7e57be9ca7bc91a320a638d Mon Sep 17 00:00:00 2001 From: Lukas Ruegner Date: Fri, 20 Oct 2023 18:39:20 +0200 Subject: [PATCH 1/3] set version to 2.7.0 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index 0bca512d..c450c178 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ import io.gitlab.arturbosch.detekt.Detekt object Meta { const val groupId = "io.github.smiley4" const val artifactId = "ktor-swagger-ui" - const val version = "2.6.0" + const val version = "2.7.0" const val name = "Ktor Swagger-UI" const val description = "Ktor plugin to document routes and provide Swagger UI" const val licenseName = "The Apache License, Version 2.0" From fc0cc757fbc4b6e9656d982e753c3d4459f55a10 Mon Sep 17 00:00:00 2001 From: Lukas Ruegner Date: Sat, 11 Nov 2023 13:42:17 +0100 Subject: [PATCH 2/3] upgrade victools-jsonschemagenerator to latest version --- build.gradle.kts | 2 +- .../ktorswaggerui/data/EncodingData.kt | 1 - .../tests/schema/SchemaBuilderTest.kt | 90 +++++++++++-------- 3 files changed, 56 insertions(+), 37 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index c450c178..63032ed6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -51,7 +51,7 @@ dependencies { val swaggerParserVersion = "2.1.13" implementation("io.swagger.parser.v3:swagger-parser:$swaggerParserVersion") - val jsonSchemaGeneratorVersion = "4.28.0" + val jsonSchemaGeneratorVersion = "4.32.0" implementation("com.github.victools:jsonschema-generator:$jsonSchemaGeneratorVersion") implementation("com.github.victools:jsonschema-module-jackson:$jsonSchemaGeneratorVersion") implementation("com.github.victools:jsonschema-module-swagger-2:$jsonSchemaGeneratorVersion") diff --git a/src/main/kotlin/io/github/smiley4/ktorswaggerui/data/EncodingData.kt b/src/main/kotlin/io/github/smiley4/ktorswaggerui/data/EncodingData.kt index a87c9245..111c618e 100644 --- a/src/main/kotlin/io/github/smiley4/ktorswaggerui/data/EncodingData.kt +++ b/src/main/kotlin/io/github/smiley4/ktorswaggerui/data/EncodingData.kt @@ -82,7 +82,6 @@ data class EncodingData( */ fun schemaGeneratorConfigBuilder(): SchemaGeneratorConfigBuilder = SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON) - .with(JacksonModule()) .with(Swagger2Module()) .with(Option.EXTRA_OPEN_API_FORMAT_VALUES) .with(Option.ALLOF_CLEANUP_AT_THE_END) diff --git a/src/test/kotlin/io/github/smiley4/ktorswaggerui/tests/schema/SchemaBuilderTest.kt b/src/test/kotlin/io/github/smiley4/ktorswaggerui/tests/schema/SchemaBuilderTest.kt index 44ef34d6..7102e82a 100644 --- a/src/test/kotlin/io/github/smiley4/ktorswaggerui/tests/schema/SchemaBuilderTest.kt +++ b/src/test/kotlin/io/github/smiley4/ktorswaggerui/tests/schema/SchemaBuilderTest.kt @@ -7,15 +7,14 @@ import com.github.victools.jsonschema.generator.OptionPreset import com.github.victools.jsonschema.generator.SchemaGenerator import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder import com.github.victools.jsonschema.generator.SchemaVersion -import com.github.victools.jsonschema.module.jackson.JacksonModule import com.github.victools.jsonschema.module.swagger2.Swagger2Module -import io.github.smiley4.ktorswaggerui.dsl.Example -import io.github.smiley4.ktorswaggerui.dsl.SchemaEncoder -import io.github.smiley4.ktorswaggerui.dsl.getSchemaType import io.github.smiley4.ktorswaggerui.builder.schema.SchemaBuilder import io.github.smiley4.ktorswaggerui.builder.schema.SchemaDefinitions import io.github.smiley4.ktorswaggerui.builder.schema.SchemaTypeAttributeOverride import io.github.smiley4.ktorswaggerui.builder.schema.TypeOverwrites +import io.github.smiley4.ktorswaggerui.dsl.Example +import io.github.smiley4.ktorswaggerui.dsl.SchemaEncoder +import io.github.smiley4.ktorswaggerui.dsl.getSchemaType import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.collections.shouldContainExactly import io.kotest.matchers.maps.shouldHaveSize @@ -30,35 +29,6 @@ import kotlin.reflect.jvm.javaType class SchemaBuilderTest : StringSpec({ - "victools field names".config(enabled = false) { - /** - * Test-case for https://github.com/SMILEY4/ktor-swagger-ui/issues/60. - * -> victools incorrectly ignores fields with is[A-Z] - */ - createSchemaVictools(false).also { defs -> - defs.root.also { schema -> - schema.`$ref` shouldBe null - schema.type shouldBe "object" - schema.properties.keys shouldContainExactly setOf("flag", "getAnotherText", "text", "isSomething", "isSomeText") - schema.properties["flag"]!!.also { prop -> - prop.type shouldBe "boolean" - } - schema.properties["isSomething"]!!.also { prop -> - prop.type shouldBe "boolean" - } - schema.properties["text"]!!.also { prop -> - prop.type shouldBe "string" - } - schema.properties["getAnotherText"]!!.also { prop -> - prop.type shouldBe "string" - } - schema.properties["isSomeText"]!!.also { prop -> - prop.type shouldBe "string" - } - } - } - } - "primitive (victools, all definitions)" { createSchemaVictools(true).also { defs -> defs.definitions.keys shouldContainExactly setOf("int") @@ -149,6 +119,31 @@ class SchemaBuilderTest : StringSpec({ } } + "object with special field names (victools)" { + createSchemaVictools(false).also { defs -> + defs.root.also { schema -> + schema.`$ref` shouldBe null + schema.type shouldBe "object" + schema.properties.keys shouldContainExactly setOf("flag", "getAnotherText", "text", "isSomething", "isSomeText") + schema.properties["flag"]!!.also { prop -> + prop.type shouldBe "boolean" + } + schema.properties["isSomething"]!!.also { prop -> + prop.type shouldBe "boolean" + } + schema.properties["text"]!!.also { prop -> + prop.type shouldBe "string" + } + schema.properties["getAnotherText"]!!.also { prop -> + prop.type shouldBe "string" + } + schema.properties["isSomeText"]!!.also { prop -> + prop.type shouldBe "string" + } + } + } + } + "simple object (kotlinx, definitions)" { createSchemaKotlinX(true).also { defs -> defs.definitions.keys shouldContainExactly setOf("1d8t6cs0dbcap", "x1xjd3yo2dbzzz", "xq0zwcprkn9j3") @@ -209,6 +204,31 @@ class SchemaBuilderTest : StringSpec({ } } + "object with special field names (kotlinx)" { + createSchemaKotlinX(false).also { defs -> + defs.root.also { schema -> + schema.`$ref` shouldBe null + schema.type shouldBe "object" + schema.properties.keys shouldContainExactly setOf("flag", "getAnotherText", "text", "isSomething", "isSomeText") + schema.properties["flag"]!!.also { prop -> + prop.type shouldBe "boolean" + } + schema.properties["isSomething"]!!.also { prop -> + prop.type shouldBe "boolean" + } + schema.properties["text"]!!.also { prop -> + prop.type shouldBe "string" + } + schema.properties["getAnotherText"]!!.also { prop -> + prop.type shouldBe "string" + } + schema.properties["isSomeText"]!!.also { prop -> + prop.type shouldBe "string" + } + } + } + } + //==== SIMPLE LIST ===================================================== "simple list (victools, all definitions)" { @@ -432,7 +452,8 @@ class SchemaBuilderTest : StringSpec({ ) - data class WithFieldNames( + @Serializable + class WithFieldNames( val flag: Boolean, val isSomething: Boolean, val text: String, @@ -457,7 +478,6 @@ class SchemaBuilderTest : StringSpec({ return { type -> SchemaGenerator( SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON) - .with(JacksonModule()) .with(Swagger2Module()) .with(Option.EXTRA_OPEN_API_FORMAT_VALUES) .with(Option.ALLOF_CLEANUP_AT_THE_END) From a352c8be4b5b8fae28850a44652622f7d8414501 Mon Sep 17 00:00:00 2001 From: Lukas Ruegner Date: Sat, 11 Nov 2023 14:06:28 +0100 Subject: [PATCH 3/3] upgrade versions of dependencies --- build.gradle.kts | 22 ++++++++-------- .../smiley4/ktorswaggerui/SwaggerPlugin.kt | 2 +- .../data/SwaggerUiSyntaxHighlight.kt | 3 ++- .../ktorswaggerui/routing/ResourceContent.kt | 2 +- .../ktorswaggerui/tests/ApplicationTests.kt | 26 +++++++++---------- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 63032ed6..90398f0d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,7 +33,7 @@ repositories { dependencies { - val ktorVersion = "2.3.3" + val ktorVersion = "2.3.6" implementation("io.ktor:ktor-server-core-jvm:$ktorVersion") implementation("io.ktor:ktor-server-webjars:$ktorVersion") implementation("io.ktor:ktor-server-auth:$ktorVersion") @@ -45,10 +45,10 @@ dependencies { testImplementation("io.ktor:ktor-server-call-logging:$ktorVersion") testImplementation("io.ktor:ktor-server-test-host:$ktorVersion") - val swaggerUiVersion = "4.15.0" // this version must match the version declared in the code (SwaggerPlugin#SWAGGER_UI_WEBJARS_VERSION) + val swaggerUiVersion = "5.9.0" // this version must match the version declared in the code (SwaggerPlugin#SWAGGER_UI_WEBJARS_VERSION) implementation("org.webjars:swagger-ui:$swaggerUiVersion") - val swaggerParserVersion = "2.1.13" + val swaggerParserVersion = "2.1.18" implementation("io.swagger.parser.v3:swagger-parser:$swaggerParserVersion") val jsonSchemaGeneratorVersion = "4.32.0" @@ -56,28 +56,28 @@ dependencies { implementation("com.github.victools:jsonschema-module-jackson:$jsonSchemaGeneratorVersion") implementation("com.github.victools:jsonschema-module-swagger-2:$jsonSchemaGeneratorVersion") - val jacksonVersion = "2.14.2" + val jacksonVersion = "2.15.3" implementation("com.fasterxml.jackson.module:jackson-module-kotlin:${jacksonVersion}") - val kotlinLoggingVersion = "2.1.23" + val kotlinLoggingVersion = "3.0.5" implementation("io.github.microutils:kotlin-logging-jvm:$kotlinLoggingVersion") - val logbackVersion = "1.4.5" + val logbackVersion = "1.4.11" testImplementation("ch.qos.logback:logback-classic:$logbackVersion") - val versionMockk = "1.12.7" + val versionMockk = "1.13.8" testImplementation("io.mockk:mockk:$versionMockk") - val versionKotest = "5.7.2" + val versionKotest = "5.8.0" testImplementation("io.kotest:kotest-runner-junit5:$versionKotest") testImplementation("io.kotest:kotest-assertions-core:$versionKotest") - val versionKotlinTest = "1.7.21" + val versionKotlinTest = "1.8.21" testImplementation("org.jetbrains.kotlin:kotlin-test:$versionKotlinTest") - testImplementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1") + testImplementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0") testImplementation("com.github.Ricky12Awesome:json-schema-serialization:0.9.9") - testImplementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.0") + testImplementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1") } kotlin { diff --git a/src/main/kotlin/io/github/smiley4/ktorswaggerui/SwaggerPlugin.kt b/src/main/kotlin/io/github/smiley4/ktorswaggerui/SwaggerPlugin.kt index 372f874c..e111b085 100644 --- a/src/main/kotlin/io/github/smiley4/ktorswaggerui/SwaggerPlugin.kt +++ b/src/main/kotlin/io/github/smiley4/ktorswaggerui/SwaggerPlugin.kt @@ -52,7 +52,7 @@ import mu.KotlinLogging /** * This version must match the version of the gradle dependency */ -internal const val SWAGGER_UI_WEBJARS_VERSION = "4.15.0" +internal const val SWAGGER_UI_WEBJARS_VERSION = "5.9.0" private val logger = KotlinLogging.logger {} diff --git a/src/main/kotlin/io/github/smiley4/ktorswaggerui/data/SwaggerUiSyntaxHighlight.kt b/src/main/kotlin/io/github/smiley4/ktorswaggerui/data/SwaggerUiSyntaxHighlight.kt index 749adf29..3d38d957 100644 --- a/src/main/kotlin/io/github/smiley4/ktorswaggerui/data/SwaggerUiSyntaxHighlight.kt +++ b/src/main/kotlin/io/github/smiley4/ktorswaggerui/data/SwaggerUiSyntaxHighlight.kt @@ -6,5 +6,6 @@ enum class SwaggerUiSyntaxHighlight(val value: String) { MONOKAI("monokai"), NORD("nord"), OBSIDIAN("obsidian"), - TOMORROW_NIGHT("tomorrow-night") + TOMORROW_NIGHT("tomorrow-night"), + IDEA("idea") } diff --git a/src/main/kotlin/io/github/smiley4/ktorswaggerui/routing/ResourceContent.kt b/src/main/kotlin/io/github/smiley4/ktorswaggerui/routing/ResourceContent.kt index 9523187a..81d63f1d 100644 --- a/src/main/kotlin/io/github/smiley4/ktorswaggerui/routing/ResourceContent.kt +++ b/src/main/kotlin/io/github/smiley4/ktorswaggerui/routing/ResourceContent.kt @@ -11,7 +11,7 @@ class ResourceContent(private val resource: URL) : OutgoingContent.ByteArrayCont "html" to ContentType.Text.Html, "css" to ContentType.Text.CSS, "js" to ContentType.Application.JavaScript, - "json" to ContentType.Application.Json.withCharset(Charsets.UTF_8), + "json" to ContentType.Application.Json, "png" to ContentType.Image.PNG ) diff --git a/src/test/kotlin/io/github/smiley4/ktorswaggerui/tests/ApplicationTests.kt b/src/test/kotlin/io/github/smiley4/ktorswaggerui/tests/ApplicationTests.kt index e9c7fe79..9ab604be 100644 --- a/src/test/kotlin/io/github/smiley4/ktorswaggerui/tests/ApplicationTests.kt +++ b/src/test/kotlin/io/github/smiley4/ktorswaggerui/tests/ApplicationTests.kt @@ -46,12 +46,12 @@ class ApplicationTests { } get("/swagger-ui/swagger-initializer.js").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.JavaScript.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.JavaScript it.body shouldContain "url: \"/swagger-ui/api.json\"" } get("/swagger-ui/api.json").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.Json.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.Json it.body.shouldNotBeEmpty() } } @@ -82,13 +82,13 @@ class ApplicationTests { } get("my-root/swagger-ui/swagger-initializer.js").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.JavaScript.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.JavaScript it.body shouldContain "url: \"/my-root/swagger-ui/api.json\"" } get("my-root/swagger-ui/api.json").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.Json.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.Json it.body.shouldNotBeEmpty() } } @@ -121,12 +121,12 @@ class ApplicationTests { } get("/swagger-ui/swagger-initializer.js").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.JavaScript.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.JavaScript it.body shouldContain "url: \"/swagger-ui/api.json\"" } get("/swagger-ui/api.json").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.Json.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.Json it.body.shouldNotBeEmpty() } } @@ -251,13 +251,13 @@ class ApplicationTests { } get("/test-swagger/swagger-initializer.js").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.JavaScript.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.JavaScript it.body shouldContain "url: \"/test-swagger/api.json\"" } get("/test-swagger/api.json").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.Json.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.Json it.body.shouldNotBeEmpty() } } @@ -327,12 +327,12 @@ class ApplicationTests { } get("/swagger-ui/hello/swagger-initializer.js").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.JavaScript.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.JavaScript it.body shouldContain "url: \"/swagger-ui/hello/hello.json\"" } get("/swagger-ui/hello/hello.json").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.Json.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.Json it.body.shouldNotBeEmpty() } get("/swagger-ui/world").also { @@ -347,12 +347,12 @@ class ApplicationTests { } get("/swagger-ui/world/swagger-initializer.js").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.JavaScript.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.JavaScript it.body shouldContain "url: \"/swagger-ui/world/world.json\"" } get("/swagger-ui/world/world.json").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.Json.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.Json it.body.shouldNotBeEmpty() } } @@ -379,7 +379,7 @@ class ApplicationTests { } get("/swagger-ui/hello/hello.json").also { it.status shouldBe HttpStatusCode.OK - it.contentType shouldBe ContentType.Application.Json.withCharset(Charsets.UTF_8) + it.contentType shouldBe ContentType.Application.Json it.body.shouldNotBeEmpty() } get("/swagger-ui/world/index.html").also {