Skip to content

Commit

Permalink
Merge pull request #175 from tangcent/dev/v2.0.0
Browse files Browse the repository at this point in the history
feat: show attr of param with @requestbody for `yapi`
  • Loading branch information
tangcent authored Apr 26, 2020
2 parents 1202c09 + c1a49fa commit a0bb5a0
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Response>? = null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand All @@ -68,7 +67,7 @@ class PostmanFormatter {
val copyItem = copyItem(item)
val copyUrl: HashMap<String, Any?> = 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 {
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -291,7 +288,8 @@ class ApiCallDialog : JDialog() {
}

autoComputer.bind(this.pathTextField!!)
.from(this, "this.currRequest.path")
.with<URL>(this, "this.currRequest.path")
.eval { it.url()?:"" }

autoComputer.bindVisible(this.paramPanel!!)
.with(this::currRequest)
Expand Down

0 comments on commit a0bb5a0

Please sign in to comment.