class

Analyzer::Python::FastAPI

Inherits Analyzer::Python::PythonEngine < Analyzer < FileHelper < Reference < Object

Constants

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_s expansion of the interpolated constants is byte-identical to the previous inline form.

HANDLER_CALL_RE = /^(#{PYTHON_VAR_NAME_REGEX}(?:\.#{PYTHON_VAR_NAME_REGEX})?)\s*\(/
HANDLER_REF_RE = /^#{PYTHON_VAR_NAME_REGEX}(?:\.#{PYTHON_VAR_NAME_REGEX})?$/
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 methods

tech_name
Source

Instance methods

analyze
Source
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

Source
find_base_model_params(source : String, class_name : String, param_name : String) : Array(Param)

Finds the parameters for a base model class

Source
find_dictionary_params(source : String, param : FunctionParameter) : Array(Param)

Finds parameters in dictionary structures

Source
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

Source
resolve_constant_value(expression : String, import_modules : Hash(String, Tuple(String, Int32))) : String | Nil

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 via from app.core.config import API_V1_STR. We look up the constant's defining module via import_modules and search it for NAME = "literal".
  • prefix=settings.API_V1_STR — class-attribute access on an imported instance. We look up settings's module and search it for API_V1_STR: str = "literal" (the BaseSettings shape full-stack-fastapi-template uses) or API_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.

Source
tech

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.

Source