Skip to content

Commit a525259

Browse files
authored
feat: Add support for processing inner classes in API export (#1258)
1 parent af26ff0 commit a525259

File tree

21 files changed

+2298
-796
lines changed

21 files changed

+2298
-796
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ plugin_version=2.8.2.212.0
33
kotlin.code.style=official
44
kotlin_version=2.1.0
55
junit_version=5.9.2
6-
itangcent_intellij_version=1.7.9
6+
itangcent_intellij_version=1.8.0

idea-plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ version = properties["plugin_version"]!!
88
val intellijVersions = arrayOf(
99
mapOf("jdk" to 21, "version" to "2025.1.2", "since" to "251"),
1010
mapOf("jdk" to 17, "version" to "2023.1.3", "since" to "231"),
11-
mapOf("jdk" to 15, "version" to "2022.2.3", "since" to "223"),
11+
mapOf("jdk" to 15, "version" to "2022.2.3", "since" to "222"),
1212
mapOf("jdk" to 11, "version" to "2021.2.1", "since" to "212")
1313
)
1414

idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/ClassApiExporterHelper.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ open class ClassApiExporterHelper {
239239
break
240240
}
241241
} else {
242+
for (innerClass in psiClass.innerClasses) {
243+
psiClassQueue.add(innerClass)
244+
}
242245
val classQualifiedName = actionContext.callInReadUI { psiClass.qualifiedName }
243246
LOG.info("Processing API for class: $classQualifiedName")
244247
actionContext.withBoundary {

idea-plugin/src/test/kotlin/com/itangcent/idea/plugin/api/ClassApiExporterHelperTest.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,14 @@ class ClassApiExporterHelperTest : PluginContextLightCodeInsightFixtureTestCase(
7878
}
7979
actionContext.waitComplete()
8080

81+
//not contains methods from innerclass
82+
assertEquals(4, methods.size)
83+
8184
assertTrue(methods.contains("create"))
8285
assertTrue(methods.contains("get"))
8386
assertFalse(methods.contains("toString"))
87+
//not contains methods from innerclass
88+
assertFalse(methods.contains("getProfileSettings"))
8489
}
8590

8691
fun testExport() {
@@ -89,6 +94,7 @@ class ClassApiExporterHelperTest : PluginContextLightCodeInsightFixtureTestCase(
8994

9095
assertNotNull(docs)
9196
assertTrue(docs.isNotEmpty())
97+
assertEquals(5, docs.size)
9298

9399
// Verify first API doc
94100
docs[0].let { doc ->

idea-plugin/src/test/kotlin/com/itangcent/idea/plugin/api/export/yapi/YapiApiExporterTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ internal abstract class YapiApiExporterTest : PluginContextLightCodeInsightFixtu
112112
builder.mock<YapiApiHelper> {
113113
this.on { it.findCart(eq("token111111"), eq("apis about user")) }
114114
.thenReturn(null, "111111")
115+
this.on { it.findCart(eq("token111111"), eq("Nested API for user profile operations")) }
116+
.thenReturn("333333")
115117
this.on { it.getProjectIdByToken(eq("token111111")) }
116118
.thenReturn("12345")
117119
this.on { it.addCart(any(), any(), any()) }
@@ -166,6 +168,8 @@ internal abstract class YapiApiExporterTest : PluginContextLightCodeInsightFixtu
166168
.thenReturn("111111")
167169
this.on { it.findCart(eq("token111111"), eq("test apis")) }
168170
.thenReturn("222222")
171+
this.on { it.findCart(eq("token111111"), eq("Nested API for user profile operations")) }
172+
.thenReturn("333333")
169173
this.on { it.getProjectIdByToken(eq("token111111")) }
170174
.thenReturn("12345")
171175
this.on { it.getCartWeb(any(""), any("")) }

idea-plugin/src/test/resources/api/UserCtrl.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.itangcent.model.UserInfo;
88
import org.springframework.web.bind.annotation.GetMapping;
99
import org.springframework.web.bind.annotation.ModelAttribute;
10+
import org.springframework.web.bind.annotation.PathVariable;
1011
import org.springframework.web.bind.annotation.PostMapping;
1112
import org.springframework.web.bind.annotation.PutMapping;
1213
import org.springframework.web.bind.annotation.RequestMapping;
@@ -66,4 +67,29 @@ public Result<UserInfo> update(@ModelAttribute UserInfo userInfo) {
6667
return Result.success(userInfo);
6768
}
6869

69-
}
70+
/**
71+
* Nested API for user profile operations
72+
*
73+
* @module user-profiles
74+
*/
75+
@RestController
76+
@RequestMapping(value = "/profile")
77+
public static class ProfileApi extends BaseController {
78+
79+
/**
80+
* Get user profile settings
81+
*
82+
* @param userId The ID of the user whose profile settings to retrieve
83+
* @return User profile settings
84+
*/
85+
@GetMapping("/settings/{userId}")
86+
public Result<UserInfo> getProfileSettings(@PathVariable("userId") Long userId) {
87+
UserInfo userInfo = new UserInfo();
88+
userInfo.setId(userId);
89+
userInfo.setName("Profile User");
90+
userInfo.setAge(30);
91+
return Result.success(userInfo);
92+
}
93+
}
94+
95+
}

idea-plugin/src/test/resources/result/com.itangcent.idea.plugin.api.export.markdown.MarkdownApiExporterTest.CustomizedDirectorySpringMarkdownApiExporterTest.txt

Lines changed: 123 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -910,14 +910,131 @@ test apis
910910

911911

912912

913-
## 1.2 apis about user
913+
## 1.2 Nested API for user profile operations
914+
915+
Nested API for user profile operations
916+
917+
918+
---
919+
### 1.2.21 current ctrl name
920+
921+
> `BASIC`
922+
923+
**`Path params`:** /profile/ctrl/name
924+
925+
**`Method`:** GET
926+
927+
> `QUERY`
928+
929+
**Headers:**
930+
931+
| `name` | `value` | `desc` |
932+
| ------------ | ------------ | ----: |
933+
| token | | auth token |
934+
935+
936+
937+
> `Response`
938+
939+
**Headers:**
940+
941+
| `name` | `value` | `required` | `desc` |
942+
| ------------ | ------------ | ------------ | :----: |
943+
| content-type | application/json;charset=UTF-8 | N | |
944+
945+
**Body:**
946+
947+
| `name` | `type` | `desc` |
948+
| ------------ | :----: | ------------ |
949+
| | string | |
950+
951+
**`Response demo`:**
952+
953+
```json
954+
955+
```
956+
957+
958+
959+
960+
---
961+
### 1.2.22 Get user profile settings
962+
963+
> `BASIC`
964+
965+
**`Path params`:** /profile/settings/{userId}
966+
967+
**`Method`:** GET
968+
969+
> `QUERY`
970+
971+
**Headers:**
972+
973+
| `name` | `value` | `desc` |
974+
| ------------ | ------------ | ----: |
975+
| token | | auth token |
976+
977+
**Query:**
978+
979+
| `name` | `value` | `required` | `desc` |
980+
| ------------ | ------------ | ------------ | ----: |
981+
| userId | | N | The ID of the user whose profile settings to retrieve |
982+
983+
984+
985+
> `Response`
986+
987+
**Headers:**
988+
989+
| `name` | `value` | `required` | `desc` |
990+
| ------------ | ------------ | ------------ | :----: |
991+
| content-type | application/json;charset=UTF-8 | N | |
992+
993+
**Body:**
994+
995+
| `name` | `type` | `desc` |
996+
| ------------ | :----: | ------------ |
997+
| code | integer | response code |
998+
| msg | string | message |
999+
| data | object | response data |
1000+
| &ensp;&ensp;&#124;─id | integer | user id |
1001+
| &ensp;&ensp;&#124;─type | integer | user type<br>1 :administration<br>2 :a person, an animal or a plant<br>3 :Anonymous visitor |
1002+
| &ensp;&ensp;&#124;─name | string | user name |
1003+
| &ensp;&ensp;&#124;─age | integer | user age |
1004+
| &ensp;&ensp;&#124;─sex | integer | |
1005+
| &ensp;&ensp;&#124;─birthDay | string | user birthDay |
1006+
| &ensp;&ensp;&#124;─regtime | string | user regtime |
1007+
1008+
**`Response demo`:**
1009+
1010+
```json
1011+
{
1012+
"code": 0,
1013+
"msg": "",
1014+
"data": {
1015+
"id": 0,
1016+
"type": 0,
1017+
"name": "",
1018+
"age": 0,
1019+
"sex": 0,
1020+
"birthDay": "",
1021+
"regtime": ""
1022+
}
1023+
}
1024+
```
1025+
1026+
1027+
1028+
1029+
1030+
## 1.3 apis about user
9141031

9151032
apis about user
9161033
access user info
9171034

9181035

9191036
---
920-
### 1.2.21 current ctrl name
1037+
### 1.3.23 current ctrl name
9211038

9221039
> `BASIC`
9231040

@@ -959,7 +1076,7 @@ access user info
9591076

9601077

9611078
---
962-
### 1.2.22 say hello
1079+
### 1.3.24 say hello
9631080

9641081
> `BASIC`
9651082

@@ -997,7 +1114,7 @@ access user info
9971114

9981115

9991116
---
1000-
### 1.2.23 get user info
1117+
### 1.3.25 get user info
10011118

10021119
> `BASIC`
10031120

@@ -1066,7 +1183,7 @@ access user info
10661183

10671184

10681185
---
1069-
### 1.2.24 create an user
1186+
### 1.3.26 create an user
10701187

10711188
> `BASIC`
10721189

@@ -1156,7 +1273,7 @@ access user info
11561273

11571274

11581275
---
1159-
### 1.2.25 update user info
1276+
### 1.3.27 update user info
11601277

11611278
> `BASIC`
11621279

0 commit comments

Comments
 (0)