class
Analyzer::Python::FastAPI
Defined in:
analyzer/analyzers/python/fastapi.crConstant Summary
-
APIROUTER_INSTANCE_RE =
/(#{PYTHON_VAR_NAME_REGEX})(?::#{DOT_NATION})?=(?:fastapi\.)?APIRouter\(/ -
FASTAPI_INSTANCE_RE =
/(#{PYTHON_VAR_NAME_REGEX})(?::#{DOT_NATION})?=(?:fastapi\.)?FastAPI\(/ -
Constant-only matchers hoisted out of the per-line analyze loops so they aren't recompiled (Crystal rebuilds an interpolated regex literal on every evaluation). The
.to_sexpansion of the interpolated constants is byte-identical to the previous inline form. -
FASTAPI_PARAM_CLASS_RE =
/\b(?:Header|Query|Cookie|Path|Body|Form|File)\s*\(/ -
The Python identifier a FastAPI handler declares is not always the name the client sends. Two rules rewrite it, and Noir honored neither:
alias=overrides the name outright, for every parameter class (Header,Query,Cookie,Form,File,Body,Path).Header— and onlyHeader— additionally maps_to-, because an HTTP header name can't carry an underscore in most stacks. That isconvert_underscores, and it defaults to True; passingconvert_underscores=Falseis what opts back out.
Reporting the identifier verbatim is not a cosmetic mismatch: it is the name Noir hands to the next stage.
-f curlemitted-H 'x_token: 'forx_token: str = Header(None), a header the app reads as nothing, and a DAST tool importing the OpenAPI doc probed?q_name=for a parameter the app only accepts asq-name. -
HANDLER_CALL_RE =
/^(#{PYTHON_VAR_NAME_REGEX}(?:\.#{PYTHON_VAR_NAME_REGEX})?)\s*\(/ -
HANDLER_REF_RE =
/^#{PYTHON_VAR_NAME_REGEX}(?:\.#{PYTHON_VAR_NAME_REGEX})?$/ -
MODEL_FIELD_CALL_RE =
/\bField\s*\(/ -
The same rename, one layer down. A request body is described by a Pydantic model, and
Field(alias=...)renames the key there too — withpopulate_by_nameoff (the default) the alias is the only key the model accepts, so the attribute name is a body field the app rejects outright. -
NO_CONVERT_UNDERSCORES_RE =
/\bconvert_underscores\s*=\s*False\b/ -
PATH_PARAM_REGEX =
/\{(#{PYTHON_VAR_NAME_REGEX})(?::[a-zA-Z_][a-zA-Z0-9_]*)?\}/ -
TYPED_PATH_PARAM_REGEX =
/\{(#{PYTHON_VAR_NAME_REGEX}):[a-zA-Z_][a-zA-Z0-9_]*\}/ -
VAR_NAME_FULL_RE =
/^#{PYTHON_VAR_NAME_REGEX}$/
Class Method Summary
Instance Method Summary
- #analyze
-
#configure_router_prefix(file : String, include_router_map : Hash(String, Hash(String, Router)), app_base_path : String, router_prefix : String = "", target_instance_name : String | Nil = nil, visited : Set(String) = Set(::String).new)
Configures the prefix for each router
-
#find_base_model_params(source : String, class_name : String, param_name : String) : Array(Param)
Finds the parameters for a base model class
-
#find_dictionary_params(source : String, param : FunctionParameter) : Array(Param)
Finds parameters in dictionary structures
-
#infer_parameter_type(data : String, is_param_type = false) : String | Nil
Infers the type of the parameter based on its default value or type annotation
-
#resolve_constant_value(expression : String, import_modules : Hash(String, Tuple(String, Int32))) : String | Nil
Best-effort resolver for a non-literal
prefix=expression ininclude_router(...). -
#tech : String
Instance-side view of the same declaration.
Instance methods inherited from class Analyzer::Python::PythonEngine
build_callees_from(body : String, body_start_line : Int32, path : String, *, definition_base_path : String | Nil = nil, source : String | Nil = nil) : Array(Callee)
build_callees_from,
find_def_line(lines : Array(String), decorator_line : Int32) : Int32 | Nil
find_def_line,
find_imported_modules(app_base_path : String, file_path : String, content : String | Nil = nil) : Hash(String, Tuple(String, Int32))
find_imported_modules,
find_imported_package(package_path : String, dotted_as_names : String) : Array(Tuple(String, String, Int32))
find_imported_package,
find_json_params(codeblock_lines : Array(String), json_var_names : Array(String)) : Array(Param)
find_json_params,
join_until_python_call_closes(lines : Array(String), index : Int32, line : String) : String
join_until_python_call_closes,
parse_code_block(data : String | Array(String), after : Regex | Nil = nil) : String | Nil
parse_code_block,
parse_function_def(source_lines : Array(String), start_index : Int32) : FunctionDefinition | Nil
parse_function_def,
push_callees_from(endpoint : Endpoint, body : String, body_start_line : Int32, path : String, *, definition_base_path : String | Nil = nil, source : String | Nil = nil) : Nil
push_callees_from,
python_bracket_delta(line : String) : Int32
python_bracket_delta,
python_paren_delta(line : String) : Int32
python_paren_delta,
python_signature_line_span(lines : Array(String)) : Int32
python_signature_line_span,
return_literal_value(data : String) : String
return_literal_value
Class methods inherited from class Analyzer::Python::PythonEngine
python_test_path?(path : String, base_path : String | Nil = nil) : Bool
python_test_path?
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_at_byte_offset(content : String, byte_offset : Int32) : Int32
line_at_byte_offset,
line_at_offset(content : String, offset : Int32) : Int32
line_at_offset,
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
Configures the prefix for each router
Finds the parameters for a base model class
Finds parameters in dictionary structures
Infers the type of the parameter based on its default value or type annotation
Best-effort resolver for a non-literal prefix= expression in
include_router(...). Handles two shapes the wild produces:
prefix=API_V1_STR— a top-level constant imported viafrom app.core.config import API_V1_STR. We look up the constant's defining module viaimport_modulesand search it forNAME = "literal".prefix=settings.API_V1_STR— class-attribute access on an imported instance. We look upsettings's module and search it forAPI_V1_STR: str = "literal"(the BaseSettings shape full-stack-fastapi-template uses) orAPI_V1_STR = "literal".
Returns nil when the expression doesn't match either shape or we can't find the underlying file — the caller then falls back to an empty prefix so we never surface raw Python expressions in URLs.
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.