diff --git a/build.gradle.kts b/build.gradle.kts index af0b4b6..3bd7533 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "io.github.smiley4" -version = "1.3.1" +version = "1.3.2" repositories { mavenCentral() diff --git a/src/main/kotlin/io/github/smiley4/ktorswaggerui/specbuilder/OApiSchemaBuilder.kt b/src/main/kotlin/io/github/smiley4/ktorswaggerui/specbuilder/OApiSchemaBuilder.kt index 513ccb9..0db699c 100644 --- a/src/main/kotlin/io/github/smiley4/ktorswaggerui/specbuilder/OApiSchemaBuilder.kt +++ b/src/main/kotlin/io/github/smiley4/ktorswaggerui/specbuilder/OApiSchemaBuilder.kt @@ -1,23 +1,83 @@ package io.github.smiley4.ktorswaggerui.specbuilder +import com.fasterxml.jackson.core.type.TypeReference import io.github.smiley4.ktorswaggerui.SwaggerUIPluginConfig import io.swagger.v3.oas.models.media.Schema import java.io.File import java.lang.reflect.Type import java.math.BigDecimal -import kotlin.reflect.KClass /** * Builder for an OpenAPI Schema Object */ class OApiSchemaBuilder { - private val jsonSchemaBuilder = OApiJsonSchemaBuilder() + private companion object { + + private val BYTE: Type = (object : TypeReference() {}.type) + private val SHORT: Type = (object : TypeReference() {}.type) + private val INT: Type = (object : TypeReference() {}.type) + private val LONG: Type = (object : TypeReference() {}.type) + private val UBYTE: Type = (object : TypeReference() {}.type) + private val USHORT: Type = (object : TypeReference() {}.type) + private val UINT: Type = (object : TypeReference() {}.type) + private val ULONG: Type = (object : TypeReference() {}.type) + private val FLOAT: Type = (object : TypeReference() {}.type) + private val DOUBLE: Type = (object : TypeReference() {}.type) + private val BOOLEAN: Type = (object : TypeReference() {}.type) + private val CHAR: Type = (object : TypeReference() {}.type) + private val STRING: Type = (object : TypeReference() {}.type) + private val ARRAY_BYTE: Type = (object : TypeReference>() {}.type) + private val ARRAY_SHORT: Type = (object : TypeReference>() {}.type) + private val ARRAY_INT: Type = (object : TypeReference>() {}.type) + private val ARRAY_LONG: Type = (object : TypeReference>() {}.type) + private val ARRAY_UBYTE: Type = (object : TypeReference>() {}.type) + private val ARRAY_USHORT: Type = (object : TypeReference>() {}.type) + private val ARRAY_UINT: Type = (object : TypeReference>() {}.type) + private val ARRAY_ULONG: Type = (object : TypeReference>() {}.type) + private val ARRAY_FLOAT: Type = (object : TypeReference>() {}.type) + private val ARRAY_DOUBLE: Type = (object : TypeReference>() {}.type) + private val ARRAY_CHAR: Type = (object : TypeReference>() {}.type) + private val ARRAY_STRING: Type = (object : TypeReference>() {}.type) + private val FILE: Type = (object : TypeReference() {}.type) + + fun typeRefToJavaType(type: Type): Type = when (type) { + BYTE -> Byte::class.java + SHORT -> Short::class.java + INT -> Int::class.java + LONG -> Long::class.java + UBYTE -> UByte::class.java + USHORT -> UShort::class.java + UINT -> UInt::class.java + ULONG -> ULong::class.java + FLOAT -> Float::class.java + DOUBLE -> Double::class.java + BOOLEAN -> Boolean::class.java + CHAR -> Char::class.java + STRING -> String::class.java + ARRAY_BYTE -> Array::class.java + ARRAY_SHORT -> Array::class.java + ARRAY_INT -> Array::class.java + ARRAY_LONG -> Array::class.java + ARRAY_UBYTE -> Array::class.java + ARRAY_USHORT -> Array::class.java + ARRAY_UINT -> Array::class.java + ARRAY_ULONG -> Array::class.java + ARRAY_FLOAT -> Array::class.java + ARRAY_DOUBLE -> Array::class.java + ARRAY_CHAR -> Array::class.java + ARRAY_STRING -> Array::class.java + FILE -> File::class.java + else -> type + } + } + + private val jsonSchemaBuilder = OApiJsonSchemaBuilder() fun build(type: Type, components: ComponentsContext, config: SwaggerUIPluginConfig): Schema { return Schema().apply { - when (type) { + when (typeRefToJavaType(type)) { Byte::class.java -> { this.type = "integer" minimum = BigDecimal.valueOf(Byte.MIN_VALUE.toLong())