fix: improved error output when an unknown schema is encountered (#327)
This commit is contained in:
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@ -16,7 +16,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
distribution: 'adopt'
|
distribution: 'adopt'
|
||||||
java-version: '17'
|
java-version: '17'
|
||||||
- name: Publlish to Maven Central
|
- name: Publish to Maven Central
|
||||||
uses: burrunan/gradle-cache-action@v1
|
uses: burrunan/gradle-cache-action@v1
|
||||||
with:
|
with:
|
||||||
gradle-version: wrapper
|
gradle-version: wrapper
|
||||||
|
@ -12,6 +12,12 @@
|
|||||||
|
|
||||||
## Released
|
## Released
|
||||||
|
|
||||||
|
## [3.3.1] - September 26th, 2022
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Better exception thrown when unidentified type is encountered
|
||||||
|
|
||||||
## [3.3.0] - September 15th, 2022
|
## [3.3.0] - September 15th, 2022
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -53,12 +53,16 @@ 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
|
||||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||||
|
import io.bkbn.kompendium.json.schema.exception.UnknownSchemaException
|
||||||
import io.bkbn.kompendium.oas.component.Components
|
import io.bkbn.kompendium.oas.component.Components
|
||||||
import io.bkbn.kompendium.oas.security.ApiKeyAuth
|
import io.bkbn.kompendium.oas.security.ApiKeyAuth
|
||||||
import io.bkbn.kompendium.oas.security.BasicAuth
|
import io.bkbn.kompendium.oas.security.BasicAuth
|
||||||
import io.bkbn.kompendium.oas.security.BearerAuth
|
import io.bkbn.kompendium.oas.security.BearerAuth
|
||||||
import io.bkbn.kompendium.oas.security.OAuth
|
import io.bkbn.kompendium.oas.security.OAuth
|
||||||
|
import io.kotest.assertions.throwables.shouldThrow
|
||||||
import io.kotest.core.spec.style.DescribeSpec
|
import io.kotest.core.spec.style.DescribeSpec
|
||||||
|
import io.kotest.matchers.should
|
||||||
|
import io.kotest.matchers.string.startWith
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import io.ktor.client.engine.cio.CIO
|
import io.ktor.client.engine.cio.CIO
|
||||||
import io.ktor.http.HttpMethod
|
import io.ktor.http.HttpMethod
|
||||||
@ -240,6 +244,12 @@ class KompendiumTest : DescribeSpec({
|
|||||||
openApiTestAllSerializers("T0044__nested_type_name.json") { nestedTypeName() }
|
openApiTestAllSerializers("T0044__nested_type_name.json") { nestedTypeName() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
describe("Error Handling") {
|
||||||
|
it("Throws a clear exception when an unidentified type is encountered") {
|
||||||
|
val exception = shouldThrow<UnknownSchemaException> { openApiTestAllSerializers("") { dateTimeString() } }
|
||||||
|
exception.message should startWith("An unknown type was encountered: class java.time.Instant")
|
||||||
|
}
|
||||||
|
}
|
||||||
describe("Constraints") {
|
describe("Constraints") {
|
||||||
// TODO Assess strategies here
|
// TODO Assess strategies here
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Kompendium
|
# Kompendium
|
||||||
project.version=3.3.0
|
project.version=3.3.1
|
||||||
# Kotlin
|
# Kotlin
|
||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
# Gradle
|
# Gradle
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
package io.bkbn.kompendium.json.schema.exception
|
||||||
|
|
||||||
|
class UnknownSchemaException(message: String) : Exception(message)
|
@ -7,6 +7,7 @@ import io.bkbn.kompendium.json.schema.definition.NullableDefinition
|
|||||||
import io.bkbn.kompendium.json.schema.definition.OneOfDefinition
|
import io.bkbn.kompendium.json.schema.definition.OneOfDefinition
|
||||||
import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition
|
import io.bkbn.kompendium.json.schema.definition.ReferenceDefinition
|
||||||
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
import io.bkbn.kompendium.json.schema.definition.TypeDefinition
|
||||||
|
import io.bkbn.kompendium.json.schema.exception.UnknownSchemaException
|
||||||
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
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
@ -53,7 +54,20 @@ object SimpleObjectHandler {
|
|||||||
.asSequence()
|
.asSequence()
|
||||||
.filterNot { it.javaField == null }
|
.filterNot { it.javaField == null }
|
||||||
.filterNot { prop -> prop.returnType.isMarkedNullable }
|
.filterNot { prop -> prop.returnType.isMarkedNullable }
|
||||||
.filterNot { prop -> clazz.primaryConstructor!!.parameters.find { it.name == prop.name }!!.isOptional }
|
.filterNot { prop ->
|
||||||
|
clazz.primaryConstructor
|
||||||
|
?.parameters
|
||||||
|
?.find { it.name == prop.name }
|
||||||
|
?.isOptional
|
||||||
|
?: throw UnknownSchemaException(
|
||||||
|
"""
|
||||||
|
|An unknown type was encountered: $clazz. This typically indicates that a complex scalar such as dates,
|
||||||
|
|timestamps, or custom number representations such as BigInteger were not added as custom types when
|
||||||
|
|configuring the NotarizedApplication plugin. If you are still seeing this error despite adding all
|
||||||
|
|required custom types, this indicates a bug in Kompendium, please open an issue on GitHub.
|
||||||
|
""".trimMargin()
|
||||||
|
)
|
||||||
|
}
|
||||||
.map { schemaConfigurator.serializableName(it) }
|
.map { schemaConfigurator.serializableName(it) }
|
||||||
.toSet()
|
.toSet()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user