Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
SMILEY4 committed Nov 11, 2023
2 parents 6ac0055 + 335faba commit e1a9f58
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 65 deletions.
26 changes: 13 additions & 13 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand All @@ -45,39 +45,39 @@ 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.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")

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
}
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<WithFieldNames>(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<Int>(true).also { defs ->
defs.definitions.keys shouldContainExactly setOf("int")
Expand Down Expand Up @@ -149,6 +119,31 @@ class SchemaBuilderTest : StringSpec({
}
}

"object with special field names (victools)" {
createSchemaVictools<WithFieldNames>(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<Pet>(true).also { defs ->
defs.definitions.keys shouldContainExactly setOf("1d8t6cs0dbcap", "x1xjd3yo2dbzzz", "xq0zwcprkn9j3")
Expand Down Expand Up @@ -209,6 +204,31 @@ class SchemaBuilderTest : StringSpec({
}
}

"object with special field names (kotlinx)" {
createSchemaKotlinX<WithFieldNames>(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)" {
Expand Down Expand Up @@ -432,7 +452,8 @@ class SchemaBuilderTest : StringSpec({

)

data class WithFieldNames(
@Serializable
class WithFieldNames(
val flag: Boolean,
val isSomething: Boolean,
val text: String,
Expand All @@ -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)
Expand Down

0 comments on commit e1a9f58

Please sign in to comment.