You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my API, I need this field to be returned as the key global, which is a reserved keyword in Python. I am able to make this work, but I am not currently able to get it to both return as global AND be displayed as global in the generated OpenAPI schema. It seems like the primary issues is that for schema generation the validation_alias always supersedes the serialization_alias.
I am using by_alias=True on my router.
This configuration results in the API response being correct, but the schema being wrong. The schema shows this key as global_access rather than global
If I put alias="global", then I must also set the validation_alias="global_access" or the API response fails. But as long as validation_alias is set, that is the key that appears in the schema. Does anyone know if there is a way, for response schemas, to leverage the serialization_alias instead of the validation_alias on the OpenAPI schema?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am running into an issue trying to get my aliases working right for my use case.
I have a Django model with a field
global_access
on itIn my API, I need this field to be returned as the key
global
, which is a reserved keyword in Python. I am able to make this work, but I am not currently able to get it to both return asglobal
AND be displayed asglobal
in the generated OpenAPI schema. It seems like the primary issues is that for schema generation thevalidation_alias
always supersedes theserialization_alias
.I am using
by_alias=True
on my router.This configuration results in the API response being correct, but the schema being wrong. The schema shows this key as
global_access
rather thanglobal
If I put
alias="global"
, then I must also set thevalidation_alias="global_access"
or the API response fails. But as long asvalidation_alias
is set, that is the key that appears in the schema. Does anyone know if there is a way, for response schemas, to leverage theserialization_alias
instead of thevalidation_alias
on the OpenAPI schema?Beta Was this translation helpful? Give feedback.
All reactions