chore: clean up some bad habits

This commit is contained in:
Ryan Brink
2022-08-16 19:11:42 -06:00
parent 3326f10576
commit db696309c8
11 changed files with 32 additions and 29 deletions

View File

@ -25,11 +25,11 @@ class DeleteInfo private constructor(
class Builder : MethodInfo.Builder<DeleteInfo>() { class Builder : MethodInfo.Builder<DeleteInfo>() {
override fun build() = DeleteInfo( override fun build() = DeleteInfo(
response = response!!, response = response ?: error("Response info must be present"),
errors = errors, errors = errors,
tags = tags, tags = tags,
summary = summary!!, summary = summary ?: error("Summary must be present"),
description = description!!, description = description ?: error("Description must be present"),
externalDocumentation = externalDocumentation, externalDocumentation = externalDocumentation,
operationId = operationId, operationId = operationId,
deprecated = deprecated, deprecated = deprecated,

View File

@ -25,11 +25,11 @@ class HeadInfo private constructor(
class Builder : MethodInfo.Builder<HeadInfo>() { class Builder : MethodInfo.Builder<HeadInfo>() {
override fun build() = HeadInfo( override fun build() = HeadInfo(
response = response!!, response = response ?: error("Response info must be present"),
errors = errors, errors = errors,
tags = tags, tags = tags,
summary = summary!!, summary = summary ?: error("Summary must be present"),
description = description!!, description = description ?: error("Description must be present"),
externalDocumentation = externalDocumentation, externalDocumentation = externalDocumentation,
operationId = operationId, operationId = operationId,
deprecated = deprecated, deprecated = deprecated,

View File

@ -25,11 +25,11 @@ class OptionsInfo private constructor(
class Builder : MethodInfo.Builder<OptionsInfo>() { class Builder : MethodInfo.Builder<OptionsInfo>() {
override fun build() = OptionsInfo( override fun build() = OptionsInfo(
response = response!!, response = response ?: error("Response info must be provided!"),
errors = errors, errors = errors,
tags = tags, tags = tags,
summary = summary!!, summary = summary ?: error("Summary must be provided!"),
description = description!!, description = description ?: error("Description must be provided!"),
externalDocumentation = externalDocumentation, externalDocumentation = externalDocumentation,
operationId = operationId, operationId = operationId,
deprecated = deprecated, deprecated = deprecated,

View File

@ -26,12 +26,12 @@ class PatchInfo private constructor(
class Builder : MethodInfoWithRequest.Builder<PatchInfo>() { class Builder : MethodInfoWithRequest.Builder<PatchInfo>() {
override fun build() = PatchInfo( override fun build() = PatchInfo(
request = request!!, request = request ?: error("request info must be present"),
errors = errors, errors = errors,
response = response!!, response = response ?: error("response info must be present"),
tags = tags, tags = tags,
summary = summary!!, summary = summary ?: error("Summary must be present"),
description = description!!, description = description ?: error("Description must be present"),
externalDocumentation = externalDocumentation, externalDocumentation = externalDocumentation,
operationId = operationId, operationId = operationId,
deprecated = deprecated, deprecated = deprecated,

View File

@ -26,12 +26,12 @@ class PostInfo private constructor(
class Builder : MethodInfoWithRequest.Builder<PostInfo>() { class Builder : MethodInfoWithRequest.Builder<PostInfo>() {
override fun build() = PostInfo( override fun build() = PostInfo(
request = request!!, request = request ?: error("request info must be present"),
errors = errors, errors = errors,
response = response!!, response = response ?: error("response info must be present"),
tags = tags, tags = tags,
summary = summary!!, summary = summary ?: error("Summary must be present"),
description = description!!, description = description ?: error("Description must be present"),
externalDocumentation = externalDocumentation, externalDocumentation = externalDocumentation,
operationId = operationId, operationId = operationId,
deprecated = deprecated, deprecated = deprecated,

View File

@ -26,12 +26,12 @@ class PutInfo private constructor(
class Builder : MethodInfoWithRequest.Builder<PutInfo>() { class Builder : MethodInfoWithRequest.Builder<PutInfo>() {
override fun build() = PutInfo( override fun build() = PutInfo(
request = request!!, request = request ?: error("request info must be present"),
errors = errors, errors = errors,
response = response!!, response = response ?: error("response info must be present"),
tags = tags, tags = tags,
summary = summary!!, summary = summary ?: error("Summary must be present"),
description = description!!, description = description ?: error("Description must be present"),
externalDocumentation = externalDocumentation, externalDocumentation = externalDocumentation,
operationId = operationId, operationId = operationId,
deprecated = deprecated, deprecated = deprecated,

View File

@ -37,8 +37,8 @@ class RequestInfo private constructor(
} }
fun build() = RequestInfo( fun build() = RequestInfo(
requestType = requestType!!, requestType = requestType ?: error("Request type must be present"),
description = description!!, description = description ?: error("Description must be present"),
examples = examples examples = examples
) )
} }

View File

@ -55,7 +55,8 @@ object NotarizedRoute {
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!")
} }
val spec = application.attributes[KompendiumAttributes.openApiSpec] val spec = application.attributes[KompendiumAttributes.openApiSpec]

View File

@ -14,7 +14,8 @@ import kotlin.reflect.KType
object CollectionHandler { object CollectionHandler {
fun handle(type: KType, cache: MutableMap<String, JsonSchema>): JsonSchema { fun handle(type: KType, cache: MutableMap<String, JsonSchema>): 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!")
val typeSchema = SchemaGenerator.fromTypeToSchema(collectionType, cache).let { val typeSchema = SchemaGenerator.fromTypeToSchema(collectionType, cache).let {
if (it is TypeDefinition && it.type == "object") { if (it is TypeDefinition && it.type == "object") {
cache[collectionType.getSimpleSlug()] = it cache[collectionType.getSimpleSlug()] = it

View File

@ -15,10 +15,10 @@ import kotlin.reflect.KType
object MapHandler { object MapHandler {
fun handle(type: KType, cache: MutableMap<String, JsonSchema>): JsonSchema { fun handle(type: KType, cache: MutableMap<String, JsonSchema>): JsonSchema {
require(type.arguments.first().type!!.classifier as KClass<*> == String::class) { require(type.arguments.first().type?.classifier as KClass<*> == String::class) {
"JSON requires that map keys MUST be Strings. You provided ${type.arguments.first().type}" "JSON requires that map keys MUST be Strings. You provided ${type.arguments.first().type}"
} }
val valueType = type.arguments[1].type!! val valueType = type.arguments[1].type ?: error("this indicates a bug in Kompendium, please open a GitHub issue")
val valueSchema = SchemaGenerator.fromTypeToSchema(valueType, cache).let { val valueSchema = SchemaGenerator.fromTypeToSchema(valueType, cache).let {
if (it is TypeDefinition && it.type == "object") { if (it is TypeDefinition && it.type == "object") {
cache[valueType.getSimpleSlug()] = it cache[valueType.getSimpleSlug()] = it

View File

@ -92,7 +92,8 @@ object SimpleObjectHandler {
typeMap: Map<KTypeParameter, KTypeProjection>, typeMap: Map<KTypeParameter, KTypeProjection>,
cache: MutableMap<String, JsonSchema> cache: MutableMap<String, JsonSchema>
): JsonSchema { ): JsonSchema {
val type = typeMap[prop.returnType.classifier]?.type!! val type = typeMap[prop.returnType.classifier]?.type
?: error("This indicates a bug in Kompendium, please open a GitHub issue")
return SchemaGenerator.fromTypeToSchema(type, cache).let { return SchemaGenerator.fromTypeToSchema(type, cache).let {
if (it.isOrContainsObjectDef()) { if (it.isOrContainsObjectDef()) {
cache[type.getSimpleSlug()] = it cache[type.getSimpleSlug()] = it