From a4fbe836010cc74a19daeebf70bb923a7148f4bd Mon Sep 17 00:00:00 2001 From: tangcent Date: Sun, 15 Oct 2023 13:53:39 +0800 Subject: [PATCH] chore: polish YapiFormatter --- .../idea/plugin/api/export/yapi/YapiFormatter.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/yapi/YapiFormatter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/yapi/YapiFormatter.kt index 0c4dee08..48d8557b 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/yapi/YapiFormatter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/yapi/YapiFormatter.kt @@ -63,6 +63,10 @@ open class YapiFormatter { @Inject protected lateinit var urlSelector: UrlSelector + protected val json5Formatter: Json5Formatter by lazy { + actionContext.instance(Json5Formatter::class) + } + fun doc2Items(doc: Doc): List> { if (doc is Request) { return request2Items(doc) @@ -161,18 +165,15 @@ open class YapiFormatter { private fun parseQueryValueAsJson5(value: Any?): String? { when (value) { is Array<*> -> { - return actionContext.instance(Json5Formatter::class) - .format(value) + return json5Formatter.format(value) } is Collection<*> -> { - return actionContext.instance(Json5Formatter::class) - .format(value) + return json5Formatter.format(value) } is Map<*, *> -> { - return actionContext.instance(Json5Formatter::class) - .format(value) + return json5Formatter.format(value) } else -> { @@ -647,7 +648,7 @@ open class YapiFormatter { //region parse-json5 private fun parseByJson5(typedObject: Any?, rootDesc: String?): String { addMockAsProperty("", typedObject) - val json5Formatter = actionContext.instance(Json5Formatter::class) + val json5Formatter = json5Formatter return json5Formatter.format(typedObject, rootDesc) }