chore: prep for 3.3.0 (#319)

This commit is contained in:
Ryan Brink
2022-09-15 08:27:17 -05:00
committed by GitHub
parent fdcc64d29c
commit 95ae274f1d
36 changed files with 138 additions and 78 deletions

View File

@ -2,10 +2,6 @@
## Unreleased ## Unreleased
- Support for @Transient annotation
- Support for @SerialName annotation on fields
- Supports for un-backed fields, by excluding them from the generated schema.
### Added ### Added
### Changed ### Changed
@ -16,6 +12,19 @@
## Released ## Released
## [3.3.0] - September 15th, 2022
### Added
- Support for @Transient annotation
- Support for @SerialName annotation on fields
- Supports for un-backed fields, by excluding them from the generated schema.
### Changed
- Actually turned on detekt formatting 🤦
- Removed some rouge print statements
## Released
## [3.2.0] - August 23rd, 2022 ## [3.2.0] - August 23rd, 2022
### Added ### Added

View File

@ -22,6 +22,7 @@ dependencies {
// VERSIONS // VERSIONS
val kotestVersion: String by project val kotestVersion: String by project
val ktorVersion: String by project val ktorVersion: String by project
val detektVersion: String by project
// IMPLEMENTATION // IMPLEMENTATION
@ -35,6 +36,9 @@ dependencies {
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion") implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion")
implementation("ch.qos.logback:logback-classic:1.4.1") implementation("ch.qos.logback:logback-classic:1.4.1")
// Formatting
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
// TEST FIXTURES // TEST FIXTURES
testFixturesApi("io.kotest:kotest-runner-junit5-jvm:$kotestVersion") testFixturesApi("io.kotest:kotest-runner-junit5-jvm:$kotestVersion")

View File

@ -13,7 +13,7 @@ class DeleteInfo private constructor(
override val operationId: String?, override val operationId: String?,
override val deprecated: Boolean, override val deprecated: Boolean,
override val parameters: List<Parameter> override val parameters: List<Parameter>
): MethodInfo { ) : MethodInfo {
companion object { companion object {
fun builder(init: Builder.() -> Unit): DeleteInfo { fun builder(init: Builder.() -> Unit): DeleteInfo {
@ -36,5 +36,4 @@ class DeleteInfo private constructor(
parameters = parameters parameters = parameters
) )
} }
} }

View File

@ -13,7 +13,7 @@ class GetInfo private constructor(
override val operationId: String?, override val operationId: String?,
override val deprecated: Boolean, override val deprecated: Boolean,
override val parameters: List<Parameter> override val parameters: List<Parameter>
): MethodInfo { ) : MethodInfo {
companion object { companion object {
fun builder(init: Builder.() -> Unit): GetInfo { fun builder(init: Builder.() -> Unit): GetInfo {
@ -36,5 +36,4 @@ class GetInfo private constructor(
parameters = parameters parameters = parameters
) )
} }
} }

View File

@ -13,7 +13,7 @@ class HeadInfo private constructor(
override val operationId: String?, override val operationId: String?,
override val deprecated: Boolean, override val deprecated: Boolean,
override val parameters: List<Parameter> override val parameters: List<Parameter>
): MethodInfo { ) : MethodInfo {
companion object { companion object {
fun builder(init: Builder.() -> Unit): HeadInfo { fun builder(init: Builder.() -> Unit): HeadInfo {
@ -36,5 +36,4 @@ class HeadInfo private constructor(
parameters = parameters parameters = parameters
) )
} }
} }

View File

@ -3,7 +3,7 @@ package io.bkbn.kompendium.core.metadata
sealed interface MethodInfoWithRequest : MethodInfo { sealed interface MethodInfoWithRequest : MethodInfo {
val request: RequestInfo val request: RequestInfo
abstract class Builder<T: MethodInfoWithRequest> : MethodInfo.Builder<T>() { abstract class Builder<T : MethodInfoWithRequest> : MethodInfo.Builder<T>() {
internal var request: RequestInfo? = null internal var request: RequestInfo? = null
fun request(init: RequestInfo.Builder.() -> Unit) = apply { fun request(init: RequestInfo.Builder.() -> Unit) = apply {

View File

@ -13,7 +13,7 @@ class OptionsInfo private constructor(
override val operationId: String?, override val operationId: String?,
override val deprecated: Boolean, override val deprecated: Boolean,
override val parameters: List<Parameter> override val parameters: List<Parameter>
): MethodInfo { ) : MethodInfo {
companion object { companion object {
fun builder(init: Builder.() -> Unit): OptionsInfo { fun builder(init: Builder.() -> Unit): OptionsInfo {
@ -36,5 +36,4 @@ class OptionsInfo private constructor(
parameters = parameters parameters = parameters
) )
} }
} }

View File

@ -14,7 +14,7 @@ class PatchInfo private constructor(
override val operationId: String?, override val operationId: String?,
override val deprecated: Boolean, override val deprecated: Boolean,
override val parameters: List<Parameter> override val parameters: List<Parameter>
): MethodInfoWithRequest { ) : MethodInfoWithRequest {
companion object { companion object {
fun builder(init: Builder.() -> Unit): PatchInfo { fun builder(init: Builder.() -> Unit): PatchInfo {
@ -38,5 +38,4 @@ class PatchInfo private constructor(
parameters = parameters parameters = parameters
) )
} }
} }

View File

@ -14,7 +14,7 @@ class PostInfo private constructor(
override val operationId: String?, override val operationId: String?,
override val deprecated: Boolean, override val deprecated: Boolean,
override val parameters: List<Parameter> override val parameters: List<Parameter>
): MethodInfoWithRequest { ) : MethodInfoWithRequest {
companion object { companion object {
fun builder(init: Builder.() -> Unit): PostInfo { fun builder(init: Builder.() -> Unit): PostInfo {
@ -38,5 +38,4 @@ class PostInfo private constructor(
parameters = parameters parameters = parameters
) )
} }
} }

View File

@ -14,7 +14,7 @@ class PutInfo private constructor(
override val operationId: String?, override val operationId: String?,
override val deprecated: Boolean, override val deprecated: Boolean,
override val parameters: List<Parameter> override val parameters: List<Parameter>
): MethodInfoWithRequest { ) : MethodInfoWithRequest {
companion object { companion object {
fun builder(init: Builder.() -> Unit): PutInfo { fun builder(init: Builder.() -> Unit): PutInfo {
@ -38,5 +38,4 @@ class PutInfo private constructor(
parameters = parameters parameters = parameters
) )
} }
} }

View File

@ -41,5 +41,4 @@ class RequestInfo private constructor(
examples = examples examples = examples
) )
} }
} }

View File

@ -54,9 +54,9 @@ object NotarizedRoute {
pluginConfig.path?.addDefaultAuthMethods(authMethods) pluginConfig.path?.addDefaultAuthMethods(authMethods)
require(spec.paths[routePath] == null) { require(spec.paths[routePath] == null) {
""" """
The specified path ${Parameter.Location.path} has already been documented! The specified path ${Parameter.Location.path} has already been documented!
Please make sure that all notarized paths are unique Please make sure that all notarized paths are unique
""".trimIndent() """.trimIndent()
} }
spec.paths[routePath] = pluginConfig.path spec.paths[routePath] = pluginConfig.path
?: error("This indicates a bug in Kompendium. Please file a GitHub issue!") ?: error("This indicates a bug in Kompendium. Please file a GitHub issue!")

View File

@ -46,7 +46,7 @@ fun Route.redoc(pageTitle: String = "Docs", specUrl: String = "/openapi.json") {
} }
} }
body { body {
unsafe { +"<redoc spec-url='${specUrl}'></redoc>" } unsafe { +"<redoc spec-url='$specUrl'></redoc>" }
script { script {
src = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js" src = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"
} }

View File

@ -10,8 +10,8 @@ import io.bkbn.kompendium.core.metadata.PatchInfo
import io.bkbn.kompendium.core.metadata.PostInfo import io.bkbn.kompendium.core.metadata.PostInfo
import io.bkbn.kompendium.core.metadata.PutInfo import io.bkbn.kompendium.core.metadata.PutInfo
import io.bkbn.kompendium.core.metadata.ResponseInfo import io.bkbn.kompendium.core.metadata.ResponseInfo
import io.bkbn.kompendium.json.schema.SchemaGenerator
import io.bkbn.kompendium.json.schema.SchemaConfigurator import io.bkbn.kompendium.json.schema.SchemaConfigurator
import io.bkbn.kompendium.json.schema.SchemaGenerator
import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition
import io.bkbn.kompendium.json.schema.util.Helpers.getReferenceSlug import io.bkbn.kompendium.json.schema.util.Helpers.getReferenceSlug
import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug

View File

@ -10,11 +10,6 @@ import io.bkbn.kompendium.core.util.TestModules.defaultAuthConfig
import io.bkbn.kompendium.core.util.TestModules.defaultField import io.bkbn.kompendium.core.util.TestModules.defaultField
import io.bkbn.kompendium.core.util.TestModules.defaultParameter import io.bkbn.kompendium.core.util.TestModules.defaultParameter
import io.bkbn.kompendium.core.util.TestModules.exampleParams import io.bkbn.kompendium.core.util.TestModules.exampleParams
import io.bkbn.kompendium.core.util.TestModules.nestedUnderRoot
import io.bkbn.kompendium.core.util.TestModules.nonRequiredParams
import io.bkbn.kompendium.core.util.TestModules.notarizedDelete
import io.bkbn.kompendium.core.util.TestModules.notarizedGet
import io.bkbn.kompendium.core.util.TestModules.singleException
import io.bkbn.kompendium.core.util.TestModules.genericException import io.bkbn.kompendium.core.util.TestModules.genericException
import io.bkbn.kompendium.core.util.TestModules.genericPolymorphicResponse import io.bkbn.kompendium.core.util.TestModules.genericPolymorphicResponse
import io.bkbn.kompendium.core.util.TestModules.genericPolymorphicResponseMultipleImpls import io.bkbn.kompendium.core.util.TestModules.genericPolymorphicResponseMultipleImpls
@ -27,8 +22,11 @@ import io.bkbn.kompendium.core.util.TestModules.nestedGenericCollection
import io.bkbn.kompendium.core.util.TestModules.nestedGenericMultipleParamsCollection import io.bkbn.kompendium.core.util.TestModules.nestedGenericMultipleParamsCollection
import io.bkbn.kompendium.core.util.TestModules.nestedGenericResponse import io.bkbn.kompendium.core.util.TestModules.nestedGenericResponse
import io.bkbn.kompendium.core.util.TestModules.nestedTypeName import io.bkbn.kompendium.core.util.TestModules.nestedTypeName
import io.bkbn.kompendium.core.util.TestModules.nestedUnderRoot
import io.bkbn.kompendium.core.util.TestModules.nonRequiredParam import io.bkbn.kompendium.core.util.TestModules.nonRequiredParam
import io.bkbn.kompendium.core.util.TestModules.polymorphicException import io.bkbn.kompendium.core.util.TestModules.nonRequiredParams
import io.bkbn.kompendium.core.util.TestModules.notarizedDelete
import io.bkbn.kompendium.core.util.TestModules.notarizedGet
import io.bkbn.kompendium.core.util.TestModules.notarizedHead import io.bkbn.kompendium.core.util.TestModules.notarizedHead
import io.bkbn.kompendium.core.util.TestModules.notarizedOptions import io.bkbn.kompendium.core.util.TestModules.notarizedOptions
import io.bkbn.kompendium.core.util.TestModules.notarizedPatch import io.bkbn.kompendium.core.util.TestModules.notarizedPatch
@ -39,6 +37,7 @@ import io.bkbn.kompendium.core.util.TestModules.nullableField
import io.bkbn.kompendium.core.util.TestModules.nullableNestedObject import io.bkbn.kompendium.core.util.TestModules.nullableNestedObject
import io.bkbn.kompendium.core.util.TestModules.nullableReference import io.bkbn.kompendium.core.util.TestModules.nullableReference
import io.bkbn.kompendium.core.util.TestModules.polymorphicCollectionResponse import io.bkbn.kompendium.core.util.TestModules.polymorphicCollectionResponse
import io.bkbn.kompendium.core.util.TestModules.polymorphicException
import io.bkbn.kompendium.core.util.TestModules.polymorphicMapResponse import io.bkbn.kompendium.core.util.TestModules.polymorphicMapResponse
import io.bkbn.kompendium.core.util.TestModules.polymorphicResponse import io.bkbn.kompendium.core.util.TestModules.polymorphicResponse
import io.bkbn.kompendium.core.util.TestModules.primitives import io.bkbn.kompendium.core.util.TestModules.primitives
@ -49,6 +48,7 @@ import io.bkbn.kompendium.core.util.TestModules.rootRoute
import io.bkbn.kompendium.core.util.TestModules.simpleGenericResponse import io.bkbn.kompendium.core.util.TestModules.simpleGenericResponse
import io.bkbn.kompendium.core.util.TestModules.simplePathParsing import io.bkbn.kompendium.core.util.TestModules.simplePathParsing
import io.bkbn.kompendium.core.util.TestModules.simpleRecursive import io.bkbn.kompendium.core.util.TestModules.simpleRecursive
import io.bkbn.kompendium.core.util.TestModules.singleException
import io.bkbn.kompendium.core.util.TestModules.trailingSlash import io.bkbn.kompendium.core.util.TestModules.trailingSlash
import io.bkbn.kompendium.core.util.TestModules.unbackedFieldsResponse import io.bkbn.kompendium.core.util.TestModules.unbackedFieldsResponse
import io.bkbn.kompendium.core.util.TestModules.withOperationId import io.bkbn.kompendium.core.util.TestModules.withOperationId
@ -189,7 +189,9 @@ class KompendiumTest : DescribeSpec({
openApiTestAllSerializers("T0039__nested_generic_collection.json") { nestedGenericCollection() } openApiTestAllSerializers("T0039__nested_generic_collection.json") { nestedGenericCollection() }
} }
it("Can support nested generics with multiple type parameters") { it("Can support nested generics with multiple type parameters") {
openApiTestAllSerializers("T0040__nested_generic_multiple_type_params.json") { nestedGenericMultipleParamsCollection() } openApiTestAllSerializers("T0040__nested_generic_multiple_type_params.json") {
nestedGenericMultipleParamsCollection()
}
} }
it("Can handle a really gnarly generic example") { it("Can handle a really gnarly generic example") {
openApiTestAllSerializers("T0043__gnarly_generic_example.json") { gnarlyGenericResponse() } openApiTestAllSerializers("T0043__gnarly_generic_example.json") { gnarlyGenericResponse() }

View File

@ -1,6 +1,30 @@
package io.bkbn.kompendium.core.util package io.bkbn.kompendium.core.util
import io.bkbn.kompendium.core.fixtures.* import io.bkbn.kompendium.core.fixtures.Barzo
import io.bkbn.kompendium.core.fixtures.ColumnSchema
import io.bkbn.kompendium.core.fixtures.ComplexRequest
import io.bkbn.kompendium.core.fixtures.DateTimeString
import io.bkbn.kompendium.core.fixtures.DefaultField
import io.bkbn.kompendium.core.fixtures.ExceptionResponse
import io.bkbn.kompendium.core.fixtures.Flibbity
import io.bkbn.kompendium.core.fixtures.FlibbityGibbit
import io.bkbn.kompendium.core.fixtures.Foosy
import io.bkbn.kompendium.core.fixtures.Gibbity
import io.bkbn.kompendium.core.fixtures.ManyThings
import io.bkbn.kompendium.core.fixtures.MultiNestedGenerics
import io.bkbn.kompendium.core.fixtures.Nested
import io.bkbn.kompendium.core.fixtures.NullableEnum
import io.bkbn.kompendium.core.fixtures.NullableField
import io.bkbn.kompendium.core.fixtures.Page
import io.bkbn.kompendium.core.fixtures.ProfileUpdateRequest
import io.bkbn.kompendium.core.fixtures.SerialNameObject
import io.bkbn.kompendium.core.fixtures.TestCreatedResponse
import io.bkbn.kompendium.core.fixtures.TestNested
import io.bkbn.kompendium.core.fixtures.TestRequest
import io.bkbn.kompendium.core.fixtures.TestResponse
import io.bkbn.kompendium.core.fixtures.TestSimpleRequest
import io.bkbn.kompendium.core.fixtures.TransientObject
import io.bkbn.kompendium.core.fixtures.UnbakcedObject
import io.bkbn.kompendium.core.metadata.DeleteInfo import io.bkbn.kompendium.core.metadata.DeleteInfo
import io.bkbn.kompendium.core.metadata.GetInfo import io.bkbn.kompendium.core.metadata.GetInfo
import io.bkbn.kompendium.core.metadata.HeadInfo import io.bkbn.kompendium.core.metadata.HeadInfo

View File

@ -15,6 +15,13 @@ style:
excludeCommentStatements: true excludeCommentStatements: true
MagicNumber: MagicNumber:
excludes: ['**/kompendium-playground/**/*', '**/test/**/*'] excludes: ['**/kompendium-playground/**/*', '**/test/**/*']
ForbiddenMethodCall:
active: true
formatting:
Indentation:
indentSize: 2
ImportOrdering:
active: false
naming: naming:
ConstructorParameterNaming: ConstructorParameterNaming:
active: false active: false

View File

@ -1,5 +1,5 @@
# Kompendium # Kompendium
project.version=3.2.0 project.version=3.3.0
# Kotlin # Kotlin
kotlin.code.style=official kotlin.code.style=official
# Gradle # Gradle
@ -10,3 +10,4 @@ org.gradle.jvmargs=-Xmx2000m
# Dependencies # Dependencies
ktorVersion=2.1.1 ktorVersion=2.1.1
kotestVersion=5.4.2 kotestVersion=5.4.2
detektVersion=1.21.0

View File

@ -18,9 +18,15 @@ sourdoughLibrary {
} }
dependencies { dependencies {
// Versions
val detektVersion: String by project
implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.10") implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.10")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0")
// Formatting
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
testImplementation(testFixtures(projects.kompendiumCore)) testImplementation(testFixtures(projects.kompendiumCore))
} }

View File

@ -7,7 +7,7 @@ import kotlin.reflect.KProperty1
import kotlin.reflect.full.hasAnnotation import kotlin.reflect.full.hasAnnotation
import kotlin.reflect.full.memberProperties import kotlin.reflect.full.memberProperties
class KotlinXSchemaConfigurator: SchemaConfigurator { class KotlinXSchemaConfigurator : SchemaConfigurator {
override fun serializableMemberProperties(clazz: KClass<*>): Collection<KProperty1<out Any, *>> = override fun serializableMemberProperties(clazz: KClass<*>): Collection<KProperty1<out Any, *>> =
clazz.memberProperties clazz.memberProperties
@ -16,5 +16,5 @@ class KotlinXSchemaConfigurator: SchemaConfigurator {
override fun serializableName(property: KProperty1<out Any, *>): String = override fun serializableName(property: KProperty1<out Any, *>): String =
property.annotations property.annotations
.filterIsInstance<SerialName>() .filterIsInstance<SerialName>()
.firstOrNull()?.value?: property.name .firstOrNull()?.value ?: property.name
} }

View File

@ -8,11 +8,10 @@ interface SchemaConfigurator {
fun serializableMemberProperties(clazz: KClass<*>): Collection<KProperty1<out Any, *>> fun serializableMemberProperties(clazz: KClass<*>): Collection<KProperty1<out Any, *>>
fun serializableName(property: KProperty1<out Any, *>): String fun serializableName(property: KProperty1<out Any, *>): String
open class Default: SchemaConfigurator { open class Default : SchemaConfigurator {
override fun serializableMemberProperties(clazz: KClass<*>): Collection<KProperty1<out Any, *>> override fun serializableMemberProperties(clazz: KClass<*>): Collection<KProperty1<out Any, *>> =
= clazz.memberProperties clazz.memberProperties
override fun serializableName(property: KProperty1<out Any, *>): String
= property.name
}
override fun serializableName(property: KProperty1<out Any, *>): String = property.name
}
} }

View File

@ -7,8 +7,8 @@ import io.bkbn.kompendium.json.schema.definition.TypeDefinition
import io.bkbn.kompendium.json.schema.handler.CollectionHandler import io.bkbn.kompendium.json.schema.handler.CollectionHandler
import io.bkbn.kompendium.json.schema.handler.EnumHandler import io.bkbn.kompendium.json.schema.handler.EnumHandler
import io.bkbn.kompendium.json.schema.handler.MapHandler import io.bkbn.kompendium.json.schema.handler.MapHandler
import io.bkbn.kompendium.json.schema.handler.SimpleObjectHandler
import io.bkbn.kompendium.json.schema.handler.SealedObjectHandler import io.bkbn.kompendium.json.schema.handler.SealedObjectHandler
import io.bkbn.kompendium.json.schema.handler.SimpleObjectHandler
import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug
import kotlin.reflect.KClass import kotlin.reflect.KClass
import kotlin.reflect.KType import kotlin.reflect.KType
@ -39,6 +39,7 @@ object SchemaGenerator {
please call SchemaGenerator.fromTypeOrUnit() please call SchemaGenerator.fromTypeOrUnit()
""".trimIndent() """.trimIndent()
) )
Int::class -> checkForNull(type, TypeDefinition.INT) Int::class -> checkForNull(type, TypeDefinition.INT)
Long::class -> checkForNull(type, TypeDefinition.LONG) Long::class -> checkForNull(type, TypeDefinition.LONG)
Double::class -> checkForNull(type, TypeDefinition.DOUBLE) Double::class -> checkForNull(type, TypeDefinition.DOUBLE)
@ -71,7 +72,7 @@ object SchemaGenerator {
else -> fromTypeToSchema(type, cache, schemaConfigurator) else -> fromTypeToSchema(type, cache, schemaConfigurator)
} }
private fun checkForNull(type: KType, schema: JsonSchema, ): JsonSchema = when (type.isMarkedNullable) { private fun checkForNull(type: KType, schema: JsonSchema): JsonSchema = when (type.isMarkedNullable) {
true -> OneOfDefinition(NullableDefinition(), schema) true -> OneOfDefinition(NullableDefinition(), schema)
false -> schema false -> schema
} }

View File

@ -1,7 +1,7 @@
package io.bkbn.kompendium.json.schema.handler package io.bkbn.kompendium.json.schema.handler
import io.bkbn.kompendium.json.schema.SchemaGenerator
import io.bkbn.kompendium.json.schema.SchemaConfigurator import io.bkbn.kompendium.json.schema.SchemaConfigurator
import io.bkbn.kompendium.json.schema.SchemaGenerator
import io.bkbn.kompendium.json.schema.definition.ArrayDefinition import io.bkbn.kompendium.json.schema.definition.ArrayDefinition
import io.bkbn.kompendium.json.schema.definition.JsonSchema import io.bkbn.kompendium.json.schema.definition.JsonSchema
import io.bkbn.kompendium.json.schema.definition.NullableDefinition import io.bkbn.kompendium.json.schema.definition.NullableDefinition
@ -13,7 +13,6 @@ import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug
import kotlin.reflect.KType import kotlin.reflect.KType
object CollectionHandler { object CollectionHandler {
fun handle(type: KType, cache: MutableMap<String, JsonSchema>, schemaConfigurator: SchemaConfigurator): JsonSchema { fun handle(type: KType, cache: MutableMap<String, JsonSchema>, schemaConfigurator: SchemaConfigurator): JsonSchema {
val collectionType = type.arguments.first().type val collectionType = type.arguments.first().type
?: error("This indicates a bug in Kompendium, please open a GitHub issue!") ?: error("This indicates a bug in Kompendium, please open a GitHub issue!")
@ -31,5 +30,4 @@ object CollectionHandler {
false -> definition false -> definition
} }
} }
} }

