Codesnippet.dev
</>

Integrating camelcase for Django REST Framework & drf_spectacular

django swagger drf django rest framework drf_spectacular

In Django REST API you usually want to achieve:

  1. Camelcase instead of snake_case for your data:
  1. Autogenerated Swagger documentation for your API

However, if you combine these two, types generated by drf_spectacular are still in snake_case.

The following configuration helps to solve the issue:

# settings.py
SPECTACULAR_SETTINGS = {
# makes params in URLs camelcase for consistency
'CAMELIZE_NAMES': True,
# transforms data types and responses
'POSTPROCESSING_HOOKS': [
'drf_spectacular.contrib.djangorestframework_camel_case.camelize_serializer_fields'
]
}