Skip to content

Commit

Permalink
chore: prep for 3.3.0 (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
brizzbuzz authored Sep 15, 2022
1 parent fdcc64d commit 95ae274
Show file tree
Hide file tree
Showing 36 changed files with 138 additions and 78 deletions.
17 changes: 13 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
// VERSIONS
val kotestVersion: String by project
val ktorVersion: String by project
val detektVersion: String by project

// IMPLEMENTATION

Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DeleteInfo private constructor(
override val operationId: String?,
override val deprecated: Boolean,
override val parameters: List<Parameter>
): MethodInfo {
) : MethodInfo {

companion object {
fun builder(init: Builder.() -> Unit): DeleteInfo {
Expand All @@ -36,5 +36,4 @@ class DeleteInfo private constructor(
parameters = parameters
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GetInfo private constructor(
override val operationId: String?,
override val deprecated: Boolean,
override val parameters: List<Parameter>
): MethodInfo {
) : MethodInfo {

companion object {
fun builder(init: Builder.() -> Unit): GetInfo {
Expand All @@ -36,5 +36,4 @@ class GetInfo private constructor(
parameters = parameters
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class HeadInfo private constructor(
override val operationId: String?,
override val deprecated: Boolean,
override val parameters: List<Parameter>
): MethodInfo {
) : MethodInfo {

companion object {
fun builder(init: Builder.() -> Unit): HeadInfo {
Expand All @@ -36,5 +36,4 @@ class HeadInfo private constructor(
parameters = parameters
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.bkbn.kompendium.core.metadata
sealed interface MethodInfoWithRequest : MethodInfo {
val request: RequestInfo

abstract class Builder<T: MethodInfoWithRequest> : MethodInfo.Builder<T>() {
abstract class Builder<T : MethodInfoWithRequest> : MethodInfo.Builder<T>() {
internal var request: RequestInfo? = null

fun request(init: RequestInfo.Builder.() -> Unit) = apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class OptionsInfo private constructor(
override val operationId: String?,
override val deprecated: Boolean,
override val parameters: List<Parameter>
): MethodInfo {
) : MethodInfo {

companion object {
fun builder(init: Builder.() -> Unit): OptionsInfo {
Expand All @@ -36,5 +36,4 @@ class OptionsInfo private constructor(
parameters = parameters
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PatchInfo private constructor(
override val operationId: String?,
override val deprecated: Boolean,
override val parameters: List<Parameter>
): MethodInfoWithRequest {
) : MethodInfoWithRequest {

companion object {
fun builder(init: Builder.() -> Unit): PatchInfo {
Expand All @@ -38,5 +38,4 @@ class PatchInfo private constructor(
parameters = parameters
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PostInfo private constructor(
override val operationId: String?,
override val deprecated: Boolean,
override val parameters: List<Parameter>
): MethodInfoWithRequest {
) : MethodInfoWithRequest {

companion object {
fun builder(init: Builder.() -> Unit): PostInfo {
Expand All @@ -38,5 +38,4 @@ class PostInfo private constructor(
parameters = parameters
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PutInfo private constructor(
override val operationId: String?,
override val deprecated: Boolean,
override val parameters: List<Parameter>
): MethodInfoWithRequest {
) : MethodInfoWithRequest {

companion object {
fun builder(init: Builder.() -> Unit): PutInfo {
Expand All @@ -38,5 +38,4 @@ class PutInfo private constructor(
parameters = parameters
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ class RequestInfo private constructor(
examples = examples
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun Route.redoc(pageTitle: String = "Docs", specUrl: String = "/openapi.json") {
}
}
body {
unsafe { +"<redoc spec-url='${specUrl}'></redoc>" }
unsafe { +"<redoc spec-url='$specUrl'></redoc>" }
script {
src = "https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 9 additions & 7 deletions core/src/test/kotlin/io/bkbn/kompendium/core/KompendiumTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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() }
Expand Down
26 changes: 25 additions & 1 deletion core/src/test/kotlin/io/bkbn/kompendium/core/util/TestModules.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Kompendium
project.version=3.2.0
project.version=3.3.0
# Kotlin
kotlin.code.style=official
# Gradle
Expand All @@ -10,3 +10,4 @@ org.gradle.jvmargs=-Xmx2000m
# Dependencies
ktorVersion=2.1.1
kotestVersion=5.4.2
detektVersion=1.21.0
6 changes: 6 additions & 0 deletions json-schema/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<KProperty1<out Any, *>> =
clazz.memberProperties
Expand All @@ -16,5 +16,5 @@ class KotlinXSchemaConfigurator: SchemaConfigurator {
override fun serializableName(property: KProperty1<out Any, *>): String =
property.annotations
.filterIsInstance<SerialName>()
.firstOrNull()?.value?: property.name
.firstOrNull()?.value ?: property.name
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ interface SchemaConfigurator {
fun serializableMemberProperties(clazz: KClass<*>): Collection<KProperty1<out Any, *>>
fun serializableName(property: KProperty1<out Any, *>): String

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

override fun serializableName(property: KProperty1<out Any, *>): String = property.name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
Loading

0 comments on commit 95ae274

Please sign in to comment.