View File

@ -8,7 +8,6 @@ import kotlin.reflect.KClass
import kotlin.reflect.KType import kotlin.reflect.KType
object EnumHandler { object EnumHandler {
fun handle(type: KType, clazz: KClass<*>): JsonSchema { fun handle(type: KType, clazz: KClass<*>): JsonSchema {
val options = clazz.java.enumConstants.map { it.toString() }.toSet() val options = clazz.java.enumConstants.map { it.toString() }.toSet()
val definition = EnumDefinition(enum = options) val definition = EnumDefinition(enum = options)
@ -17,5 +16,4 @@ object EnumHandler {
false -> definition false -> definition
} }
} }
} }

View File

@ -1,7 +1,7 @@
package io.bkbn.kompendium.json.schema.handler package io.bkbn.kompendium.json.schema.handler
import io.bkbn.kompendium.json.schema.SchemaGenerator
import io.bkbn.kompendium.json.schema.SchemaConfigurator import io.bkbn.kompendium.json.schema.SchemaConfigurator
import io.bkbn.kompendium.json.schema.SchemaGenerator
import io.bkbn.kompendium.json.schema.definition.JsonSchema import io.bkbn.kompendium.json.schema.definition.JsonSchema
import io.bkbn.kompendium.json.schema.definition.MapDefinition import io.bkbn.kompendium.json.schema.definition.MapDefinition
import io.bkbn.kompendium.json.schema.definition.NullableDefinition import io.bkbn.kompendium.json.schema.definition.NullableDefinition
@ -34,5 +34,4 @@ object MapHandler {
false -> definition false -> definition
} }
} }
} }

