All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.http4k.tracing.renderer.MarkdownTraceDepthTable.kt Maven / Gradle / Ivy

There is a newer version: 5.41.0.0
Show newest version
package org.http4k.tracing.renderer

import org.http4k.tracing.Trace
import org.http4k.tracing.TraceRender
import org.http4k.tracing.TraceRenderer
import org.http4k.tracing.TraceStep

object MarkdownTraceDepthTable : TraceRenderer {
    override fun render(scenarioName: String, steps: List): TraceRender {
        val body = steps.filterIsInstance()
            .map { it to it.maxDepth(1) }
            .sortedByDescending { it.second }
            .joinToString("\n") {
                "|\t${it.first.origin.name}\t|\t${it.first.target.name}\t|\t${it.first.request}\t|\t${it.second}\t|"
            }

        val header = """
## $scenarioName - Maximum Trace Depth

| Origin | Target | Request |  Max Depth  |
|:------:|:------:|:-------:|:-----------:|
"""
        return TraceRender("$scenarioName - Maximum Trace Depth", "MD", header + body)
    }

    private fun Trace.maxDepth(i: Int): Int = (listOf(i) + children.map { it.maxDepth(i + 1) }).max()
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy