Schema

CustomAutoSchema

class headless_cms.schema.auto_schema.CustomAutoSchema

Bases: AutoSchema

Custom AutoSchema for DRF Spectacular.

This class extends the default AutoSchema provided by DRF Spectacular to add global parameters to the OpenAPI schema. Specifically, it adds an “accept-language” header parameter to all endpoints.

global_params

A list of global OpenAPI parameters to be added to all endpoints.

Type:

list

Configuration:

To use this custom schema in Django REST Framework, update your settings:

# Rest framework
REST_FRAMEWORK = {
    "DEFAULT_RENDERER_CLASSES": [
        "rest_framework.renderers.JSONRenderer",
    ],
    "DEFAULT_SCHEMA_CLASS": "headless_cms.schema.auto_schema.CustomAutoSchema",
}
get_override_parameters()

Get the override parameters for the schema.

This method extends the default parameters with the global parameters defined in the global_params attribute.

Returns:

A list of OpenAPI parameters.

Return type:

list

global_params = [<drf_spectacular.utils.OpenApiParameter object>]

preprocessing_filter_spec

headless_cms.schema.preprocessing_hooks.preprocessing_filter_spec(endpoints)

Preprocessing hook to filter endpoints for the OpenAPI schema.

This function filters the endpoints to include only those views that extend the CMSSchemaMixin. It is used as a preprocessing hook for DRF Spectacular to dynamically generate the OpenAPI schema for CMS views.

Parameters:

endpoints (list) – A list of endpoints to be processed.

Returns:

A filtered list of endpoints that include only CMS views.

Return type:

list

CMSSpectacularAPIView

class headless_cms.schema.views.CMSSpectacularAPIView(**kwargs)

Bases: SpectacularAPIView

Custom Spectacular API view for CMS.

This view extends the default Spectacular API view to use custom settings for preprocessing hooks, as defined in the headless CMS settings.

custom_settings

A dictionary of custom settings for the Spectacular API view.

Type:

dict

custom_settings: Dict[str, Any] | None = {'PREPROCESSING_HOOKS': ['headless_cms.schema.preprocessing_hooks.preprocessing_filter_spec']}