mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-16 13:51:26 +01:00
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.
21 lines
635 B
Python
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}…`."
|
|
),
|
|
}
|