Skip to content

Commit 1129c14

Browse files
committed
feat(endpoints): add WebApiView toolchain function #308
- Introduce WebApiViewFunctionProvider to list web APIs in the project. - Rename ArchViewCommand.WebApi to WebApiView for consistency. - Update configuration to include the new toolchain function provider.
1 parent 38b3369 commit 1129c14

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

core/src/main/kotlin/cc/unitmesh/devti/bridge/Bridge.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ sealed class Assessment(override val name: String) : BridgeCommandProvider {
4141
sealed class Target(override val name: String) : BridgeCommandProvider {
4242
object Docker : Target("docker")
4343
object BuildTool : Target("buildTool")
44-
object Mermaid : Target("mermaid")
4544
}
4645

4746
/**
@@ -68,7 +67,7 @@ sealed class Security(override val name: String) : BridgeCommandProvider {
6867
* ```
6968
*/
7069
sealed class ArchViewCommand(override val name: String) : BridgeCommandProvider {
71-
object WebApi : ArchViewCommand("webapi")
70+
object WebApiView : ArchViewCommand("webApiView")
7271

7372
/**
7473
* Aka Module View
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
List all web apis of current project
2+
/webApiView
3+
If return no endpoints, we need to check Endpoint plugin installed.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package cc.unitmesh.endpoints.bridge
2+
3+
import cc.unitmesh.devti.bridge.ArchViewCommand
4+
import cc.unitmesh.devti.provider.toolchain.ToolchainFunctionProvider
5+
import com.intellij.microservices.endpoints.EndpointsProvider
6+
import com.intellij.microservices.endpoints.EndpointsUrlTargetProvider
7+
import com.intellij.microservices.endpoints.ModuleEndpointsFilter
8+
import com.intellij.openapi.application.runReadAction
9+
import com.intellij.openapi.project.Project
10+
import com.intellij.openapi.project.modules
11+
import com.intellij.spring.model.SpringBeanPointer
12+
import com.intellij.spring.mvc.mapping.UrlMappingElement
13+
import org.jetbrains.kotlin.idea.base.facet.isTestModule
14+
15+
class WebApiViewFunctionProvider : ToolchainFunctionProvider {
16+
override fun funcNames(): List<String> = listOf(ArchViewCommand.WebApiView.name)
17+
18+
override fun isApplicable(project: Project, funcName: String): Boolean = funcName == ArchViewCommand.WebApiView.name
19+
20+
override fun execute(
21+
project: Project,
22+
prop: String,
23+
args: List<Any>,
24+
allVariables: Map<String, Any?>
25+
): Any {
26+
val model = runReadAction { EndpointsProvider.getAvailableProviders(project).toList() }
27+
if (model.isEmpty()) return "Cannot find any endpoints"
28+
29+
val availableProviders = model
30+
.filter { it.getStatus(project) == EndpointsProvider.Status.HAS_ENDPOINTS }
31+
.filterIsInstance<EndpointsUrlTargetProvider<SpringBeanPointer<*>, UrlMappingElement>>()
32+
33+
// return availableProviders.joinToString("\n") {
34+
// it.getEndpointGroups(project, ModuleEndpointsFilter(project))
35+
// "This project has http endpoints from ${it.presentation.title}"
36+
// }
37+
val modules = project.modules
38+
val groups = modules.map { module ->
39+
val moduleEndpointsFilter = ModuleEndpointsFilter(module, false, module.isTestModule)
40+
availableProviders.map { provider ->
41+
provider.getEndpointGroups(project, moduleEndpointsFilter)
42+
}.flatten()
43+
}.flatten()
44+
45+
val map: List<UrlMappingElement> = groups.map { group ->
46+
availableProviders.map {
47+
it.getEndpoints(group)
48+
}.flatten()
49+
}.flatten()
50+
51+
return map.joinToString("\n")
52+
}
53+
}

exts/ext-endpoints/src/233/main/resources/cc.unitmesh.endpoints.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
<extensions defaultExtensionNs="cc.unitmesh">
1010
<!-- Since it's very slow to load all the endpoints, we disable it by default. -->
1111
<!-- <chatContextProvider implementation="cc.unitmesh.endpoints.provider.EndpointsContextProvider"/>-->
12+
<toolchainFunctionProvider implementation="cc.unitmesh.endpoints.bridge.WebApiViewFunctionProvider"/>
1213
</extensions>
1314
</idea-plugin>

0 commit comments

Comments
 (0)