-
-
Notifications
You must be signed in to change notification settings - Fork 528
-
I'm trying to add a new Schema in the response depending on the parameter of the endpoint, but I'm getting a Pydantic error. Is it possible to include like this or I'll have to split it in two different endpoints?
api.py
@router.get( "/infodengue/", response={ 200: Union[List[HistoricoAlertaSchema], List[HistoricoAlertaPartialSchema]], # <---- Union 404: NotFoundSchema, 500: InternalErrorSchema, }, auth=uidkey_auth, tags=["datastore", "infodengue"], ) @paginate(paginator) @csrf_exempt def get_infodengue( request, filters: HistoricoAlertaFilterSchema = Query(...), full: bool = False, # <---- parameter to define the returning schema **kwargs, ): [...] if full: data = HistoricoAlerta.objects.using("infodengue").all() else: data = HistoricoAlertaPartial.objects.using("infodengue").all() [...] data = filters.filter(data) return data.order_by("-data_iniSE")
Traceback
pydantic_core._pydantic_core.ValidationError: 300 validation errors for NinjaResponseSchema response.items.0 Input should be a valid list [type=list_type, input_value=<HistoricoAlertaPartial: ...ct (411980620240520123)>, input_type=HistoricoAlertaPartial] For further information visit https://errors.pydantic.dev/2.11/v/list_type
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment