feat: schema configurator to enable field name overrides and transient field omission (#302)

This commit is contained in:
Stuart Campbell
2022-08-23 13:02:50 +01:00
committed by GitHub
parent bf31dd213c
commit 07bdeda364
28 changed files with 581 additions and 85 deletions

View File

@ -1,12 +1,7 @@
package io.bkbn.kompendium.json.schema
import io.bkbn.kompendium.core.fixtures.ComplexRequest
import io.bkbn.kompendium.core.fixtures.FlibbityGibbit
import io.bkbn.kompendium.core.fixtures.SimpleEnum
import io.bkbn.kompendium.core.fixtures.SlammaJamma
import io.bkbn.kompendium.core.fixtures.*
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.json.schema.definition.JsonSchema
import io.kotest.assertions.json.shouldEqualJson
import io.kotest.assertions.throwables.shouldThrow
@ -45,6 +40,15 @@ class SchemaGeneratorTest : DescribeSpec({
xit("Can generate the schema for a recursive type") {
// TODO jsonSchemaTest<SlammaJamma>("T0016__recursive_object.json")
}
it("Can generate the schema for object with transient property") {
jsonSchemaTest<TransientObject>("T0018__transient_object.json")
}
it("Can generate the schema for object with unbacked property") {
jsonSchemaTest<UnbakcedObject>("T0019__unbacked_object.json")
}
it("Can generate the schema for object with SerialName annotation") {
jsonSchemaTest<SerialNameObject>("T0020__serial_name_object.json")
}
}
describe("Enums") {
it("Can generate the schema for a simple enum") {
@ -91,7 +95,7 @@ class SchemaGeneratorTest : DescribeSpec({
private inline fun <reified T> jsonSchemaTest(snapshotName: String) {
// act
val schema = SchemaGenerator.fromTypeToSchema<T>()
val schema = SchemaGenerator.fromTypeToSchema<T>(schemaConfigurator = KotlinXSchemaConfigurator())
// todo add cache assertions!!!

View File

@ -0,0 +1,11 @@
{
"type": "object",
"properties": {
"nonTransient": {
"type": "string"
}
},
"required": [
"nonTransient"
]
}

View File

@ -0,0 +1,11 @@
{
"type": "object",
"properties": {
"backed": {
"type": "string"
}
},
"required": [
"backed"
]
}

View File

@ -0,0 +1,12 @@
{
"type": "object",
"properties": {
"snake_case_name": {
"type": "string"
}
},
"required": [
"snake_case_name"
]
}