I'm trying to POST some data to an API method using the browser (By using woocommerce in wordpress). When I use POST request with model entity as a null value model = None
to send data it works fine, but when use an Union of something (st) and None as model model: Union[st, None] = None
"422 Unprocessable Entity" error.
Handler:
@router.post("", status_code=201)
async def post_webhook(
request: Request,
db: Database = Depends(deps.get_db_async),
settings: MountOlympusSettings = Depends(deps.get_settings),
model: Union[WebhookModel, None] = None,
) -> Any:
That WebhookModel is:
class Billing(BaseModel):
first_name: str
last_name: str
company: str
address_1: str
address_2: str
city: str
postcode: str
country: str
state: str
email: str
phone: str
class Shipping(BaseModel):
first_name: str
last_name: str
company: str
address_1: str
address_2: str
city: str
postcode: str
country: str
state: str
phone: str
class MetaDatum(BaseModel):
id: int
key: str
value: str
class WebhookModel(BaseModel):
id: int
date_created: str
date_created_gmt: str
date_modified: str
date_modified_gmt: str
email: str
first_name: str
last_name: str
role: str
username: str
billing: Billing
shipping: Shipping
is_paying_customer: bool
avatar_url: str
meta_data: List[MetaDatum]
_links: _Links
In this code, when model is as a WebhookModel it's ok, but when model is none, it dos't work and return 422 Unprocessable Entity
Error.