module Noir::TreeSitterKotlinKtorRouteExtractor

Overview

Tree-sitter-backed Ktor DSL route extractor.

Walks the canonical Ktor server idiom:

routing {
  get("/x") { ... }
  route("/api") {
    post("/items") { val item = call.receive < Item > () }
  }
  authenticate("auth-jwt") {
    get("/profile") { ... }
  }
}

Recognises:

Not covered yet:

Extended Modules

Defined in:

miniparsers/kotlin_ktor_route_extractor_ts.cr

Constant Summary

HTTP_VERB_NAMES = {"get" => "GET", "post" => "POST", "put" => "PUT", "delete" => "DELETE", "patch" => "PATCH", "head" => "HEAD", "options" => "OPTIONS", "webSocket" => "GET", "webSocketRaw" => "GET", "sse" => "GET"}
PASSTHROUGH_NAMES = Set {"routing", "authenticate", "rateLimit", "intercept", "host", "port"}

Pass-through DSL calls — descend into their lambda body without changing the path prefix. routing is the entry point; authenticate wraps a sub-tree behind an auth realm; the remaining names cover the common Ktor scoping helpers. install is handled separately (see walk) because only install(Routing) contributes routes — every other plugin config block must NOT be walked as routing.

Instance Method Summary

Instance Method Detail

def compose_resource_paths(raws : Array(RawResource)) : Hash(String, String) #

Resolve each raw resource to its full URL path. The parent is the first primary-constructor property whose type is itself a resource (root: Root/api); the child path joins onto it. Returns a map keyed by BOTH the dotted lexical name (Articles.New) and the bare simple name (TagsResource) so get<...> references resolve either way.


[View source]
def extract_resource_classes(source : String) : Array(RawResource) #

Collect every @Resource("path")-annotated class/object in a file (including nested ones, with their dotted lexical name). The analyzer gathers these across the whole project before composing full paths, since a resource's parent is often declared in another module (Ktor's KMP commonMain resource definitions).


[View source]
def extract_routes(source : String, string_constants = Hash(String, String).new, resource_paths = Hash(String, String).new, *, include_callees : Bool = false) : Array(Route) #

[View source]
def extract_string_constants(source : String) : Hash(String, String) #

[View source]