Files
WYGIWYH/app/apps/api/schema.py
T
Herculino Trotta a432fae632 fix(api): clear the API docs schema warnings
Describe the API token authentication, name the colliding transaction
type enums, and use nullable instead of an OpenAPI 3.1 null type. A test
keeps the schema free of warnings.
2026-11-14 02:12:16 -03:00

21 lines
635 B
Python

from drf_spectacular.extensions import OpenApiAuthenticationExtension
from apps.users.models import APIToken
class APITokenAuthenticationScheme(OpenApiAuthenticationExtension):
"""Describes APITokenAuthentication in the API docs."""
target_class = "apps.api.authentication.APITokenAuthentication"
name = "apiToken"
def get_security_definition(self, auto_schema):
return {
"type": "apiKey",
"in": "header",
"name": "Authorization",
"description": (
f"A personal API token, sent as `Token {APIToken.TOKEN_PREFIX}…`."
),
}