feat: schema configurator to enable field name overrides and transient field omission (#302)
This commit is contained in:
@ -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!!!
|
||||
|
||||
|
11
json-schema/src/test/resources/T0018__transient_object.json
Normal file
11
json-schema/src/test/resources/T0018__transient_object.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"nonTransient": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"nonTransient"
|
||||
]
|
||||
}
|
11
json-schema/src/test/resources/T0019__unbacked_object.json
Normal file
11
json-schema/src/test/resources/T0019__unbacked_object.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"backed": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"backed"
|
||||
]
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"snake_case_name": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"snake_case_name"
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user