Skip to content

Commit 35fa744

Browse files
committed
feat: Introduces a new ApiDashboardPanel for API testing
1 parent 627905a commit 35fa744

File tree

202 files changed

+5040
-6749
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

202 files changed

+5040
-6749
lines changed

assets/reset.svg

Lines changed: 7 additions & 0 deletions
Loading

common-api/src/main/kotlin/com/itangcent/common/model/FormParam.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package com.itangcent.common.model
33
import com.itangcent.common.utils.SimpleExtensible
44
import java.io.Serializable
55

6-
class FormParam : SimpleExtensible(), Serializable {
6+
class FormParam : SimpleExtensible(), NamedValue<String>, Serializable {
77

8-
var name: String? = null
8+
override var name: String? = null
99

10-
var value: String? = null
10+
override var value: String? = null
1111

1212
var desc: String? = null
1313

common-api/src/main/kotlin/com/itangcent/common/model/Header.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import java.io.Serializable
66
/**
77
* Represents an HTTP header field.
88
*/
9-
class Header : SimpleExtensible(), Serializable {
10-
var name: String? = null
9+
class Header : SimpleExtensible(), NamedValue<String>, Serializable {
10+
override var name: String? = null
1111

12-
var value: String? = null
12+
override var value: String? = null
1313

1414
var desc: String? = null
1515

@@ -42,5 +42,13 @@ class Header : SimpleExtensible(), Serializable {
4242
override fun toString(): String {
4343
return "Header(name=$name, value=$value, desc=$desc, required=$required)"
4444
}
45+
}
4546

46-
}
47+
fun Header(name: String, value: String): Header {
48+
return Header().apply {
49+
this.name = name
50+
this.value = value
51+
}
52+
}
53+
54+
fun List<Header>.contentType(): String? = this.findIgnoreCase("Content-Type")?.value
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.itangcent.common.model
2+
3+
/**
4+
* Interface for objects that have a name and value.
5+
*/
6+
interface NamedValue<T> {
7+
/**
8+
* The name of this value.
9+
*/
10+
var name: String?
11+
12+
/**
13+
* The value.
14+
*/
15+
var value: T?
16+
}
17+
18+
19+
fun <V, T : NamedValue<V>> List<T>.find(name: String): T? {
20+
return this.firstOrNull { it.name == name }
21+
}
22+
23+
fun <V, T : NamedValue<V>> List<T>.findIgnoreCase(name: String): T? {
24+
return this.firstOrNull { it.name?.equals(name, ignoreCase = true) == true }
25+
}

common-api/src/main/kotlin/com/itangcent/common/model/Param.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package com.itangcent.common.model
33
import com.itangcent.common.utils.SimpleExtensible
44
import java.io.Serializable
55

6-
class Param : SimpleExtensible(), Serializable {
7-
var name: String? = null
6+
class Param : SimpleExtensible(), NamedValue<Any>, Serializable {
7+
override var name: String? = null
88

9-
var value: Any? = null
9+
override var value: Any? = null
1010

1111
var desc: String? = null
1212

@@ -37,5 +37,4 @@ class Param : SimpleExtensible(), Serializable {
3737
override fun toString(): String {
3838
return "Param(name=$name, value=$value, desc=$desc, required=$required)"
3939
}
40-
4140
}

common-api/src/main/kotlin/com/itangcent/common/model/PathParam.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ package com.itangcent.common.model
33
import com.itangcent.common.utils.SimpleExtensible
44
import java.io.Serializable
55

6-
class PathParam : SimpleExtensible(), Serializable {
7-
var name: String? = null
6+
class PathParam : SimpleExtensible(), NamedValue<String>, Serializable {
7+
override var name: String? = null
88

9-
var value: String? = null
9+
override var value: String? = null
1010

1111
var desc: String? = null
1212

@@ -33,6 +33,4 @@ class PathParam : SimpleExtensible(), Serializable {
3333
override fun toString(): String {
3434
return "PathParam(name=$name, value=$value, desc=$desc)"
3535
}
36-
37-
3836
}

common-api/src/main/kotlin/com/itangcent/common/model/Request.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.itangcent.common.model
22

33
import com.itangcent.common.constant.HttpMethod
4-
import com.itangcent.common.utils.firstOrNull
4+
import org.apache.http.entity.ContentType
55

66
/**
77
* Request represent A Http API.
@@ -81,16 +81,20 @@ open class Request : Doc() {
8181
}
8282
}
8383

84-
fun Request.getContentType(): String? {
84+
fun Request.rawContentType(): String? {
8585
return this.header("content-type")
8686
}
8787

88+
fun Request.contentType(): ContentType? {
89+
return this.rawContentType()?.let { ContentType.parse(it) }
90+
}
91+
8892
fun Request.hasForm(): Boolean {
8993
if (this.method == HttpMethod.GET || this.method != HttpMethod.NO_METHOD) {
9094
return false
9195
}
9296

93-
val contentType = this.getContentType() ?: return false
97+
val contentType = this.rawContentType() ?: return false
9498
return !contentType.contains("application/json")
9599
}
96100

common-api/src/main/kotlin/com/itangcent/http/HttpRequest.kt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ abstract class AbstractHttpResponse : HttpResponse {
10461046
* {@code null} if the content type is unknown
10471047
*/
10481048
override fun contentType(): String? {
1049-
return this.firstHeader("content-type")
1049+
return headers()?.contentType()
10501050
}
10511051

10521052
/**
@@ -1087,10 +1087,7 @@ abstract class AbstractHttpResponse : HttpResponse {
10871087
* @return value of the first header or {@code null}
10881088
*/
10891089
override fun firstHeader(headerName: String): String? {
1090-
return headers()
1091-
?.filter { it.name().equalIgnoreCase(headerName) }
1092-
?.map { it.value() }
1093-
?.firstOrNull { it != null }
1090+
return headers()?.firstHeader(headerName)
10941091
}
10951092

10961093
/**
@@ -1211,6 +1208,9 @@ class BasicHttpHeader : HttpHeader {
12111208
}
12121209
}
12131210

1211+
fun HttpHeader(name: String, value: String): HttpHeader {
1212+
return BasicHttpHeader(name, value)
1213+
}
12141214
@ScriptTypeName("param")
12151215
interface HttpParam {
12161216

@@ -1270,4 +1270,12 @@ class BasicHttpParam : HttpParam {
12701270
fun setType(type: String?) {
12711271
this.type = type
12721272
}
1273+
}
1274+
1275+
fun List<HttpHeader>.firstHeader(name: String): String? {
1276+
return this.firstOrNull { it.name().equalIgnoreCase(name) }?.value()
1277+
}
1278+
1279+
fun List<HttpHeader>.contentType(): String? {
1280+
return this.firstHeader("content-type")
12731281
}

common-api/src/main/kotlin/com/itangcent/http/RequestUtils.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.itangcent.http
33
import com.itangcent.common.constant.Attrs
44
import com.itangcent.common.utils.*
55
import java.net.URL
6-
import kotlin.streams.toList
76

87
object RequestUtils {
98

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.itangcent.utils
2+
3+
/**
4+
* Event keys for inner action completion
5+
*/
6+
object ActionKeys {
7+
/**
8+
* Event key for when an inner action is completed.
9+
* Listeners can use this to perform cleanup operations (e.g. clear caches)
10+
* but should remain active for future actions.
11+
*/
12+
const val ACTION_COMPLETED = "com.itangcent.action.completed"
13+
}

0 commit comments

Comments
 (0)