class
Analyzer::Go::Huma
- Analyzer::Go::Huma
- Analyzer::Go::GoEngine
- Analyzer
- Reference
- Object
Overview
Huma (https://huma.rocks/) is an OpenAPI-first Go framework
where every operation is registered through
huma.Register(api, huma.Operation{Method: ..., Path: ...}, handler)
The Operation literal carries method/path verbatim, and the
handler's Input struct fields declare parameter shape via
tags (path:"id", query:"limit", header:"X-Auth", plus
a Body field for request bodies). That makes extraction
unusually precise compared to other Go routers.
Defined in:
analyzer/analyzers/go/huma.crConstant Summary
-
HTTP_METHOD_CONSTANTS =
{"http.MethodGet" => "GET", "http.MethodPost" => "POST", "http.MethodPut" => "PUT", "http.MethodPatch" => "PATCH", "http.MethodDelete" => "DELETE", "http.MethodHead" => "HEAD", "http.MethodOptions" => "OPTIONS", "http.MethodConnect" => "CONNECT", "http.MethodTrace" => "TRACE", "http.MethodQuery" => "QUERY"} -
IMPORT_MARKER =
"github.com/danielgtaylor/huma" -
IMPORT_MARKER_RE =
Regex.union(IMPORT_MARKER) -
One precompiled matcher instead of a
String#includes?scan per.gofile:includes?runs Rabin-Karp over the whole buffer and the marker is absent in the overwhelming majority of files in a polyglot repo, so every one of them pays the full scan. SeeAnalyzer#content_matches?. -
PARAM_TAG_KINDS =
{"path" => "path", "query" => "query", "header" => "header", "cookie" => "cookie"} -
Tags we lift from Input struct fields onto endpoint params.
-
PARAM_TAG_PATTERNS =
PARAM_TAG_KINDS.map do |go_tag, param_type| {param_type, /#{go_tag}:"([^"]+)"/} end -
Crystal recompiles an interpolated regex literal on every evaluation (a full PCRE2 JIT compile) — precompile the fixed tag matchers once at load time instead of per struct field.
-
SUGAR_VERBS =
{"huma.Get" => "GET", "huma.Post" => "POST", "huma.Put" => "PUT", "huma.Patch" => "PATCH", "huma.Delete" => "DELETE", "huma.Head" => "HEAD", "huma.Options" => "OPTIONS"} -
Huma v2's typed convenience helpers —
huma.Get(api, "/path", handler)and friends — register an operation without the verbosehuma.Register(api, huma.Operation{...}, handler)literal. The verb is the method name; the path is the SECOND argument (the first is the API/group). Mapped here so the call walker can decode them alongsidehuma.Register.
Class Method Summary
Instance Method Summary
- #analyze
-
#tech : String
Instance-side view of the same declaration.
Instance methods inherited from class Analyzer::Go::GoEngine
add_param_to_endpoint(param : Param, endpoint : Endpoint)
add_param_to_endpoint,
add_static_path_if_valid(static_path : Hash(String, String), public_dirs : Array(Hash(String, String)))
add_static_path_if_valid,
collect_import_path_function_bodies(package_function_bodies : Hash(String, Hash(String, Noir::GoCalleeExtractor::FunctionBody))) : Hash(String, Hash(String, Noir::GoCalleeExtractor::FunctionBody))
collect_import_path_function_bodies,
collect_import_path_method_bodies(package_method_bodies : Hash(String, Hash(String, Array(Noir::GoCalleeExtractor::FunctionBody)))) : Hash(String, Hash(String, Array(Noir::GoCalleeExtractor::FunctionBody)))
collect_import_path_method_bodies,
collect_package_controller_method_bodies(file_contents : Hash(String, String)) : Hash(String, Hash(String, Array(Noir::GoCalleeExtractor::FunctionBody)))
collect_package_controller_method_bodies,
collect_package_controller_methods(file_contents : Hash(String, String)) : Hash(String, Hash(String, Array(String)))
collect_package_controller_methods,
collect_package_function_bodies(file_contents : Hash(String, String)) : Hash(String, Hash(String, Noir::GoCalleeExtractor::FunctionBody))
collect_package_function_bodies,
collect_package_groups_ts(group_method : String = "Group", import_marker : String | Nil = nil) : Tuple(Hash(String, Hash(String, String)), Hash(String, String))
collect_package_groups_ts,
framework_package_dirs(file_contents : Hash(String, String), import_marker : String) : Set(String)
framework_package_dirs,
framework_route_source_candidate?(content : String, dir : String, framework_dirs : Set(String), import_marker : String, extra_methods : Array(String)) : Bool
framework_route_source_candidate?,
go_route_source_candidate?(content : String, extra_methods : Array(String)) : Bool
go_route_source_candidate?,
read_package_file_contents : Hash(String, String)
read_package_file_contents,
resolve_public_dirs(public_dirs : Array(Hash(String, String)))
resolve_public_dirs,
resolve_public_dirs_with_glob(public_dirs : Array(Hash(String, String)))
resolve_public_dirs_with_glob,
static_dir_entry(source_path : String, static_path : String, file_path : String) : Hash(String, String)
static_dir_entry,
ts_controller_method_bodies_for_directory(package_controller_method_bodies : Hash(String, Hash(String, Array(Noir::GoCalleeExtractor::FunctionBody))), dir : String) : Hash(String, Array(Noir::GoCalleeExtractor::FunctionBody))
ts_controller_method_bodies_for_directory,
ts_controller_methods_for_directory(package_controller_methods : Hash(String, Hash(String, Array(String))), dir : String) : Hash(String, Array(String))
ts_controller_methods_for_directory,
ts_function_bodies_for_directory(package_function_bodies : Hash(String, Hash(String, Noir::GoCalleeExtractor::FunctionBody)), dir : String) : Hash(String, Noir::GoCalleeExtractor::FunctionBody)
ts_function_bodies_for_directory,
ts_groups_for_directory(package_groups : Hash(String, Hash(String, String)), dir : String) : Hash(String, String)
ts_groups_for_directory
Class methods inherited from class Analyzer::Go::GoEngine
go_test_file?(relative_path : String) : Bool
go_test_file?,
strip_comments(text : String) : String
strip_comments
Instance methods inherited from class Analyzer
analyze
analyze,
base_path : String
base_path,
base_paths : Array(String)
base_paths,
base_relative_path(path : String) : String
base_relative_path,
callees_needed? : Bool
callees_needed?,
content_matches?(content : String, markers : Regex) : Bool
content_matches?,
http_header_name(name : String) : String | Nil
http_header_name,
line_number_for_index(content : String, char_index : Int32) : Int32
line_number_for_index,
logger : NoirLogger
logger,
parallel_analyze(files : Array(String), &block : String -> Nil)
parallel_analyze,
read_file_content(path : String) : String
read_file_content,
result : Array(Endpoint)
result,
tech : String
tech,
unique_params(params : Array(Param)) : Array(Param)
unique_params,
url : String
url,
web_root_path(path : String, markers : Array(String)) : String
web_root_path
Constructor methods inherited from class Analyzer
new(options : Hash(String, YAML::Any))
new
Macros inherited from class Analyzer
analyzer_for(tech)
analyzer_for
Instance methods inherited from module FileHelper
all_files : Array(String)
all_files,
get_files_by_basename(basename : String) : Array(String)
get_files_by_basename,
get_files_by_extension(extension : String) : Array(String)
get_files_by_extension,
get_files_by_extensions(extensions : Array(String)) : Array(String)
get_files_by_extensions,
get_files_by_prefix(prefix : String) : Array(String)
get_files_by_prefix,
get_files_by_prefix_and_extension(prefix : String, extension : String) : Array(String)
get_files_by_prefix_and_extension,
get_files_by_relative_path(relative_path : String, root : String = "") : Array(String)
get_files_by_relative_path,
get_public_dir_files(base_path : String, folder : String) : Array(String)
get_public_dir_files,
get_public_files(base_path : String, anchors : Array(String) = ["shard.yml", "Gemfile"]) : Array(String)
get_public_files,
walked_path(expanded : String) : String
walked_path
Class Method Detail
Instance Method Detail
Instance-side view of the same declaration. The per-file rescues live on
this base class, which has no way to name the analyzer that is running
inside them, so a skipped file could not be attributed to a tech.
Deriving it from analyzer_for keeps the name written exactly once.