code: def as_form(cls: Type[BaseModel]) -> Any:
      """Adds an as_form class method to decorated models.
  
      The as_form class method can be used with FastAPI endpoints
      """
      new_params = [
          inspect.Parameter(
              field.alias,
              inspect.Parameter.POSITIONAL_ONLY,
              default=(
                  Form(field.default)
                  if not field.required
                  else Form(...)
              ),
          )
          for field in cls.__fields__.values()
      ]
  
      async def _as_form(**data):  # type: ignore
          return cls(**data)
  
      sig = inspect.signature(_as_form)
      sig = sig.replace(parameters=new_params)
      _as_form.__signature__ = sig  # type: ignore
      setattr(cls, "as_form", _as_form)
      return cls
  
imports: import inspect
  from typing import Any, Type
  from fastapi import FastAPI, Form
  from pydantic import BaseModel
label_desc: Use image node_id 1 for calling a global function with example usage: as_form(cls) and returns: cls, cls