View File

@ -1,7 +1,7 @@
package io.bkbn.kompendium.json.schema.handler package io.bkbn.kompendium.json.schema.handler
import io.bkbn.kompendium.json.schema.SchemaGenerator
import io.bkbn.kompendium.json.schema.SchemaConfigurator import io.bkbn.kompendium.json.schema.SchemaConfigurator
import io.bkbn.kompendium.json.schema.SchemaGenerator
import io.bkbn.kompendium.json.schema.definition.AnyOfDefinition import io.bkbn.kompendium.json.schema.definition.AnyOfDefinition
import io.bkbn.kompendium.json.schema.definition.JsonSchema import io.bkbn.kompendium.json.schema.definition.JsonSchema
import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition

View File

@ -1,7 +1,7 @@
package io.bkbn.kompendium.json.schema.handler package io.bkbn.kompendium.json.schema.handler
import io.bkbn.kompendium.json.schema.SchemaGenerator
import io.bkbn.kompendium.json.schema.SchemaConfigurator import io.bkbn.kompendium.json.schema.SchemaConfigurator
import io.bkbn.kompendium.json.schema.SchemaGenerator
import io.bkbn.kompendium.json.schema.definition.JsonSchema import io.bkbn.kompendium.json.schema.definition.JsonSchema
import io.bkbn.kompendium.json.schema.definition.NullableDefinition import io.bkbn.kompendium.json.schema.definition.NullableDefinition
import io.bkbn.kompendium.json.schema.definition.OneOfDefinition import io.bkbn.kompendium.json.schema.definition.OneOfDefinition
@ -33,21 +33,21 @@ object SimpleObjectHandler {
val props = schemaConfigurator.serializableMemberProperties(clazz) val props = schemaConfigurator.serializableMemberProperties(clazz)
.filterNot { it.javaField == null } .filterNot { it.javaField == null }
.associate { prop -> .associate { prop ->
val schema = when (prop.needsToInjectGenerics(typeMap)) { val schema = when (prop.needsToInjectGenerics(typeMap)) {
true -> handleNestedGenerics(typeMap, prop, cache, schemaConfigurator) true -> handleNestedGenerics(typeMap, prop, cache, schemaConfigurator)
false -> when (typeMap.containsKey(prop.returnType.classifier)) { false -> when (typeMap.containsKey(prop.returnType.classifier)) {
true -> handleGenericProperty(prop, typeMap, cache, schemaConfigurator) true -> handleGenericProperty(prop, typeMap, cache, schemaConfigurator)
false -> handleProperty(prop, cache, schemaConfigurator) false -> handleProperty(prop, cache, schemaConfigurator)
}
} }
}
val nullCheckSchema = when (prop.returnType.isMarkedNullable && !schema.isNullable()) { val nullCheckSchema = when (prop.returnType.isMarkedNullable && !schema.isNullable()) {
true -> OneOfDefinition(NullableDefinition(), schema) true -> OneOfDefinition(NullableDefinition(), schema)
false -> schema false -> schema
} }
schemaConfigurator.serializableName(prop) to nullCheckSchema schemaConfigurator.serializableName(prop) to nullCheckSchema
} }
val required = schemaConfigurator.serializableMemberProperties(clazz) val required = schemaConfigurator.serializableMemberProperties(clazz)
.asSequence() .asSequence()

View File

@ -1,7 +1,15 @@
package io.bkbn.kompendium.json.schema package io.bkbn.kompendium.json.schema
import io.bkbn.kompendium.core.fixtures.* import io.bkbn.kompendium.core.fixtures.ComplexRequest
import io.bkbn.kompendium.core.fixtures.FlibbityGibbit
import io.bkbn.kompendium.core.fixtures.SerialNameObject
import io.bkbn.kompendium.core.fixtures.SimpleEnum
import io.bkbn.kompendium.core.fixtures.SlammaJamma
import io.bkbn.kompendium.core.fixtures.TestHelpers.getFileSnapshot import io.bkbn.kompendium.core.fixtures.TestHelpers.getFileSnapshot
import io.bkbn.kompendium.core.fixtures.TestResponse
import io.bkbn.kompendium.core.fixtures.TestSimpleRequest
import io.bkbn.kompendium.core.fixtures.TransientObject
import io.bkbn.kompendium.core.fixtures.UnbakcedObject
import io.bkbn.kompendium.json.schema.definition.JsonSchema import io.bkbn.kompendium.json.schema.definition.JsonSchema
import io.kotest.assertions.json.shouldEqualJson import io.kotest.assertions.json.shouldEqualJson
import io.kotest.assertions.throwables.shouldThrow import io.kotest.assertions.throwables.shouldThrow

View File

@ -17,6 +17,9 @@ sourdoughLibrary {
} }
dependencies { dependencies {
// Versions
val detektVersion: String by project
// IMPLEMENTATION // IMPLEMENTATION
implementation(projects.kompendiumCore) implementation(projects.kompendiumCore)
@ -26,6 +29,9 @@ dependencies {
// TESTING // TESTING
testImplementation(testFixtures(projects.kompendiumCore)) testImplementation(testFixtures(projects.kompendiumCore))
// Formatting
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
} }
testing { testing {

View File

@ -43,6 +43,7 @@ object NotarizedLocations {
name = "NotarizedLocations", name = "NotarizedLocations",
createConfiguration = ::Config createConfiguration = ::Config
) { ) {
println("hi")
val spec = application.attributes[KompendiumAttributes.openApiSpec] val spec = application.attributes[KompendiumAttributes.openApiSpec]
val serializableReader = application.attributes[KompendiumAttributes.schemaConfigurator] val serializableReader = application.attributes[KompendiumAttributes.schemaConfigurator]
pluginConfig.locations.forEach { (k, v) -> pluginConfig.locations.forEach { (k, v) ->

View File

@ -18,9 +18,15 @@ sourdoughLibrary {
} }
dependencies { dependencies {
// Versions
val detektVersion: String by project
api(projects.kompendiumJsonSchema) api(projects.kompendiumJsonSchema)
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0")
// Formatting
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
testImplementation(testFixtures(projects.kompendiumCore)) testImplementation(testFixtures(projects.kompendiumCore))
} }

View File

@ -12,6 +12,6 @@ import kotlinx.serialization.Serializable
*/ */
@Serializable @Serializable
data class Components( data class Components(
val schemas: MutableMap<String, JsonSchema> = mutableMapOf(), val schemas: MutableMap<String, JsonSchema> = mutableMapOf(),
val securitySchemes: MutableMap<String, SecuritySchema> = mutableMapOf() val securitySchemes: MutableMap<String, SecuritySchema> = mutableMapOf()
) )

View File

@ -16,10 +16,10 @@ import kotlinx.serialization.Serializable
*/ */
@Serializable @Serializable
data class Header( data class Header(
val schema: JsonSchema, val schema: JsonSchema,
val description: String? = null, val description: String? = null,
val required: Boolean = true, val required: Boolean = true,
val deprecated: Boolean = false, val deprecated: Boolean = false,
val allowEmptyValue: Boolean? = null, val allowEmptyValue: Boolean? = null,
// todo support styling https://spec.openapis.org/oas/v3.1.0#style-values // todo support styling https://spec.openapis.org/oas/v3.1.0#style-values
) )

View File

@ -15,9 +15,9 @@ import kotlinx.serialization.Serializable
*/ */
@Serializable @Serializable
data class MediaType( data class MediaType(
val schema: JsonSchema, val schema: JsonSchema,
val examples: Map<String, Example>? = null, val examples: Map<String, Example>? = null,
val encoding: Map<String, Encoding>? = null, val encoding: Map<String, Encoding>? = null,
) { ) {
@Serializable @Serializable
data class Example(@Contextual val value: Any) data class Example(@Contextual val value: Any)

View File

@ -3,7 +3,7 @@ package io.bkbn.kompendium.oas.security
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
@Serializable @Serializable
data class BearerAuth(val bearerFormat: String? = null): SecuritySchema { data class BearerAuth(val bearerFormat: String? = null) : SecuritySchema {
val type: String = "http" val type: String = "http"
val scheme: String = "bearer" val scheme: String = "bearer"
} }

View File

@ -16,5 +16,4 @@ object UriSerializer : KSerializer<URI> {
override fun serialize(encoder: Encoder, value: URI) { override fun serialize(encoder: Encoder, value: URI) {
encoder.encodeString(value.toString()) encoder.encodeString(value.toString())
} }
} }