I have a FastAPI endpoint that fetches all database records for an entity, applying a payload. One of the payload fields refers to the order when bringing the data (which can even be by more than one column). So I have this:
class PayloadExecution(BaseExecution): init_date__lte: Optional[datetime] = Field(None, alias="init_date_below_equal") final_date__gte: Optional[datetime] = Field(None, alias="final_date_above_equal") custom_order: Optional[List[OrderOptions]] class config: use_enum_values = Trueclass QueryPayloadExecution(PayloadExecution): @classmethod async def as_query( cls, init_date: Optional[datetime] = Query(None), final_date: Optional[datetime] = Query(None), tag: Optional[str] = Query(None), guid_execution: Optional[str] = Query(None), is_officialized: Optional[bool] = Query(None), worker_status: Optional[int] = Query(None), worker_info: Optional[str] = Query(None), official_name: Optional[str] = Query(None), status: Optional[int] = Query(None), last_real: Optional[datetime] = Query(None), subfamily_x_forecast_id: Optional[int] = Query(None), execution_type: Optional[str] = Query(None), init_date__lte: Optional[datetime] = Query(None), final_date__gte: Optional[datetime] = Query(None), custom_order: Optional[List[OrderOptions]] = Query(None), ): return cls( init_date=init_date, final_date=final_date, tag=tag, guid_execution=guid_execution, is_officialized=is_officialized, worker_status=worker_status, worker_info=worker_info, official_name=official_name, status=status, last_real=last_real, subfamily_x_forecast_id=subfamily_x_forecast_id, execution_type=execution_type, init_date__lte=init_date__lte, final_date__gte=final_date__gte, custom_order=custom_order, )@router.get("", response_class=JSONResponse, response_model=Optional[List[ExecutionInDB]], status_code=200, responses={ 200: {"description": "Execution found"}, 401: {"description": "unauthorized"}, },)async def get_all( *, payload: QueryPayloadExecution = Depends(QueryPayloadExecution.as_query), skip: int = Query(0), limit: int = Query(99999)): executions_responses = await execution_service.get_all_ordered( payload=payload.dict(exclude_none=True), skip=skip, limit=limit, ) return executions_responses
As you can see, custom_order is a list of OrderOptions. So, this looks like this in my swagger:
But I don't want it to be generated like this, since the order in which they are sent is important. I would like it to appear as when it is simply a string:
(But I can select values from the enum). This way I can add them in the order I want. Is this possible? If it is, how is it done?