Open armanddidierjean opened 1 year ago
A possible amelioration would be the usage of a as_form decorator to mark a schema as Form. See https://stackoverflow.com/questions/60127234/how-to-use-a-pydantic-model-with-form-data-in-fastapi/77113651#77113651
as_form
Form
We would need to require Python 3.11 to use this syntax
import inspect from typing import Annotated from fastapi import Form def as_form(cls): """ https://stackoverflow.com/questions/60127234/how-to-use-a-pydantic-model-with-form-data-in-fastapi/77113651#77113651 """ new_params = [ inspect.Parameter( field_name, inspect.Parameter.POSITIONAL_ONLY, default=model_field.default, annotation=Annotated[model_field.annotation, *model_field.metadata, Form()], ) for field_name, model_field in cls.model_fields.items() ] cls.__signature__ = cls.__signature__.replace(parameters=new_params) return cls
https://fastapi.tiangolo.com/tutorial/request-form-models/
Subject of the issue
A possible amelioration would be the usage of a
as_form
decorator to mark a schema asForm
. See https://stackoverflow.com/questions/60127234/how-to-use-a-pydantic-model-with-form-data-in-fastapi/77113651#77113651We would need to require Python 3.11 to use this syntax