Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update enrichment documentation to match class usage #672

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
update enrichment examples to match class usage
  • Loading branch information
fennifith committed Dec 13, 2024
commit 5561b272d7b5b6801b82868819fa8ad8e18e50da
56 changes: 39 additions & 17 deletions docs/concepts/enrichment.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
Kompendium allows users to enrich their data types with additional information. This can be done by defining a
`TypeEnrichment` object and passing it to the `enrichment` parameter of the relevant `requestType` or `responseType`.
Kompendium allows users to enrich their data types with additional information. This can be done by defining an
`ObjectEnrichment` object and passing it to the `enrichment` parameter of the relevant `requestType` or `responseType`.

```kotlin
data class SimpleData(val a: String, val b: Int? = null)

val myEnrichment = TypeEnrichment<SimpleData>(id = "simple-enrichment") {
val myEnrichment = ObjectEnrichment<SimpleData>(id = "simple-enrichment") {
SimpleData::a {
description = "This will update the field description"
StringEnrichment("a") {
description = "This will update the field description"
}
}
SimpleData::b {
// Will indicate in the UI that the field will be removed soon
deprecated = true
NumberEnrichment("b") {
// Will indicate in the UI that the field will be removed soon
deprecated = true
}
}
}

Expand Down Expand Up @@ -50,28 +54,34 @@ and skip analyzing the new enrichment.
### Nested Enrichments

Enrichments are portable and composable, meaning that we can take an enrichment for a child data class
and apply it inside a parent data class using the `typeEnrichment` property.
and apply it inside a parent data class.

```kotlin
data class ParentData(val a: String, val b: ChildData)
data class ChildData(val c: String, val d: Int? = null)

val childEnrichment = TypeEnrichment<ChildData>(id = "child-enrichment") {
val childEnrichment = ObjectEnrichment<ChildData>(id = "child-enrichment") {
description = "This will update the field description of field b on parent data"
ChildData::c {
description = "This will update the field description of field c on child data"
StringEnrichment("c") {
description = "This will update the field description of field c on child data"
}
}
ChildData::d {
description = "This will update the field description of field d on child data"
NumberEnrichment("d") {
description = "This will update the field description of field d on child data"
}
}
}

val parentEnrichment = TypeEnrichment<ParentData>(id = "parent-enrichment") {
val parentEnrichment = ObjectEnrichment<ParentData>(id = "parent-enrichment") {
ParentData::a {
description = "This will update the field description"
StringEnrichment("a") {
description = "This will update the field description"
}
}
ParentData::b {
description = "This will update the field description of field b on parent data"
typeEnrichment = childEnrichment // Will apply the child enrichment to the internals of field b
childEnrichment // Will apply the child enrichment to the internals of field b
}
}
```
Expand All @@ -83,24 +93,36 @@ All enrichments support the following properties:
- description -> Provides a reader friendly description of the field in the object
- deprecated -> Indicates that the field is deprecated and should not be used

### String
### Strings (`StringEnrichment`)

- minLength -> The minimum length of the string
- maxLength -> The maximum length of the string
- pattern -> A regex pattern that the string must match
- contentEncoding -> The encoding of the string
- contentMediaType -> The media type of the string

### Numbers
### Numbers (`NumberEnrichment`)

- minimum -> The minimum value of the number
- maximum -> The maximum value of the number
- exclusiveMinimum -> Indicates that the minimum value is exclusive
- exclusiveMaximum -> Indicates that the maximum value is exclusive
- multipleOf -> Indicates that the number must be a multiple of the provided value

### Arrays
### Arrays (`CollectionEnrichment`)

- minItems -> The minimum number of items in the array
- maxItems -> The maximum number of items in the array
- uniqueItems -> Indicates that the array must contain unique items
- itemEnrichment -> An enrichment object for the array items

### Maps (`MapEnrichment`)

- minProperties -> The minimum number of items in the map
- maxProperties -> The maximum number of items in the map
- keyEnrichment -> A `StringEnrichment` object for the map keys
- valueEnrichment -> An enrichment object for the map values

### Booleans (`BooleanEnrichment`)

(No additional properties)