Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
097413067b | |||
eb7360b8d2 | |||
3ec467c1d8 | |||
152476c26e | |||
c4df4c7b2c | |||
87fa0b5602 | |||
53c76d6037 | |||
44324ca3a4 |
@ -12,6 +12,12 @@
|
|||||||
|
|
||||||
## Released
|
## Released
|
||||||
|
|
||||||
|
## [3.14.1] - April 28th, 2023
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Generating enrichments for generic classes no longer throws the `Slugs should not be generated for field enrichments` error.
|
||||||
|
|
||||||
## [3.14.0] - April 6th, 2023
|
## [3.14.0] - April 6th, 2023
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -11,6 +11,7 @@ import io.bkbn.kompendium.core.util.defaultAuthConfig
|
|||||||
import io.bkbn.kompendium.core.util.defaultField
|
import io.bkbn.kompendium.core.util.defaultField
|
||||||
import io.bkbn.kompendium.core.util.defaultParameter
|
import io.bkbn.kompendium.core.util.defaultParameter
|
||||||
import io.bkbn.kompendium.core.util.doubleConstraints
|
import io.bkbn.kompendium.core.util.doubleConstraints
|
||||||
|
import io.bkbn.kompendium.core.util.enrichedGenericResponse
|
||||||
import io.bkbn.kompendium.core.util.enrichedComplexGenericType
|
import io.bkbn.kompendium.core.util.enrichedComplexGenericType
|
||||||
import io.bkbn.kompendium.core.util.enrichedNestedCollection
|
import io.bkbn.kompendium.core.util.enrichedNestedCollection
|
||||||
import io.bkbn.kompendium.core.util.enrichedSimpleRequest
|
import io.bkbn.kompendium.core.util.enrichedSimpleRequest
|
||||||
@ -452,6 +453,9 @@ class KompendiumTest : DescribeSpec({
|
|||||||
it("Can enrich a complex generic type") {
|
it("Can enrich a complex generic type") {
|
||||||
openApiTestAllSerializers("T0057__enriched_complex_generic_type.json") { enrichedComplexGenericType() }
|
openApiTestAllSerializers("T0057__enriched_complex_generic_type.json") { enrichedComplexGenericType() }
|
||||||
}
|
}
|
||||||
|
it("Can enrich a generic object") {
|
||||||
|
openApiTestAllSerializers("T0067__enriched_generic_object.json") { enrichedGenericResponse() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
describe("Constraints") {
|
describe("Constraints") {
|
||||||
it("Can apply constraints to an int field") {
|
it("Can apply constraints to an int field") {
|
||||||
|
@ -6,6 +6,7 @@ import io.bkbn.kompendium.core.fixtures.NestedComplexItem
|
|||||||
import io.bkbn.kompendium.core.fixtures.TestCreatedResponse
|
import io.bkbn.kompendium.core.fixtures.TestCreatedResponse
|
||||||
import io.bkbn.kompendium.core.fixtures.TestResponse
|
import io.bkbn.kompendium.core.fixtures.TestResponse
|
||||||
import io.bkbn.kompendium.core.fixtures.TestSimpleRequest
|
import io.bkbn.kompendium.core.fixtures.TestSimpleRequest
|
||||||
|
import io.bkbn.kompendium.core.fixtures.GenericObject
|
||||||
import io.bkbn.kompendium.core.metadata.GetInfo
|
import io.bkbn.kompendium.core.metadata.GetInfo
|
||||||
import io.bkbn.kompendium.core.metadata.PostInfo
|
import io.bkbn.kompendium.core.metadata.PostInfo
|
||||||
import io.bkbn.kompendium.core.plugin.NotarizedRoute
|
import io.bkbn.kompendium.core.plugin.NotarizedRoute
|
||||||
@ -135,3 +136,33 @@ fun Routing.enrichedComplexGenericType() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Routing.enrichedGenericResponse() {
|
||||||
|
route("/example") {
|
||||||
|
install(NotarizedRoute()) {
|
||||||
|
get = GetInfo.builder {
|
||||||
|
summary(TestModules.defaultPathSummary)
|
||||||
|
description(TestModules.defaultPathDescription)
|
||||||
|
response {
|
||||||
|
responseType(
|
||||||
|
enrichment = TypeEnrichment("generic") {
|
||||||
|
GenericObject<TestSimpleRequest>::data {
|
||||||
|
description = "A simple description"
|
||||||
|
typeEnrichment = TypeEnrichment("simple") {
|
||||||
|
TestSimpleRequest::a {
|
||||||
|
description = "A simple description"
|
||||||
|
}
|
||||||
|
TestSimpleRequest::b {
|
||||||
|
deprecated = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
description("A good response")
|
||||||
|
responseCode(HttpStatusCode.Created)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
91
core/src/test/resources/T0067__enriched_generic_object.json
Normal file
91
core/src/test/resources/T0067__enriched_generic_object.json
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
{
|
||||||
|
"openapi": "3.1.0",
|
||||||
|
"jsonSchemaDialect": "https://json-schema.org/draft/2020-12/schema",
|
||||||
|
"info": {
|
||||||
|
"title": "Test API",
|
||||||
|
"version": "1.33.7",
|
||||||
|
"description": "An amazing, fully-ish 😉 generated API spec",
|
||||||
|
"termsOfService": "https://example.com",
|
||||||
|
"contact": {
|
||||||
|
"name": "Homer Simpson",
|
||||||
|
"url": "https://gph.is/1NPUDiM",
|
||||||
|
"email": "chunkylover53@aol.com"
|
||||||
|
},
|
||||||
|
"license": {
|
||||||
|
"name": "MIT",
|
||||||
|
"url": "https://github.com/bkbnio/kompendium/blob/main/LICENSE"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"servers": [
|
||||||
|
{
|
||||||
|
"url": "https://myawesomeapi.com",
|
||||||
|
"description": "Production instance of my API"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://staging.myawesomeapi.com",
|
||||||
|
"description": "Where the fun stuff happens"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"/example": {
|
||||||
|
"get": {
|
||||||
|
"tags": [],
|
||||||
|
"summary": "Great Summary!",
|
||||||
|
"description": "testing more",
|
||||||
|
"parameters": [],
|
||||||
|
"responses": {
|
||||||
|
"201": {
|
||||||
|
"description": "A good response",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/GenericObject-TestSimpleRequest-generic"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"deprecated": false
|
||||||
|
},
|
||||||
|
"parameters": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"webhooks": {},
|
||||||
|
"components": {
|
||||||
|
"schemas": {
|
||||||
|
"GenericObject-TestSimpleRequest-generic": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/components/schemas/TestSimpleRequest-simple",
|
||||||
|
"description": "A simple description"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"data"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"TestSimpleRequest-simple": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"a": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "A simple description"
|
||||||
|
},
|
||||||
|
"b": {
|
||||||
|
"type": "number",
|
||||||
|
"format": "int32",
|
||||||
|
"deprecated": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"a",
|
||||||
|
"b"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"securitySchemes": {}
|
||||||
|
},
|
||||||
|
"security": [],
|
||||||
|
"tags": []
|
||||||
|
}
|
@ -180,6 +180,10 @@ data class SerialNameObject(
|
|||||||
val camelCaseName: String
|
val camelCaseName: String
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class GenericObject<T>(
|
||||||
|
val data: T
|
||||||
|
)
|
||||||
|
|
||||||
enum class Color {
|
enum class Color {
|
||||||
RED,
|
RED,
|
||||||
GREEN,
|
GREEN,
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
# Summary
|
# Summary
|
||||||
|
|
||||||
* [Introduction](index.md)
|
* [Introduction](index.md)
|
||||||
* [Helpers](helpers/index.md)
|
|
||||||
* [Protobuf java converter](helpers/protobuf_java_converter.md)
|
|
||||||
* [Concepts](concepts/index.md)
|
|
||||||
* [Enrichment](concepts/enrichment.md)
|
|
||||||
* [Plugins](plugins/index.md)
|
* [Plugins](plugins/index.md)
|
||||||
* [Notarized Application](plugins/notarized_application.md)
|
* [Notarized Application](plugins/notarized_application.md)
|
||||||
* [Notarized Route](plugins/notarized_route.md)
|
* [Notarized Route](plugins/notarized_route.md)
|
||||||
* [Notarized Locations](plugins/notarized_locations.md)
|
* [Notarized Locations](plugins/notarized_locations.md)
|
||||||
* [Notarized Resources](plugins/notarized_resources.md)
|
* [Notarized Resources](plugins/notarized_resources.md)
|
||||||
|
* [Concepts](concepts/index.md)
|
||||||
|
* [Enrichment](concepts/enrichment.md)
|
||||||
|
* [Helpers](helpers/index.md)
|
||||||
|
* [Protobuf java converter](helpers/protobuf_java_converter.md)
|
||||||
* [The Playground](playground.md)
|
* [The Playground](playground.md)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Kompendium
|
# Kompendium
|
||||||
project.version=3.14.0
|
project.version=3.14.1
|
||||||
# Kotlin
|
# Kotlin
|
||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
# Gradle
|
# Gradle
|
||||||
@ -9,6 +9,6 @@ org.gradle.jvmargs=-Xmx2000m
|
|||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
ktorVersion=2.2.4
|
ktorVersion=2.3.0
|
||||||
kotestVersion=5.5.5
|
kotestVersion=5.6.1
|
||||||
detektVersion=1.22.0
|
detektVersion=1.22.0
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@ -133,8 +133,8 @@ object SimpleObjectHandler {
|
|||||||
?: error("This indicates a bug in Kompendium, please open a GitHub issue")
|
?: error("This indicates a bug in Kompendium, please open a GitHub issue")
|
||||||
return SchemaGenerator.fromTypeToSchema(type, cache, schemaConfigurator, propEnrichment?.typeEnrichment).let {
|
return SchemaGenerator.fromTypeToSchema(type, cache, schemaConfigurator, propEnrichment?.typeEnrichment).let {
|
||||||
if (it.isOrContainsObjectOrEnumDef()) {
|
if (it.isOrContainsObjectOrEnumDef()) {
|
||||||
cache[type.getSlug(propEnrichment)] = it
|
cache[type.getSlug(propEnrichment?.typeEnrichment)] = it
|
||||||
ReferenceDefinition(type.getReferenceSlug(propEnrichment))
|
ReferenceDefinition(type.getReferenceSlug(propEnrichment?.typeEnrichment))
|
||||||
} else {
|
} else {
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
|
@ -7,11 +7,12 @@ import io.bkbn.kompendium.core.fixtures.ObjectWithEnum
|
|||||||
import io.bkbn.kompendium.core.fixtures.SerialNameObject
|
import io.bkbn.kompendium.core.fixtures.SerialNameObject
|
||||||
import io.bkbn.kompendium.core.fixtures.SimpleEnum
|
import io.bkbn.kompendium.core.fixtures.SimpleEnum
|
||||||
import io.bkbn.kompendium.core.fixtures.SlammaJamma
|
import io.bkbn.kompendium.core.fixtures.SlammaJamma
|
||||||
import io.bkbn.kompendium.core.fixtures.TestHelpers.getFileSnapshot
|
|
||||||
import io.bkbn.kompendium.core.fixtures.TestResponse
|
import io.bkbn.kompendium.core.fixtures.TestResponse
|
||||||
import io.bkbn.kompendium.core.fixtures.TestSimpleRequest
|
import io.bkbn.kompendium.core.fixtures.TestSimpleRequest
|
||||||
import io.bkbn.kompendium.core.fixtures.TransientObject
|
import io.bkbn.kompendium.core.fixtures.TransientObject
|
||||||
import io.bkbn.kompendium.core.fixtures.UnbackedObject
|
import io.bkbn.kompendium.core.fixtures.UnbackedObject
|
||||||
|
import io.bkbn.kompendium.core.fixtures.GenericObject
|
||||||
|
import io.bkbn.kompendium.core.fixtures.TestHelpers.getFileSnapshot
|
||||||
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
import io.bkbn.kompendium.enrichment.TypeEnrichment
|
||||||
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
import io.bkbn.kompendium.json.schema.definition.JsonSchema
|
||||||
import io.kotest.assertions.json.shouldEqualJson
|
import io.kotest.assertions.json.shouldEqualJson
|
||||||
@ -62,6 +63,9 @@ class SchemaGeneratorTest : DescribeSpec({
|
|||||||
it("Can generate the schema for object with SerialName annotation") {
|
it("Can generate the schema for object with SerialName annotation") {
|
||||||
jsonSchemaTest<SerialNameObject>("T0020__serial_name_object.json")
|
jsonSchemaTest<SerialNameObject>("T0020__serial_name_object.json")
|
||||||
}
|
}
|
||||||
|
it("Can generate the schema for object with generic property") {
|
||||||
|
jsonSchemaTest<GenericObject<TestSimpleRequest>>("T0024__generic_object.json")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
describe("Enums") {
|
describe("Enums") {
|
||||||
it("Can generate the schema for a simple enum") {
|
it("Can generate the schema for a simple enum") {
|
||||||
@ -135,6 +139,24 @@ class SchemaGeneratorTest : DescribeSpec({
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
it("Can properly assign a reference to a generic object") {
|
||||||
|
jsonSchemaTest<GenericObject<TestSimpleRequest>>(
|
||||||
|
snapshotName = "T0025__enrichment_generic_object.json",
|
||||||
|
enrichment = TypeEnrichment("generic") {
|
||||||
|
GenericObject<TestSimpleRequest>::data {
|
||||||
|
description = "This is a generic param"
|
||||||
|
typeEnrichment = TypeEnrichment("simple") {
|
||||||
|
TestSimpleRequest::a {
|
||||||
|
description = "This is a simple description"
|
||||||
|
}
|
||||||
|
TestSimpleRequest::b {
|
||||||
|
deprecated = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
companion object {
|
companion object {
|
||||||
|
11
json-schema/src/test/resources/T0024__generic_object.json
Normal file
11
json-schema/src/test/resources/T0024__generic_object.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"$ref": "#/components/schemas/TestSimpleRequest"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"data"
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"data": {
|
||||||
|
"description": "This is a generic param",
|
||||||
|
"$ref": "#/components/schemas/TestSimpleRequest-simple"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"data"
|
||||||
|
]
|
||||||
|
}
|
@ -22,8 +22,8 @@ dependencies {
|
|||||||
// IMPLEMENTATION
|
// IMPLEMENTATION
|
||||||
|
|
||||||
implementation(projects.kompendiumCore)
|
implementation(projects.kompendiumCore)
|
||||||
implementation("io.ktor:ktor-server-core:2.2.4")
|
implementation("io.ktor:ktor-server-core:2.3.0")
|
||||||
implementation("io.ktor:ktor-server-locations:2.2.4")
|
implementation("io.ktor:ktor-server-locations:2.3.0")
|
||||||
|
|
||||||
// TESTING
|
// TESTING
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ dependencies {
|
|||||||
|
|
||||||
|
|
||||||
implementation(projects.kompendiumJsonSchema)
|
implementation(projects.kompendiumJsonSchema)
|
||||||
implementation("com.google.protobuf:protobuf-java:3.22.2")
|
implementation("com.google.protobuf:protobuf-java:3.22.3")
|
||||||
implementation("org.jetbrains.kotlin:kotlin-reflect:1.8.20")
|
implementation("org.jetbrains.kotlin:kotlin-reflect:1.8.20")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
|
||||||
|
|
||||||
|
@ -22,8 +22,8 @@ dependencies {
|
|||||||
// IMPLEMENTATION
|
// IMPLEMENTATION
|
||||||
|
|
||||||
implementation(projects.kompendiumCore)
|
implementation(projects.kompendiumCore)
|
||||||
implementation("io.ktor:ktor-server-core:2.2.4")
|
implementation("io.ktor:ktor-server-core:2.3.0")
|
||||||
implementation("io.ktor:ktor-server-resources:2.2.4")
|
implementation("io.ktor:ktor-server-resources:2.3.0")
|
||||||
|
|
||||||
// TESTING
|
// TESTING
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user