From b73550536f42697c6feb5595b8dd4d5cc16c4ac1 Mon Sep 17 00:00:00 2001 From: wwan13 Date: Tue, 17 Sep 2024 01:57:24 +0900 Subject: [PATCH] fix : Error where markdown format is broken --- .../wwan13/api/document/ApiDocumentContext.kt | 21 ++++++++++++------- .../api/document/util/MarkdownConverter.kt | 5 ++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/api/src/main/kotlin/io/wwan13/api/document/ApiDocumentContext.kt b/api/src/main/kotlin/io/wwan13/api/document/ApiDocumentContext.kt index 80f3319..4dcaca5 100644 --- a/api/src/main/kotlin/io/wwan13/api/document/ApiDocumentContext.kt +++ b/api/src/main/kotlin/io/wwan13/api/document/ApiDocumentContext.kt @@ -17,9 +17,10 @@ import org.springframework.restdocs.request.PathParametersSnippet import org.springframework.restdocs.request.RequestDocumentation import org.springframework.restdocs.request.RequestParametersSnippet import org.springframework.restdocs.snippet.Snippet +import kotlin.String as String1 data class ApiDocumentContext( - val identifier: String, + val identifier: String1, val summary: DocumentSummary, val guide: DocumentGuide, val enums: List, @@ -47,13 +48,17 @@ data class ApiDocumentContext( return snippets.toTypedArray() } - val description: String - get() = MarkdownConverter.join( - summary.description, - MarkdownConverter.convertGuide(guide), - MarkdownConverter.convertEnums(enums), - MarkdownConverter.convertErrors(errors), - ) + val description: String1 + get() { + val elements = mutableListOf() + + if (summary.hasDescription()) elements.add(summary.description) + if (guide.hasValue()) elements.add(MarkdownConverter.convertGuide(guide)) + if (enums.isNotEmpty()) elements.add(MarkdownConverter.convertEnums(enums)) + if (errors.isNotEmpty()) elements.add(MarkdownConverter.convertErrors(errors)) + + return MarkdownConverter.join(elements) + } private val allResponseFields: List get() { diff --git a/api/src/main/kotlin/io/wwan13/api/document/util/MarkdownConverter.kt b/api/src/main/kotlin/io/wwan13/api/document/util/MarkdownConverter.kt index 2d96377..3591f13 100644 --- a/api/src/main/kotlin/io/wwan13/api/document/util/MarkdownConverter.kt +++ b/api/src/main/kotlin/io/wwan13/api/document/util/MarkdownConverter.kt @@ -8,6 +8,7 @@ object MarkdownConverter { fun convertGuide(guide: DocumentGuide): String { return """ + | |### Api Guide | |${guide.value.joinToString("\n") { "- $it" }} @@ -26,6 +27,7 @@ object MarkdownConverter { } return """ + | |### Enum Values | |
@@ -40,6 +42,7 @@ object MarkdownConverter { fun convertErrors(errors: List): String { return """ + | |### Error Codes | |
@@ -54,7 +57,7 @@ object MarkdownConverter { """.trimMargin() } - fun join(vararg values: String): String { + fun join(values: List): String { return values.joinToString("
") } }