Home / Function/ create_model_field() — fastapi Function Reference

create_model_field() — fastapi Function Reference

Architecture documentation for the create_model_field() function in utils.py from the fastapi codebase.

Entity Profile

Dependency Diagram

graph TD
  8e7d845c_a4e7_ee84_5295_5f3b995b05b4["create_model_field()"]
  1c2c0e68_6ed1_7632_8c35_00818f97b599["utils.py"]
  8e7d845c_a4e7_ee84_5295_5f3b995b05b4 -->|defined in| 1c2c0e68_6ed1_7632_8c35_00818f97b599
  3a586946_6748_d24d_8ee8_d3c9dbd7e696["analyze_param()"]
  3a586946_6748_d24d_8ee8_d3c9dbd7e696 -->|calls| 8e7d845c_a4e7_ee84_5295_5f3b995b05b4
  442274ca_f275_350e_f39a_7f88cd50be4a["get_body_field()"]
  442274ca_f275_350e_f39a_7f88cd50be4a -->|calls| 8e7d845c_a4e7_ee84_5295_5f3b995b05b4
  d8b4fb83_3521_0b7e_fcfa_0c7f161ca116["__init__()"]
  d8b4fb83_3521_0b7e_fcfa_0c7f161ca116 -->|calls| 8e7d845c_a4e7_ee84_5295_5f3b995b05b4
  style 8e7d845c_a4e7_ee84_5295_5f3b995b05b4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

fastapi/utils.py lines 60–79

def create_model_field(
    name: str,
    type_: Any,
    default: Optional[Any] = Undefined,
    field_info: Optional[FieldInfo] = None,
    alias: Optional[str] = None,
    mode: Literal["validation", "serialization"] = "validation",
) -> ModelField:
    if annotation_is_pydantic_v1(type_):
        raise PydanticV1NotSupportedError(
            "pydantic.v1 models are no longer supported by FastAPI."
            f" Please update the response model {type_!r}."
        )
    field_info = field_info or FieldInfo(annotation=type_, default=default, alias=alias)
    try:
        return v2.ModelField(mode=mode, name=name, field_info=field_info)
    except PydanticSchemaGenerationError:
        raise fastapi.exceptions.FastAPIError(
            _invalid_args_message.format(type_=type_)
        ) from None

Domain

Subdomains

Defined In

Frequently Asked Questions

What does create_model_field() do?
create_model_field() is a function in the fastapi codebase, defined in fastapi/utils.py.
Where is create_model_field() defined?
create_model_field() is defined in fastapi/utils.py at line 60.
What calls create_model_field()?
create_model_field() is called by 3 function(s): __init__, analyze_param, get_body_field.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free