fastapi2cli.parameters package

Submodules

fastapi2cli.parameters.get_params_for module

fastapi2cli.parameters.get_params_for.get_parameters_for_dependency(dependency: Dependant, property_names_to_include: Sequence[Literal['path_params', 'query_params', 'header_params', 'cookie_params', 'body_params']] = None) dict[str, FieldInfo]

Recursively retrieves parameters associated with a dependency.

This function traverses through the dependency tree and collects all parameters associated with the dependency, including path, query, header, cookie, and body parameters.

Parameters:
  • dependency (Dependant) – The dependency object for which parameters are retrieved.

  • property_names_to_include (Sequence[AllowedPropertyName], optional) – A list of property names to include in parameter retrieval. Default is None, which includes all properties (path_params, query_params, header_params, cookie_params, body_params).

Returns:

A dictionary containing parameter names as keys and corresponding ModelField objects as values.

Return type:

Dict[str, FieldInfo]

fastapi2cli.parameters.get_params_for.get_parameters_for_route(route: APIRoute, *, property_names_to_include: Sequence[Literal['path_params', 'query_params', 'header_params', 'cookie_params', 'body_params']] = None) dict[str, FieldInfo]

Retrieves parameters associated with a route.

This function collects all parameters associated with a given route, including those defined in the route dependency tree.

Parameters:
  • route (APIRoute) – The route for which parameters are retrieved.

  • property_names_to_include (Sequence[AllowedPropertyName], optional) – A list of property names to include in parameter retrieval. Default is None, which includes all properties (path_params, query_params, header_params, cookie_params, body_params).

Returns:

A dictionary containing parameter names as keys and corresponding ModelField objects as values.

Return type:

Dict[str, ModelField]

fastapi2cli.parameters.simplifier module

fastapi2cli.parameters.simplifier.convert_parameters_to_typer_supported_format(original_parameters: dict[str, FieldInfo]) dict[str, FieldInfo]

Convert parameters from an original dictionary into a dict of typer supported FieldInfo.

Convert parameters by removing nested BaseModel types and returning a dictionary containing flattened parameters. Also, convert ‘type | None’ into Optional[type] as typer don’t support the first format

Parameters:

original_parameters (dict[str, ModelField]) – The original dictionary containing parameters.

Returns:

A dictionary containing simplified parameters.

Return type:

dict[str, ModelField]

fastapi2cli.parameters.simplifier.explode_parameter(parent_key: str, parent_type: type[BaseModel]) dict[str, FieldInfo]

Explode parameters from a parent BaseModel type.

Recursively explores the fields of a parent BaseModel type and returns a dictionary containing parameter names as keys and corresponding ModelField objects as values.

Parameters:
  • parent_key (str) – The key of the parent parameter.

  • parent_type (type[BaseModel]) – The parent BaseModel type.

Returns:

A dictionary containing exploded parameters.

Return type:

Dict[str, ModelField]

fastapi2cli.parameters.validation module

fastapi2cli.parameters.validation.validate_parameter_consistency(new_parameter_name: str, new_parameter_value: FieldInfo, existing_parameters: dict[str, FieldInfo])

Validate consistency of a new parameter with existing parameters.

This function checks whether a new parameter being added to a dictionary of existing parameters is consistent with the types of parameters with the same name already present in the dictionary.

Parameters:
  • new_parameter_name (str) – The name of the new parameter to be validated.

  • new_parameter_value (FieldInfo) – Information about the new parameter to be validated.

  • existing_parameters (dict[str, FieldInfo]) – Dictionary containing information about existing parameters.

Raises:

ValueError – If the new parameter conflicts with an existing parameter in terms of type.

Module contents