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

io.github.fomin.oasgen.java.JavaDoc.kt Maven / Gradle / Ivy

There is a newer version: 0.2.2
Show newest version
package io.github.fomin.oasgen.java

import io.github.fomin.oasgen.JsonSchema
import org.commonmark.parser.Parser
import org.commonmark.renderer.html.HtmlRenderer

private val parser = Parser.builder().build()
private val renderer = HtmlRenderer.builder().build()

fun javaDoc(jsonSchema: JsonSchema): String {
    val renderedDescription = jsonSchema.description?.let { description ->
        val document = parser.parse(description)
        renderer.render(document).trim()
    }
    val titleAndDescription = listOfNotNull(jsonSchema.title?.trim(), renderedDescription)
    if (titleAndDescription.isNotEmpty()) {
        val javaDocContent = titleAndDescription
            .joinToString("\n\n")
            .lines()
            .joinToString("\n") { " * $it".trimEnd() }

        return """|/**
              |$javaDocContent
              | */""".trimMargin()
    } else {
        return ""
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy