Document the API in Swagger with tags, parameters and examples
- Add OpenAPI tags for the seven API groups and a full description (auth, error envelope, pagination, idempotency) in SPECTACULAR_SETTINGS - Annotate every endpoint with @extend_schema: summary, description, query parameters, request/response examples and error responses - Add shared schema helpers in apps/common/schema.py: ErrorEnvelope, error_responses(), pagination and catalog filter parameters - Document JWT login and token refresh that simplejwt ships without docs - Add ReDoc at /api/redoc/ next to Swagger UI at /api/docs/ - Add export_api_docs management command rendering the schema into a standalone HTML reference (no CDN) and commit docs/api-reference.html - Describe the documentation entry points in docs/architecture.md Schema validates cleanly: 41 operations, 0 warnings.
This commit is contained in:
1 parent
756f40353b
commit
f6c61ff8da
14 files changed
+2038
-9
No files matched your search
@@ -1,10 +1,20 @@
|
||||
from drf_spectacular.utils import (
|
||||
OpenApiExample,
|
||||
extend_schema,
|
||||
inline_serializer,
|
||||
)
|
||||
from rest_framework import serializers
|
||||
from rest_framework.permissions import AllowAny
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from apps.common.schema import error_responses
|
||||
|
||||
from .serializers import PaymentWebhookSerializer
|
||||
from .services import handle_yookassa_webhook
|
||||
|
||||
TAGS = ["Платежи"]
|
||||
|
||||
|
||||
class YooKassaWebhookView(APIView):
|
||||
"""Receives ЮKassa notifications.
|
||||
@@ -16,6 +26,51 @@ class YooKassaWebhookView(APIView):
|
||||
authentication_classes: list = []
|
||||
serializer_class = PaymentWebhookSerializer
|
||||
|
||||
@extend_schema(
|
||||
tags=TAGS,
|
||||
summary="Уведомление ЮKassa",
|
||||
description=(
|
||||
"Служебный метод: его вызывает платёжный провайдер, а не клиент. "
|
||||
"Применяет событие к платежу и заказу.\n\n"
|
||||
"Поддерживаемые события: `payment.succeeded`, `payment.canceled`, "
|
||||
"`refund.succeeded`. После успешной оплаты статус оплаты заказа "
|
||||
"пересчитывается по сумме всех успешных платежей — заказ может быть "
|
||||
"оплачен частично.\n\n"
|
||||
"Неизвестный платёж не считается ошибкой: ответ `200` с `detail: ignored`, "
|
||||
"чтобы провайдер не повторял доставку бесконечно."
|
||||
),
|
||||
request=PaymentWebhookSerializer,
|
||||
responses={
|
||||
200: inline_serializer(
|
||||
name="PaymentWebhookResponse",
|
||||
fields={
|
||||
"detail": serializers.CharField(
|
||||
help_text="`ok` — событие применено, `ignored` — платёж не найден."
|
||||
)
|
||||
},
|
||||
),
|
||||
**error_responses(400),
|
||||
},
|
||||
examples=[
|
||||
OpenApiExample(
|
||||
"Оплата прошла",
|
||||
value={
|
||||
"event": "payment.succeeded",
|
||||
"object": {
|
||||
"id": "2f1a9c74-000f-5000-9000-1a2b3c4d5e6f",
|
||||
"status": "succeeded",
|
||||
"amount": {"value": "21583.00", "currency": "RUB"},
|
||||
},
|
||||
},
|
||||
request_only=True,
|
||||
),
|
||||
OpenApiExample(
|
||||
"Событие применено",
|
||||
value={"detail": "ok"},
|
||||
response_only=True,
|
||||
),
|
||||
],
|
||||
)
|
||||
def post(self, request):
|
||||
payment = handle_yookassa_webhook(request.data)
|
||||
if payment is None:
|
||||
|
||||
Reference in new issue
Block a user