admin: fix mismatched Swagger schema

This commit is contained in:
Jens Langhammer 2021-03-03 17:44:47 +01:00
parent 77d5ba2862
commit ea784d47f4
4 changed files with 12 additions and 10 deletions

View File

@ -7,14 +7,14 @@ from django.http.response import Http404
from django.utils.translation import gettext_lazy as _
from drf_yasg2.utils import swagger_auto_schema
from rest_framework.decorators import action
from rest_framework.fields import CharField, DateTimeField, IntegerField, ListField
from rest_framework.fields import CharField, ChoiceField, DateTimeField, ListField
from rest_framework.permissions import IsAdminUser
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.serializers import Serializer
from rest_framework.viewsets import ViewSet
from authentik.events.monitored_tasks import TaskInfo
from authentik.events.monitored_tasks import TaskInfo, TaskResultStatus
class TaskSerializer(Serializer):
@ -24,7 +24,9 @@ class TaskSerializer(Serializer):
task_description = CharField()
task_finish_timestamp = DateTimeField(source="finish_timestamp")
status = IntegerField(source="result.status.value")
status = ChoiceField(source="result.status.name", choices=[
(x.name, x.name) for x in TaskResultStatus
])
messages = ListField(source="result.messages")
def create(self, validated_data: dict) -> Model:

View File

@ -55,7 +55,7 @@ class VersionViewSet(ListModelMixin, GenericViewSet):
def get_queryset(self): # pragma: no cover
return None
@swagger_auto_schema(responses={200: VersionSerializer(many=True)})
@swagger_auto_schema(responses={200: VersionSerializer(many=False)})
def list(self, request: Request) -> Response:
"""Get running and latest version."""
return Response(VersionSerializer(True).data)

View File

@ -150,7 +150,6 @@ SWAGGER_SETTINGS = {
REST_FRAMEWORK = {
"DEFAULT_PAGINATION_CLASS": "authentik.api.pagination.Pagination",
"PAGE_SIZE": 100,
"DATETIME_FORMAT": "%s",
"DEFAULT_FILTER_BACKENDS": [
"rest_framework_guardian.filters.ObjectPermissionsFilter",
"django_filters.rest_framework.DjangoFilterBackend",

View File

@ -96,9 +96,6 @@ paths:
'200':
description: Get running and latest version.
schema:
description: ''
type: array
items:
$ref: '#/definitions/Version'
tags:
- admin
@ -9338,7 +9335,11 @@ definitions:
format: date-time
status:
title: Status
type: integer
type: string
enum:
- SUCCESSFUL
- WARNING
- ERROR
messages:
description: ''
type: array