Skip to content

Commit 049f132

Browse files
authored
Add KDoc to public API across all modules (KOJAK-36) (#10)
## Summary - Add KDoc documentation to all 15 undocumented public Kotlin files across 5 modules (core, http, kafka, postgres, mysql) - Follow existing project KDoc style: concise, `[ClassName]` references, no `@param`/`@return` - Documentation-only changes — zero code modifications, 80 lines added ## Modules covered | Module | Files | What was documented | |--------|-------|---------------------| | okapi-core | 6 | Data classes, enums, sealed interface (`OutboxMessage`, `OutboxId`, `OutboxStatus`, `OutboxEntry`, `DeliveryResult`, `RetryPolicy`) | | okapi-http | 4 | Transport impl, delivery info, DSL builder with usage example, enum | | okapi-kafka | 3 | Transport impl, delivery info, DSL builder with usage example | | okapi-postgres | 1 | Store implementation class | | okapi-mysql | 1 | Store implementation class | ## Test plan - [x] `./gradlew ktlintCheck` — passed - [x] `./gradlew compileKotlin` — passed (verifies KDoc `[references]` don't break compilation) - [x] No code changes — only KDoc comment additions
1 parent d74607a commit 049f132

15 files changed

Lines changed: 80 additions & 0 deletions

File tree

okapi-core/src/main/kotlin/com/softwaremill/okapi/core/DeliveryResult.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package com.softwaremill.okapi.core
22

3+
/**
4+
* Outcome of a single delivery attempt by a [MessageDeliverer].
5+
*
6+
* [OutboxEntryProcessor] uses this to decide whether to retry, mark as failed,
7+
* or mark as delivered.
8+
*/
39
sealed interface DeliveryResult {
410
data object Success : DeliveryResult
511

okapi-core/src/main/kotlin/com/softwaremill/okapi/core/OutboxEntry.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ package com.softwaremill.okapi.core
22

33
import java.time.Instant
44

5+
/**
6+
* Persistent representation of an outbox message with delivery state.
7+
*
8+
* Created via [createPending] and progressed through [retry], [toDelivered],
9+
* or [toFailed] — each returning a new immutable copy.
10+
*/
511
data class OutboxEntry(
612
val outboxId: OutboxId,
713
val messageType: String,
@@ -15,6 +21,7 @@ data class OutboxEntry(
1521
val lastError: String?,
1622
val deliveryMetadata: String,
1723
) {
24+
/** Returns a copy scheduled for another delivery attempt. */
1825
fun retry(now: Instant, lastError: String): OutboxEntry = copy(
1926
status = OutboxStatus.PENDING,
2027
updatedAt = now,
@@ -23,20 +30,23 @@ data class OutboxEntry(
2330
lastError = lastError,
2431
)
2532

33+
/** Returns a copy marked as permanently failed. */
2634
fun toFailed(now: Instant, lastError: String): OutboxEntry = copy(
2735
status = OutboxStatus.FAILED,
2836
updatedAt = now,
2937
lastAttempt = now,
3038
lastError = lastError,
3139
)
3240

41+
/** Returns a copy marked as successfully delivered. */
3342
fun toDelivered(now: Instant): OutboxEntry = copy(
3443
status = OutboxStatus.DELIVERED,
3544
updatedAt = now,
3645
lastAttempt = now,
3746
)
3847

3948
companion object {
49+
/** Creates a new PENDING entry from a [message] and [deliveryInfo]. */
4050
fun createPending(message: OutboxMessage, deliveryInfo: DeliveryInfo, now: Instant): OutboxEntry =
4151
createPending(message, deliveryType = deliveryInfo.type, deliveryMetadata = deliveryInfo.serialize(), now = now)
4252

okapi-core/src/main/kotlin/com/softwaremill/okapi/core/OutboxId.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package com.softwaremill.okapi.core
22

33
import java.util.UUID
44

5+
/** Unique identifier for an outbox entry. Wraps a [UUID] for type safety. */
56
@JvmInline
67
value class OutboxId(val raw: UUID) {
78
companion object {
9+
/** Generates a new random identifier. */
810
fun new(): OutboxId = OutboxId(UUID.randomUUID())
911
}
1012
}

okapi-core/src/main/kotlin/com/softwaremill/okapi/core/OutboxMessage.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.softwaremill.okapi.core
22

3+
/** Business message to be delivered via the transactional outbox. */
34
data class OutboxMessage(
45
val messageType: String,
56
val payload: String,

okapi-core/src/main/kotlin/com/softwaremill/okapi/core/OutboxStatus.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.softwaremill.okapi.core
22

3+
/** Lifecycle status of an [OutboxEntry]. */
34
enum class OutboxStatus {
45
PENDING,
56
DELIVERED,
67
FAILED,
78
;
89

910
companion object {
11+
/** Resolves a status by matching the given [value] against enum entry names. Throws if unknown. */
1012
fun from(value: String): OutboxStatus = requireNotNull(entries.find { it.name == value }) {
1113
"Unknown outbox status: $value"
1214
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.softwaremill.okapi.core
22

3+
/** Determines how many retries are allowed after the initial delivery attempt before an entry is marked as [OutboxStatus.FAILED]. */
34
data class RetryPolicy(val maxRetries: Int) {
45
init {
56
require(maxRetries >= 0) { "maxRetries must be >= 0, got: $maxRetries" }
67
}
78

9+
/** Returns `true` if [currentRetries] has not yet reached [maxRetries]. */
810
fun shouldRetry(currentRetries: Int): Boolean = currentRetries < maxRetries
911
}

okapi-http/src/main/kotlin/com/softwaremill/okapi/http/HttpDeliveryInfo.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
44
import com.fasterxml.jackson.module.kotlin.readValue
55
import com.softwaremill.okapi.core.DeliveryInfo
66

7+
/**
8+
* Delivery metadata for HTTP webhook transport.
9+
*
10+
* [serviceName] is resolved to a base URL via [ServiceUrlResolver] at delivery time.
11+
* [endpointPath] is appended to form the full URL.
12+
*/
713
data class HttpDeliveryInfo(
814
override val type: String = TYPE,
915
val serviceName: String,
@@ -22,6 +28,7 @@ data class HttpDeliveryInfo(
2228
const val TYPE = "http"
2329
private val mapper = jacksonObjectMapper()
2430

31+
/** Deserializes from JSON stored in [OutboxEntry.deliveryMetadata]. */
2532
fun deserialize(json: String): HttpDeliveryInfo = mapper.readValue(json)
2633
}
2734
}

okapi-http/src/main/kotlin/com/softwaremill/okapi/http/HttpDeliveryInfoBuilder.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,16 @@ class HttpDeliveryInfoBuilder {
2222
)
2323
}
2424

25+
/**
26+
* DSL for building [HttpDeliveryInfo].
27+
*
28+
* ```
29+
* val info = httpDeliveryInfo {
30+
* serviceName = "order-service"
31+
* endpointPath = "/api/events"
32+
* httpMethod = HttpMethod.POST
33+
* header("X-Correlation-Id", correlationId)
34+
* }
35+
* ```
36+
*/
2537
fun httpDeliveryInfo(block: HttpDeliveryInfoBuilder.() -> Unit): HttpDeliveryInfo = HttpDeliveryInfoBuilder().apply(block).build()

okapi-http/src/main/kotlin/com/softwaremill/okapi/http/HttpMessageDeliverer.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import java.net.http.HttpRequest
99
import java.net.http.HttpResponse
1010
import java.time.Duration
1111

12+
/**
13+
* [MessageDeliverer] that sends outbox entries as HTTP requests via JDK [HttpClient].
14+
*
15+
* Status code classification:
16+
* - 2xx → [DeliveryResult.Success]
17+
* - 5xx, 429, 408 → [DeliveryResult.RetriableFailure] (configurable via [retriableStatusCodes])
18+
* - other → [DeliveryResult.PermanentFailure]
19+
*
20+
* Connection errors are treated as retriable.
21+
*/
1222
class HttpMessageDeliverer(
1323
private val urlResolver: ServiceUrlResolver,
1424
private val httpClient: HttpClient = defaultHttpClient(),

okapi-http/src/main/kotlin/com/softwaremill/okapi/http/HttpMethod.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.softwaremill.okapi.http
22

3+
/** HTTP methods supported by [HttpMessageDeliverer]. */
34
enum class HttpMethod {
45
POST,
56
PUT,

0 commit comments

Comments
 (0)