From 7d7a1b5686bf7de8880ae1ee4f7fa5b2df46e8d2 Mon Sep 17 00:00:00 2001 From: tangcent Date: Sun, 26 Apr 2020 19:48:15 +0800 Subject: [PATCH 1/3] fix: bind `this.currRequest.path` as URL. --- .../com/itangcent/idea/plugin/dialog/ApiCallDialog.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/ApiCallDialog.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/ApiCallDialog.kt index b4da8c683..37503416e 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/ApiCallDialog.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/dialog/ApiCallDialog.kt @@ -13,10 +13,7 @@ import com.intellij.util.ui.ComboBoxCellEditor import com.itangcent.common.kit.KitUtils import com.itangcent.common.kit.notNullOrEmpty import com.itangcent.common.logger.traceError -import com.itangcent.common.model.FormParam -import com.itangcent.common.model.Request -import com.itangcent.common.model.getContentType -import com.itangcent.common.model.hasBody +import com.itangcent.common.model.* import com.itangcent.common.utils.appendlnIfNotEmpty import com.itangcent.common.utils.notNullOrBlank import com.itangcent.common.utils.notNullOrEmpty @@ -291,7 +288,8 @@ class ApiCallDialog : JDialog() { } autoComputer.bind(this.pathTextField!!) - .from(this, "this.currRequest.path") + .with(this, "this.currRequest.path") + .eval { it.url()?:"" } autoComputer.bindVisible(this.paramPanel!!) .with(this::currRequest) From d40d08fe26b0ff23744e12e374dbf28b038c8987 Mon Sep 17 00:00:00 2001 From: tangcent Date: Sun, 26 Apr 2020 20:57:16 +0800 Subject: [PATCH 2/3] feat: show attr of param with @RequestBody for `markdown` --- .../main/kotlin/com/itangcent/common/model/Request.kt | 5 +++++ .../src/main/kotlin/com/itangcent/common/model/URL.kt | 2 +- .../src/main/kotlin/com/itangcent/http/RequestUtils.kt | 2 +- .../idea/plugin/api/export/DefaultRequestHelper.kt | 1 + .../idea/plugin/api/export/markdown/MarkdownFormatter.kt | 2 +- .../idea/plugin/api/export/postman/PostmanFormatter.kt | 9 ++++----- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/common-api/src/main/kotlin/com/itangcent/common/model/Request.kt b/common-api/src/main/kotlin/com/itangcent/common/model/Request.kt index e8a72e99b..511bf3ede 100644 --- a/common-api/src/main/kotlin/com/itangcent/common/model/Request.kt +++ b/common-api/src/main/kotlin/com/itangcent/common/model/Request.kt @@ -35,6 +35,11 @@ open class Request : Doc() { var body: Any? = null + /** + * The description of [body] if it is present. + */ + var bodyAttr: String? = null + var response: MutableList? = null } diff --git a/common-api/src/main/kotlin/com/itangcent/common/model/URL.kt b/common-api/src/main/kotlin/com/itangcent/common/model/URL.kt index 26cf819ed..b023af957 100644 --- a/common-api/src/main/kotlin/com/itangcent/common/model/URL.kt +++ b/common-api/src/main/kotlin/com/itangcent/common/model/URL.kt @@ -145,7 +145,7 @@ private class SingleURL(private val url: String) : URL { } override fun concat(url: URL): URL { - return url.map { RequestUtils.contractPath(this.url, it) } + return url.map { RequestUtils.concatPath(this.url, it) } } override fun union(url: URL): URL { diff --git a/common-api/src/main/kotlin/com/itangcent/http/RequestUtils.kt b/common-api/src/main/kotlin/com/itangcent/http/RequestUtils.kt index b639406e2..4e50b50df 100644 --- a/common-api/src/main/kotlin/com/itangcent/http/RequestUtils.kt +++ b/common-api/src/main/kotlin/com/itangcent/http/RequestUtils.kt @@ -37,7 +37,7 @@ object RequestUtils { return body } - fun contractPath(pathPre: String?, pathAfter: String?): String? { + fun concatPath(pathPre: String?, pathAfter: String?): String? { if (pathPre.isNullOrBlank()) return pathAfter if (pathAfter.isNullOrBlank()) return pathPre return pathPre.removeSuffix("/") + "/" + pathAfter.removePrefix("/") diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultRequestHelper.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultRequestHelper.kt index 42e642500..bef62c7a2 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultRequestHelper.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/DefaultRequestHelper.kt @@ -59,6 +59,7 @@ open class DefaultRequestHelper : RequestHelper { override fun setJsonBody(request: Request, body: Any?, bodyAttr: String?) { request.body = body + request.bodyAttr = bodyAttr } override fun appendDesc(request: Request, desc: String?) { diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/markdown/MarkdownFormatter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/markdown/MarkdownFormatter.kt index d0c805a8e..aa3454671 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/markdown/MarkdownFormatter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/markdown/MarkdownFormatter.kt @@ -245,7 +245,7 @@ class MarkdownFormatter { handle("\n**RequestBody**\n\n") handle("| name | type | desc |\n") handle("| ------------ | ------------ | ------------ |\n") - parseBody(0, "", "", request.body, handle) + parseBody(0, "", request.bodyAttr ?: "", request.body, handle) if (settingBinder!!.read().outputDemo) { handle("\n**Request Demoļ¼š**\n\n") diff --git a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanFormatter.kt b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanFormatter.kt index 5932910b8..94491262c 100644 --- a/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanFormatter.kt +++ b/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/export/postman/PostmanFormatter.kt @@ -15,7 +15,6 @@ import com.itangcent.idea.psi.ResourceHelper import com.itangcent.idea.psi.resource import com.itangcent.idea.psi.resourceClass import com.itangcent.idea.utils.ModuleHelper -import com.itangcent.intellij.config.ConfigReader import com.itangcent.intellij.config.rule.RuleComputer import com.itangcent.intellij.context.ActionContext import com.itangcent.intellij.util.ActionUtils @@ -54,7 +53,7 @@ class PostmanFormatter { if (pathInRequest.single()) { val path = pathInRequest.url() ?: "" url["path"] = path.trim().trim('/').split("/") - url["raw"] = RequestUtils.contractPath(url.getAs("host"), path) + url["raw"] = RequestUtils.concatPath(url.getAs("host"), path) return listOf(item) } @@ -68,7 +67,7 @@ class PostmanFormatter { val copyItem = copyItem(item) val copyUrl: HashMap = copyItem.getAs("request", "url")!! copyUrl["path"] = it.trim().trim('/').split("/") - copyUrl["raw"] = RequestUtils.contractPath(host, it) + copyUrl["raw"] = RequestUtils.concatPath(host, it) return@map copyItem } } else { @@ -89,7 +88,7 @@ class PostmanFormatter { } url["path"] = (path ?: "").trim().trim('/').split("/") - url["raw"] = RequestUtils.contractPath(url.getAs("host"), path) + url["raw"] = RequestUtils.concatPath(url.getAs("host"), path) return listOf(item) } } @@ -117,7 +116,7 @@ class PostmanFormatter { val path = pathInRequest.url() ?: "" url["path"] = path.trim().trim('/').split("/") - url["raw"] = RequestUtils.contractPath(url.getAs("host"), path) + url["raw"] = RequestUtils.concatPath(url.getAs("host"), path) return item } From c1a49fa023569ab8b975e0b8379b25dbcdbe45c0 Mon Sep 17 00:00:00 2001 From: tangcent Date: Sun, 26 Apr 2020 23:38:22 +0800 Subject: [PATCH 3/3] feat: show attr of param with @RequestBody for `yapi` --- .../com/itangcent/idea/plugin/api/export/yapi/YapiFormatter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8a5d3ab0b..ab4b48e6b 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 @@ -331,7 +331,7 @@ open class YapiFormatter { item["req_body_form"] = EMPTY_ARR //todo:need desc of body - item["req_body_other"] = parseBySchema(request.body, "") + item["req_body_other"] = parseBySchema(request.body, request.bodyAttr) } if (!request.response.isNullOrEmpty()) {