@@ -9,6 +9,19 @@ module Analyzer::Kotlin
99 def analyze
1010 include_callee = any_to_bool(@options [" include_callee" ]?) || any_to_bool(@options [" ai_context" ]?)
1111 file_list = all_files()
12+ string_constants = Hash (String , String ).new
13+ file_list.each do |path |
14+ next unless File .exists?(path)
15+ next unless path.ends_with?(" .#{ KOTLIN_EXTENSION } " )
16+ next if KotlinEngine .test_path?(path)
17+
18+ Noir ::TreeSitterKotlinKtorRouteExtractor .extract_string_constants(read_file_content(path)).each do |name , value |
19+ next unless fully_qualified_constant?(name)
20+
21+ string_constants[name] ||= value
22+ end
23+ end
24+
1225 file_list.each do |path |
1326 next unless File .exists?(path)
1427 next unless path.ends_with?(" .#{ KOTLIN_EXTENSION } " )
@@ -17,7 +30,7 @@ module Analyzer::Kotlin
1730 content = read_file_content(path)
1831 next unless potential_ktor_route_file?(content)
1932
20- Noir ::TreeSitterKotlinKtorRouteExtractor .extract_routes(content, include_callees: include_callee).each do |route |
33+ Noir ::TreeSitterKotlinKtorRouteExtractor .extract_routes(content, string_constants, include_callees: include_callee).each do |route |
2134 @result << build_endpoint(route, path)
2235 end
2336 end
@@ -32,6 +45,10 @@ module Analyzer::Kotlin
3245 content.includes?(" Route." )
3346 end
3447
48+ private def fully_qualified_constant? (name : String ) : Bool
49+ name.count('.' ) >= 2
50+ end
51+
3552 private def build_endpoint (route : Noir ::TreeSitterKotlinKtorRouteExtractor ::Route , path : String ) : Endpoint
3653 details = Details .new(PathInfo .new(path, route.line + 1 ))
3754 params = [] of Param
@@ -48,6 +65,8 @@ module Analyzer::Kotlin
4865
4966 if rt = route.receive_type
5067 params << Param .new(" body" , rt, " json" )
68+ elsif route.has_body?
69+ params << Param .new(" body" , " " , " json" )
5170 end
5271
5372 route.query_params.each do |name |
@@ -59,6 +78,10 @@ module Analyzer::Kotlin
5978 params << Param .new(name, " " , " header" )
6079 end
6180
81+ route.form_params.each do |name |
82+ params << Param .new(name, " " , " form" )
83+ end
84+
6285 endpoint = Endpoint .new(route.path, route.verb, params, details)
6386
6487 # 1-hop callees out of the handler lambda body. The Route
0 commit comments