Skip to main content

analyze_param

Parses and validates a function parameter's metadata to determine its FastAPI-specific configuration, such as whether it is a dependency, a path parameter, or a body field. It extracts type annotations and default values to construct a model field while enforcing strict validation rules for parameter definitions.

def analyze_param(
param_name: str,
annotation: Any,
value: Any,
is_path_param: bool
) - > ParamDetails

Parses and validates a function parameter to determine its FastAPI-specific metadata, such as whether it is a dependency, a path parameter, or a body field. This function resolves type annotations, handles Annotated metadata, and assigns appropriate FieldInfo or Depends objects based on the parameter's default value and type.

Parameters

NameTypeDescription
param_namestrThe name of the parameter as defined in the function signature.
annotationAnyThe type hint or annotation associated with the parameter, used to infer the data type and validation rules.
valueAnyThe default value assigned to the parameter in the function signature, which may contain FastAPI metadata like Query() or Depends().
is_path_paramboolA flag indicating whether this parameter is part of the URL path template.

Returns

TypeDescription
ParamDetailsAn object containing the resolved type annotation, the dependency information if applicable, and the constructed model field for the parameter.