From 95ae274f1d56e8da0a8211a9bd11498bf77d217e Mon Sep 17 00:00:00 2001 From: Ryan Brink <5607577+unredundant@users.noreply.github.com> Date: Thu, 15 Sep 2022 08:27:17 -0500 Subject: [PATCH] chore: prep for 3.3.0 (#319) --- CHANGELOG.md | 17 +++++++++--- core/build.gradle.kts | 4 +++ .../kompendium/core/metadata/DeleteInfo.kt | 3 +-- .../bkbn/kompendium/core/metadata/GetInfo.kt | 3 +-- .../bkbn/kompendium/core/metadata/HeadInfo.kt | 3 +-- .../core/metadata/MethodInfoWithRequest.kt | 2 +- .../kompendium/core/metadata/OptionsInfo.kt | 3 +-- .../kompendium/core/metadata/PatchInfo.kt | 3 +-- .../bkbn/kompendium/core/metadata/PostInfo.kt | 3 +-- .../bkbn/kompendium/core/metadata/PutInfo.kt | 3 +-- .../kompendium/core/metadata/RequestInfo.kt | 1 - .../kompendium/core/plugin/NotarizedRoute.kt | 6 ++--- .../io/bkbn/kompendium/core/routes/Redoc.kt | 2 +- .../io/bkbn/kompendium/core/util/Helpers.kt | 2 +- .../io/bkbn/kompendium/core/KompendiumTest.kt | 16 +++++++----- .../bkbn/kompendium/core/util/TestModules.kt | 26 ++++++++++++++++++- detekt.yml | 7 +++++ gradle.properties | 3 ++- json-schema/build.gradle.kts | 6 +++++ .../json/schema/KotlinXSchemaConfigurator.kt | 4 +-- .../json/schema/SchemaConfigurator.kt | 11 ++++---- .../kompendium/json/schema/SchemaGenerator.kt | 5 ++-- .../json/schema/handler/CollectionHandler.kt | 4 +-- .../json/schema/handler/EnumHandler.kt | 2 -- .../json/schema/handler/MapHandler.kt | 3 +-- .../schema/handler/SealedObjectHandler.kt | 2 +- .../schema/handler/SimpleObjectHandler.kt | 26 +++++++++---------- .../json/schema/SchemaGeneratorTest.kt | 10 ++++++- locations/build.gradle.kts | 6 +++++ .../locations/NotarizedLocations.kt | 1 + oas/build.gradle.kts | 6 +++++ .../kompendium/oas/component/Components.kt | 4 +-- .../io/bkbn/kompendium/oas/payload/Header.kt | 10 +++---- .../bkbn/kompendium/oas/payload/MediaType.kt | 6 ++--- .../kompendium/oas/security/BearerAuth.kt | 2 +- .../oas/serialization/UriSerializer.kt | 1 - 36 files changed, 138 insertions(+), 78 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e29ffca64..5c24a6b0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,6 @@ ## Unreleased -- Support for @Transient annotation -- Support for @SerialName annotation on fields -- Supports for un-backed fields, by excluding them from the generated schema. - ### Added ### Changed @@ -16,6 +12,19 @@ ## 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 ### Added diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 1ade32bbc..770990324 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { // VERSIONS val kotestVersion: String by project val ktorVersion: String by project + val detektVersion: String by project // IMPLEMENTATION @@ -35,6 +36,9 @@ dependencies { implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion") implementation("ch.qos.logback:logback-classic:1.4.1") + // Formatting + detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion") + // TEST FIXTURES testFixturesApi("io.kotest:kotest-runner-junit5-jvm:$kotestVersion") diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/DeleteInfo.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/DeleteInfo.kt index 4920ce19e..b1a2ba345 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/DeleteInfo.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/DeleteInfo.kt @@ -13,7 +13,7 @@ class DeleteInfo private constructor( override val operationId: String?, override val deprecated: Boolean, override val parameters: List -): MethodInfo { +) : MethodInfo { companion object { fun builder(init: Builder.() -> Unit): DeleteInfo { @@ -36,5 +36,4 @@ class DeleteInfo private constructor( parameters = parameters ) } - } diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/GetInfo.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/GetInfo.kt index c221ad817..9f47184dd 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/GetInfo.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/GetInfo.kt @@ -13,7 +13,7 @@ class GetInfo private constructor( override val operationId: String?, override val deprecated: Boolean, override val parameters: List -): MethodInfo { +) : MethodInfo { companion object { fun builder(init: Builder.() -> Unit): GetInfo { @@ -36,5 +36,4 @@ class GetInfo private constructor( parameters = parameters ) } - } diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/HeadInfo.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/HeadInfo.kt index 4fafac050..f1d7bed54 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/HeadInfo.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/HeadInfo.kt @@ -13,7 +13,7 @@ class HeadInfo private constructor( override val operationId: String?, override val deprecated: Boolean, override val parameters: List -): MethodInfo { +) : MethodInfo { companion object { fun builder(init: Builder.() -> Unit): HeadInfo { @@ -36,5 +36,4 @@ class HeadInfo private constructor( parameters = parameters ) } - } diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/MethodInfoWithRequest.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/MethodInfoWithRequest.kt index a28275aaf..af4c177ef 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/MethodInfoWithRequest.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/MethodInfoWithRequest.kt @@ -3,7 +3,7 @@ package io.bkbn.kompendium.core.metadata sealed interface MethodInfoWithRequest : MethodInfo { val request: RequestInfo - abstract class Builder : MethodInfo.Builder() { + abstract class Builder : MethodInfo.Builder() { internal var request: RequestInfo? = null fun request(init: RequestInfo.Builder.() -> Unit) = apply { diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/OptionsInfo.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/OptionsInfo.kt index 03894baa4..f75268cec 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/OptionsInfo.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/OptionsInfo.kt @@ -13,7 +13,7 @@ class OptionsInfo private constructor( override val operationId: String?, override val deprecated: Boolean, override val parameters: List -): MethodInfo { +) : MethodInfo { companion object { fun builder(init: Builder.() -> Unit): OptionsInfo { @@ -36,5 +36,4 @@ class OptionsInfo private constructor( parameters = parameters ) } - } diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/PatchInfo.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/PatchInfo.kt index 22af59a9d..eabf4f7fb 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/PatchInfo.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/PatchInfo.kt @@ -14,7 +14,7 @@ class PatchInfo private constructor( override val operationId: String?, override val deprecated: Boolean, override val parameters: List -): MethodInfoWithRequest { +) : MethodInfoWithRequest { companion object { fun builder(init: Builder.() -> Unit): PatchInfo { @@ -38,5 +38,4 @@ class PatchInfo private constructor( parameters = parameters ) } - } diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/PostInfo.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/PostInfo.kt index 1af5f603b..d7a406fdc 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/PostInfo.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/PostInfo.kt @@ -14,7 +14,7 @@ class PostInfo private constructor( override val operationId: String?, override val deprecated: Boolean, override val parameters: List -): MethodInfoWithRequest { +) : MethodInfoWithRequest { companion object { fun builder(init: Builder.() -> Unit): PostInfo { @@ -38,5 +38,4 @@ class PostInfo private constructor( parameters = parameters ) } - } diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/PutInfo.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/PutInfo.kt index e064a04bf..152c30b64 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/PutInfo.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/PutInfo.kt @@ -14,7 +14,7 @@ class PutInfo private constructor( override val operationId: String?, override val deprecated: Boolean, override val parameters: List -): MethodInfoWithRequest { +) : MethodInfoWithRequest { companion object { fun builder(init: Builder.() -> Unit): PutInfo { @@ -38,5 +38,4 @@ class PutInfo private constructor( parameters = parameters ) } - } diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/RequestInfo.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/RequestInfo.kt index 49abbf696..3d3b73de8 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/RequestInfo.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/metadata/RequestInfo.kt @@ -41,5 +41,4 @@ class RequestInfo private constructor( examples = examples ) } - } diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/plugin/NotarizedRoute.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/plugin/NotarizedRoute.kt index 932b82233..20de9a33b 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/plugin/NotarizedRoute.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/plugin/NotarizedRoute.kt @@ -54,9 +54,9 @@ object NotarizedRoute { pluginConfig.path?.addDefaultAuthMethods(authMethods) require(spec.paths[routePath] == null) { """ - The specified path ${Parameter.Location.path} has already been documented! - Please make sure that all notarized paths are unique - """.trimIndent() + The specified path ${Parameter.Location.path} has already been documented! + Please make sure that all notarized paths are unique + """.trimIndent() } spec.paths[routePath] = pluginConfig.path ?: error("This indicates a bug in Kompendium. Please file a GitHub issue!") diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/routes/Redoc.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/routes/Redoc.kt index b67061894..87790983e 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/routes/Redoc.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/routes/Redoc.kt @@ -46,7 +46,7 @@ fun Route.redoc(pageTitle: String = "Docs", specUrl: String = "/openapi.json") { } } body { - unsafe { +"" } + unsafe { +"" } script { src = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js" } diff --git a/core/src/main/kotlin/io/bkbn/kompendium/core/util/Helpers.kt b/core/src/main/kotlin/io/bkbn/kompendium/core/util/Helpers.kt index d77e887ba..452594635 100644 --- a/core/src/main/kotlin/io/bkbn/kompendium/core/util/Helpers.kt +++ b/core/src/main/kotlin/io/bkbn/kompendium/core/util/Helpers.kt @@ -10,8 +10,8 @@ import io.bkbn.kompendium.core.metadata.PatchInfo import io.bkbn.kompendium.core.metadata.PostInfo import io.bkbn.kompendium.core.metadata.PutInfo 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.SchemaGenerator 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.getSimpleSlug diff --git a/core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt b/core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt index 88d1d2ac7..a7f2bd365 100644 --- a/core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt +++ b/core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt @@ -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.defaultParameter 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.genericPolymorphicResponse 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.nestedGenericResponse 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.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.notarizedOptions 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.nullableReference 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.polymorphicResponse 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.simplePathParsing 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.unbackedFieldsResponse import io.bkbn.kompendium.core.util.TestModules.withOperationId @@ -189,7 +189,9 @@ class KompendiumTest : DescribeSpec({ openApiTestAllSerializers("T0039__nested_generic_collection.json") { nestedGenericCollection() } } 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") { openApiTestAllSerializers("T0043__gnarly_generic_example.json") { gnarlyGenericResponse() } diff --git a/core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt b/core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt index 36f839af0..aecb2e798 100644 --- a/core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt +++ b/core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt @@ -1,6 +1,30 @@ 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.GetInfo import io.bkbn.kompendium.core.metadata.HeadInfo diff --git a/detekt.yml b/detekt.yml index 6c38a00ac..6006f3146 100644 --- a/detekt.yml +++ b/detekt.yml @@ -15,6 +15,13 @@ style: excludeCommentStatements: true MagicNumber: excludes: ['**/kompendium-playground/**/*', '**/test/**/*'] + ForbiddenMethodCall: + active: true +formatting: + Indentation: + indentSize: 2 + ImportOrdering: + active: false naming: ConstructorParameterNaming: active: false diff --git a/gradle.properties b/gradle.properties index 1cc9f0abc..0f0661aef 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Kompendium -project.version=3.2.0 +project.version=3.3.0 # Kotlin kotlin.code.style=official # Gradle @@ -10,3 +10,4 @@ org.gradle.jvmargs=-Xmx2000m # Dependencies ktorVersion=2.1.1 kotestVersion=5.4.2 +detektVersion=1.21.0 diff --git a/json-schema/build.gradle.kts b/json-schema/build.gradle.kts index 2c67227c6..b110642cc 100644 --- a/json-schema/build.gradle.kts +++ b/json-schema/build.gradle.kts @@ -18,9 +18,15 @@ sourdoughLibrary { } dependencies { + // Versions + val detektVersion: String by project + implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.10") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0") + // Formatting + detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion") + testImplementation(testFixtures(projects.kompendiumCore)) } diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/KotlinXSchemaConfigurator.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/KotlinXSchemaConfigurator.kt index 06153da62..2bac18c38 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/KotlinXSchemaConfigurator.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/KotlinXSchemaConfigurator.kt @@ -7,7 +7,7 @@ import kotlin.reflect.KProperty1 import kotlin.reflect.full.hasAnnotation import kotlin.reflect.full.memberProperties -class KotlinXSchemaConfigurator: SchemaConfigurator { +class KotlinXSchemaConfigurator : SchemaConfigurator { override fun serializableMemberProperties(clazz: KClass<*>): Collection> = clazz.memberProperties @@ -16,5 +16,5 @@ class KotlinXSchemaConfigurator: SchemaConfigurator { override fun serializableName(property: KProperty1): String = property.annotations .filterIsInstance() - .firstOrNull()?.value?: property.name + .firstOrNull()?.value ?: property.name } diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/SchemaConfigurator.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/SchemaConfigurator.kt index 41a692ef9..2d9213e3a 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/SchemaConfigurator.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/SchemaConfigurator.kt @@ -8,11 +8,10 @@ interface SchemaConfigurator { fun serializableMemberProperties(clazz: KClass<*>): Collection> fun serializableName(property: KProperty1): String - open class Default: SchemaConfigurator { - override fun serializableMemberProperties(clazz: KClass<*>): Collection> - = clazz.memberProperties - override fun serializableName(property: KProperty1): String - = property.name - } + open class Default : SchemaConfigurator { + override fun serializableMemberProperties(clazz: KClass<*>): Collection> = + clazz.memberProperties + override fun serializableName(property: KProperty1): String = property.name + } } diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/SchemaGenerator.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/SchemaGenerator.kt index 01a9dcd18..561d2f0d1 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/SchemaGenerator.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/SchemaGenerator.kt @@ -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.EnumHandler 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.SimpleObjectHandler import io.bkbn.kompendium.json.schema.util.Helpers.getSimpleSlug import kotlin.reflect.KClass import kotlin.reflect.KType @@ -39,6 +39,7 @@ object SchemaGenerator { please call SchemaGenerator.fromTypeOrUnit() """.trimIndent() ) + Int::class -> checkForNull(type, TypeDefinition.INT) Long::class -> checkForNull(type, TypeDefinition.LONG) Double::class -> checkForNull(type, TypeDefinition.DOUBLE) @@ -71,7 +72,7 @@ object SchemaGenerator { 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) false -> schema } diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/CollectionHandler.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/CollectionHandler.kt index 3d11c9781..49c8c3801 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/CollectionHandler.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/CollectionHandler.kt @@ -1,7 +1,7 @@ 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.SchemaGenerator import io.bkbn.kompendium.json.schema.definition.ArrayDefinition import io.bkbn.kompendium.json.schema.definition.JsonSchema 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 object CollectionHandler { - fun handle(type: KType, cache: MutableMap, schemaConfigurator: SchemaConfigurator): JsonSchema { val collectionType = type.arguments.first().type ?: error("This indicates a bug in Kompendium, please open a GitHub issue!") @@ -31,5 +30,4 @@ object CollectionHandler { false -> definition } } - } diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/EnumHandler.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/EnumHandler.kt index b3744617e..965fd11bb 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/EnumHandler.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/EnumHandler.kt @@ -8,7 +8,6 @@ import kotlin.reflect.KClass import kotlin.reflect.KType object EnumHandler { - fun handle(type: KType, clazz: KClass<*>): JsonSchema { val options = clazz.java.enumConstants.map { it.toString() }.toSet() val definition = EnumDefinition(enum = options) @@ -17,5 +16,4 @@ object EnumHandler { false -> definition } } - } diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/MapHandler.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/MapHandler.kt index ddd36d77b..efaee1b35 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/MapHandler.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/MapHandler.kt @@ -1,7 +1,7 @@ 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.SchemaGenerator import io.bkbn.kompendium.json.schema.definition.JsonSchema import io.bkbn.kompendium.json.schema.definition.MapDefinition import io.bkbn.kompendium.json.schema.definition.NullableDefinition @@ -34,5 +34,4 @@ object MapHandler { false -> definition } } - } diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SealedObjectHandler.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SealedObjectHandler.kt index e63eac476..4a54f823e 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SealedObjectHandler.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SealedObjectHandler.kt @@ -1,7 +1,7 @@ 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.SchemaGenerator import io.bkbn.kompendium.json.schema.definition.AnyOfDefinition import io.bkbn.kompendium.json.schema.definition.JsonSchema import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition diff --git a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SimpleObjectHandler.kt b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SimpleObjectHandler.kt index bafcbf2e3..bb4cd722c 100644 --- a/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SimpleObjectHandler.kt +++ b/json-schema/src/main/kotlin/io/bkbn/kompendium/json/schema/handler/SimpleObjectHandler.kt @@ -1,7 +1,7 @@ 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.SchemaGenerator import io.bkbn.kompendium.json.schema.definition.JsonSchema import io.bkbn.kompendium.json.schema.definition.NullableDefinition import io.bkbn.kompendium.json.schema.definition.OneOfDefinition @@ -33,21 +33,21 @@ object SimpleObjectHandler { val props = schemaConfigurator.serializableMemberProperties(clazz) .filterNot { it.javaField == null } .associate { prop -> - val schema = when (prop.needsToInjectGenerics(typeMap)) { - true -> handleNestedGenerics(typeMap, prop, cache, schemaConfigurator) - false -> when (typeMap.containsKey(prop.returnType.classifier)) { - true -> handleGenericProperty(prop, typeMap, cache, schemaConfigurator) - false -> handleProperty(prop, cache, schemaConfigurator) + val schema = when (prop.needsToInjectGenerics(typeMap)) { + true -> handleNestedGenerics(typeMap, prop, cache, schemaConfigurator) + false -> when (typeMap.containsKey(prop.returnType.classifier)) { + true -> handleGenericProperty(prop, typeMap, cache, schemaConfigurator) + false -> handleProperty(prop, cache, schemaConfigurator) + } } - } - val nullCheckSchema = when (prop.returnType.isMarkedNullable && !schema.isNullable()) { - true -> OneOfDefinition(NullableDefinition(), schema) - false -> schema - } + val nullCheckSchema = when (prop.returnType.isMarkedNullable && !schema.isNullable()) { + true -> OneOfDefinition(NullableDefinition(), schema) + false -> schema + } - schemaConfigurator.serializableName(prop) to nullCheckSchema - } + schemaConfigurator.serializableName(prop) to nullCheckSchema + } val required = schemaConfigurator.serializableMemberProperties(clazz) .asSequence() diff --git a/json-schema/src/test/kotlin/io/bkbn/kompendium/json/schema/SchemaGeneratorTest.kt b/json-schema/src/test/kotlin/io/bkbn/kompendium/json/schema/SchemaGeneratorTest.kt index 440f152d2..5afbb13f9 100644 --- a/json-schema/src/test/kotlin/io/bkbn/kompendium/json/schema/SchemaGeneratorTest.kt +++ b/json-schema/src/test/kotlin/io/bkbn/kompendium/json/schema/SchemaGeneratorTest.kt @@ -1,7 +1,15 @@ 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.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.kotest.assertions.json.shouldEqualJson import io.kotest.assertions.throwables.shouldThrow diff --git a/locations/build.gradle.kts b/locations/build.gradle.kts index fc37d22ff..66e2bee9e 100644 --- a/locations/build.gradle.kts +++ b/locations/build.gradle.kts @@ -17,6 +17,9 @@ sourdoughLibrary { } dependencies { + // Versions + val detektVersion: String by project + // IMPLEMENTATION implementation(projects.kompendiumCore) @@ -26,6 +29,9 @@ dependencies { // TESTING testImplementation(testFixtures(projects.kompendiumCore)) + + // Formatting + detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion") } testing { diff --git a/locations/src/main/kotlin/io/bkbn/kompendium/locations/NotarizedLocations.kt b/locations/src/main/kotlin/io/bkbn/kompendium/locations/NotarizedLocations.kt index 56cfa4c00..14b6811f0 100644 --- a/locations/src/main/kotlin/io/bkbn/kompendium/locations/NotarizedLocations.kt +++ b/locations/src/main/kotlin/io/bkbn/kompendium/locations/NotarizedLocations.kt @@ -43,6 +43,7 @@ object NotarizedLocations { name = "NotarizedLocations", createConfiguration = ::Config ) { + println("hi") val spec = application.attributes[KompendiumAttributes.openApiSpec] val serializableReader = application.attributes[KompendiumAttributes.schemaConfigurator] pluginConfig.locations.forEach { (k, v) -> diff --git a/oas/build.gradle.kts b/oas/build.gradle.kts index 28b9919b6..f01399672 100644 --- a/oas/build.gradle.kts +++ b/oas/build.gradle.kts @@ -18,9 +18,15 @@ sourdoughLibrary { } dependencies { + // Versions + val detektVersion: String by project + api(projects.kompendiumJsonSchema) implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.0") + // Formatting + detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion") + testImplementation(testFixtures(projects.kompendiumCore)) } diff --git a/oas/src/main/kotlin/io/bkbn/kompendium/oas/component/Components.kt b/oas/src/main/kotlin/io/bkbn/kompendium/oas/component/Components.kt index d7d91cc43..f11f8256a 100644 --- a/oas/src/main/kotlin/io/bkbn/kompendium/oas/component/Components.kt +++ b/oas/src/main/kotlin/io/bkbn/kompendium/oas/component/Components.kt @@ -12,6 +12,6 @@ import kotlinx.serialization.Serializable */ @Serializable data class Components( - val schemas: MutableMap = mutableMapOf(), - val securitySchemes: MutableMap = mutableMapOf() + val schemas: MutableMap = mutableMapOf(), + val securitySchemes: MutableMap = mutableMapOf() ) diff --git a/oas/src/main/kotlin/io/bkbn/kompendium/oas/payload/Header.kt b/oas/src/main/kotlin/io/bkbn/kompendium/oas/payload/Header.kt index 1e8644436..2d1a9be56 100644 --- a/oas/src/main/kotlin/io/bkbn/kompendium/oas/payload/Header.kt +++ b/oas/src/main/kotlin/io/bkbn/kompendium/oas/payload/Header.kt @@ -16,10 +16,10 @@ import kotlinx.serialization.Serializable */ @Serializable data class Header( - val schema: JsonSchema, - val description: String? = null, - val required: Boolean = true, - val deprecated: Boolean = false, - val allowEmptyValue: Boolean? = null, + val schema: JsonSchema, + val description: String? = null, + val required: Boolean = true, + val deprecated: Boolean = false, + val allowEmptyValue: Boolean? = null, // todo support styling https://spec.openapis.org/oas/v3.1.0#style-values ) diff --git a/oas/src/main/kotlin/io/bkbn/kompendium/oas/payload/MediaType.kt b/oas/src/main/kotlin/io/bkbn/kompendium/oas/payload/MediaType.kt index 0d01e7785..b743d1287 100644 --- a/oas/src/main/kotlin/io/bkbn/kompendium/oas/payload/MediaType.kt +++ b/oas/src/main/kotlin/io/bkbn/kompendium/oas/payload/MediaType.kt @@ -15,9 +15,9 @@ import kotlinx.serialization.Serializable */ @Serializable data class MediaType( - val schema: JsonSchema, - val examples: Map? = null, - val encoding: Map? = null, + val schema: JsonSchema, + val examples: Map? = null, + val encoding: Map? = null, ) { @Serializable data class Example(@Contextual val value: Any) diff --git a/oas/src/main/kotlin/io/bkbn/kompendium/oas/security/BearerAuth.kt b/oas/src/main/kotlin/io/bkbn/kompendium/oas/security/BearerAuth.kt index 6ede93e02..6002df921 100644 --- a/oas/src/main/kotlin/io/bkbn/kompendium/oas/security/BearerAuth.kt +++ b/oas/src/main/kotlin/io/bkbn/kompendium/oas/security/BearerAuth.kt @@ -3,7 +3,7 @@ package io.bkbn.kompendium.oas.security import kotlinx.serialization.Serializable @Serializable -data class BearerAuth(val bearerFormat: String? = null): SecuritySchema { +data class BearerAuth(val bearerFormat: String? = null) : SecuritySchema { val type: String = "http" val scheme: String = "bearer" } diff --git a/oas/src/main/kotlin/io/bkbn/kompendium/oas/serialization/UriSerializer.kt b/oas/src/main/kotlin/io/bkbn/kompendium/oas/serialization/UriSerializer.kt index b5dc60c21..2b800164a 100644 --- a/oas/src/main/kotlin/io/bkbn/kompendium/oas/serialization/UriSerializer.kt +++ b/oas/src/main/kotlin/io/bkbn/kompendium/oas/serialization/UriSerializer.kt @@ -16,5 +16,4 @@ object UriSerializer : KSerializer { override fun serialize(encoder: Encoder, value: URI) { encoder.encodeString(value.toString()) } - }