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)