*: cleanup api schema warnings

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-08-26 09:36:41 +02:00
parent 9b09793230
commit 2ae164df78
8 changed files with 68 additions and 67 deletions

View File

@ -4,14 +4,9 @@ from django.db.models import QuerySet
from django.http.response import HttpResponseBadRequest from django.http.response import HttpResponseBadRequest
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from drf_spectacular.types import OpenApiTypes from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import ( from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
OpenApiParameter,
OpenApiResponse,
extend_schema,
inline_serializer,
)
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.fields import BooleanField, CharField, FileField, ReadOnlyField from rest_framework.fields import ReadOnlyField
from rest_framework.parsers import MultiPartParser from rest_framework.parsers import MultiPartParser
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
@ -24,6 +19,7 @@ from authentik.admin.api.metrics import CoordinateSerializer, get_events_per_1h
from authentik.api.decorators import permission_required from authentik.api.decorators import permission_required
from authentik.core.api.providers import ProviderSerializer from authentik.core.api.providers import ProviderSerializer
from authentik.core.api.used_by import UsedByMixin from authentik.core.api.used_by import UsedByMixin
from authentik.core.api.utils import FilePathSerializer, FileUploadSerializer
from authentik.core.models import Application, User from authentik.core.models import Application, User
from authentik.events.models import EventAction from authentik.events.models import EventAction
from authentik.policies.api.exec import PolicyTestResultSerializer from authentik.policies.api.exec import PolicyTestResultSerializer
@ -180,13 +176,7 @@ class ApplicationViewSet(UsedByMixin, ModelViewSet):
@permission_required("authentik_core.change_application") @permission_required("authentik_core.change_application")
@extend_schema( @extend_schema(
request={ request={
"multipart/form-data": inline_serializer( "multipart/form-data": FileUploadSerializer,
"SetIcon",
fields={
"file": FileField(required=False),
"clear": BooleanField(default=False),
},
)
}, },
responses={ responses={
200: OpenApiResponse(description="Success"), 200: OpenApiResponse(description="Success"),
@ -218,7 +208,7 @@ class ApplicationViewSet(UsedByMixin, ModelViewSet):
@permission_required("authentik_core.change_application") @permission_required("authentik_core.change_application")
@extend_schema( @extend_schema(
request=inline_serializer("SetIconURL", fields={"url": CharField()}), request=FilePathSerializer,
responses={ responses={
200: OpenApiResponse(description="Success"), 200: OpenApiResponse(description="Success"),
400: OpenApiResponse(description="Bad request"), 400: OpenApiResponse(description="Bad request"),

View File

@ -2,7 +2,7 @@
from typing import Any from typing import Any
from django.db.models import Model from django.db.models import Model
from rest_framework.fields import CharField, IntegerField from rest_framework.fields import BooleanField, CharField, FileField, IntegerField
from rest_framework.serializers import Serializer, SerializerMethodField, ValidationError from rest_framework.serializers import Serializer, SerializerMethodField, ValidationError
@ -22,8 +22,18 @@ class PassiveSerializer(Serializer):
def update(self, instance: Model, validated_data: dict) -> Model: # pragma: no cover def update(self, instance: Model, validated_data: dict) -> Model: # pragma: no cover
return Model() return Model()
class Meta:
model = Model class FileUploadSerializer(PassiveSerializer):
"""Serializer to upload file"""
file = FileField(required=False)
clear = BooleanField(default=False)
class FilePathSerializer(PassiveSerializer):
"""Serializer to upload file"""
url = CharField()
class MetaNameSerializer(PassiveSerializer): class MetaNameSerializer(PassiveSerializer):

View File

@ -7,10 +7,10 @@ from django.http.response import HttpResponseBadRequest, JsonResponse
from django.urls import reverse from django.urls import reverse
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
from drf_spectacular.types import OpenApiTypes from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiResponse, extend_schema, inline_serializer from drf_spectacular.utils import OpenApiResponse, extend_schema
from guardian.shortcuts import get_objects_for_user from guardian.shortcuts import get_objects_for_user
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.fields import BooleanField, FileField, ReadOnlyField from rest_framework.fields import ReadOnlyField
from rest_framework.parsers import MultiPartParser from rest_framework.parsers import MultiPartParser
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
@ -20,7 +20,12 @@ from structlog.stdlib import get_logger
from authentik.api.decorators import permission_required from authentik.api.decorators import permission_required
from authentik.core.api.used_by import UsedByMixin from authentik.core.api.used_by import UsedByMixin
from authentik.core.api.utils import CacheSerializer, LinkSerializer from authentik.core.api.utils import (
CacheSerializer,
FilePathSerializer,
FileUploadSerializer,
LinkSerializer,
)
from authentik.flows.exceptions import FlowNonApplicableException from authentik.flows.exceptions import FlowNonApplicableException
from authentik.flows.models import Flow from authentik.flows.models import Flow
from authentik.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlanner, cache_key from authentik.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlanner, cache_key
@ -147,7 +152,7 @@ class FlowViewSet(UsedByMixin, ModelViewSet):
], ],
) )
@extend_schema( @extend_schema(
request={"multipart/form-data": inline_serializer("SetIcon", fields={"file": FileField()})}, request={"multipart/form-data": FileUploadSerializer},
responses={ responses={
204: OpenApiResponse(description="Successfully imported flow"), 204: OpenApiResponse(description="Successfully imported flow"),
400: OpenApiResponse(description="Bad request"), 400: OpenApiResponse(description="Bad request"),
@ -259,13 +264,7 @@ class FlowViewSet(UsedByMixin, ModelViewSet):
@permission_required("authentik_flows.change_flow") @permission_required("authentik_flows.change_flow")
@extend_schema( @extend_schema(
request={ request={
"multipart/form-data": inline_serializer( "multipart/form-data": FileUploadSerializer,
"SetIcon",
fields={
"file": FileField(required=False),
"clear": BooleanField(default=False),
},
)
}, },
responses={ responses={
200: OpenApiResponse(description="Success"), 200: OpenApiResponse(description="Success"),
@ -301,7 +300,7 @@ class FlowViewSet(UsedByMixin, ModelViewSet):
@permission_required("authentik_core.change_application") @permission_required("authentik_core.change_application")
@extend_schema( @extend_schema(
request=inline_serializer("SetIconURL", fields={"url": CharField()}), request=FilePathSerializer,
responses={ responses={
200: OpenApiResponse(description="Success"), 200: OpenApiResponse(description="Success"),
400: OpenApiResponse(description="Bad request"), 400: OpenApiResponse(description="Bad request"),

View File

@ -3,7 +3,7 @@ from django.urls import reverse
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from drf_spectacular.utils import OpenApiResponse, extend_schema from drf_spectacular.utils import OpenApiResponse, extend_schema
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.fields import ReadOnlyField from rest_framework.fields import CharField
from rest_framework.generics import get_object_or_404 from rest_framework.generics import get_object_or_404
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
@ -49,12 +49,12 @@ class OAuth2ProviderSerializer(ProviderSerializer):
class OAuth2ProviderSetupURLs(PassiveSerializer): class OAuth2ProviderSetupURLs(PassiveSerializer):
"""OAuth2 Provider Metadata serializer""" """OAuth2 Provider Metadata serializer"""
issuer = ReadOnlyField() issuer = CharField(read_only=True)
authorize = ReadOnlyField() authorize = CharField(read_only=True)
token = ReadOnlyField() token = CharField(read_only=True)
user_info = ReadOnlyField() user_info = CharField(read_only=True)
provider_info = ReadOnlyField() provider_info = CharField(read_only=True)
logout = ReadOnlyField() logout = CharField(read_only=True)
class OAuth2ProviderViewSet(UsedByMixin, ModelViewSet): class OAuth2ProviderViewSet(UsedByMixin, ModelViewSet):

View File

@ -11,7 +11,7 @@ from django_filters.filterset import FilterSet
from drf_spectacular.types import OpenApiTypes from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.fields import CharField, FileField, ReadOnlyField, SerializerMethodField from rest_framework.fields import CharField, FileField, SerializerMethodField
from rest_framework.parsers import MultiPartParser from rest_framework.parsers import MultiPartParser
from rest_framework.permissions import AllowAny from rest_framework.permissions import AllowAny
from rest_framework.relations import SlugRelatedField from rest_framework.relations import SlugRelatedField
@ -70,8 +70,8 @@ class SAMLProviderSerializer(ProviderSerializer):
class SAMLMetadataSerializer(PassiveSerializer): class SAMLMetadataSerializer(PassiveSerializer):
"""SAML Provider Metadata serializer""" """SAML Provider Metadata serializer"""
metadata = ReadOnlyField() metadata = CharField(read_only=True)
download_url = ReadOnlyField(required=False) download_url = CharField(read_only=True, required=False)
class SAMLProviderImportSerializer(PassiveSerializer): class SAMLProviderImportSerializer(PassiveSerializer):

View File

@ -1710,7 +1710,7 @@ paths:
content: content:
multipart/form-data: multipart/form-data:
schema: schema:
$ref: '#/components/schemas/SetIconRequest' $ref: '#/components/schemas/FileUploadRequest'
security: security:
- authentik: [] - authentik: []
- cookieAuth: [] - cookieAuth: []
@ -1738,13 +1738,13 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/SetIconURLRequest' $ref: '#/components/schemas/FilePathRequest'
application/x-www-form-urlencoded: application/x-www-form-urlencoded:
schema: schema:
$ref: '#/components/schemas/SetIconURLRequest' $ref: '#/components/schemas/FilePathRequest'
multipart/form-data: multipart/form-data:
schema: schema:
$ref: '#/components/schemas/SetIconURLRequest' $ref: '#/components/schemas/FilePathRequest'
required: true required: true
security: security:
- authentik: [] - authentik: []
@ -5492,7 +5492,7 @@ paths:
content: content:
multipart/form-data: multipart/form-data:
schema: schema:
$ref: '#/components/schemas/SetIconRequest' $ref: '#/components/schemas/FileUploadRequest'
security: security:
- authentik: [] - authentik: []
- cookieAuth: [] - cookieAuth: []
@ -5520,13 +5520,13 @@ paths:
content: content:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/SetIconURLRequest' $ref: '#/components/schemas/FilePathRequest'
application/x-www-form-urlencoded: application/x-www-form-urlencoded:
schema: schema:
$ref: '#/components/schemas/SetIconURLRequest' $ref: '#/components/schemas/FilePathRequest'
multipart/form-data: multipart/form-data:
schema: schema:
$ref: '#/components/schemas/SetIconURLRequest' $ref: '#/components/schemas/FilePathRequest'
required: true required: true
security: security:
- authentik: [] - authentik: []
@ -5613,7 +5613,7 @@ paths:
content: content:
multipart/form-data: multipart/form-data:
schema: schema:
$ref: '#/components/schemas/SetIconRequest' $ref: '#/components/schemas/FileUploadRequest'
security: security:
- authentik: [] - authentik: []
- cookieAuth: [] - cookieAuth: []
@ -21583,6 +21583,24 @@ components:
type: string type: string
required: required:
- expression - expression
FilePathRequest:
type: object
description: Serializer to upload file
properties:
url:
type: string
required:
- url
FileUploadRequest:
type: object
description: Serializer to upload file
properties:
file:
type: string
format: binary
clear:
type: boolean
default: false
Flow: Flow:
type: object type: object
description: Flow Serializer description: Flow Serializer
@ -29582,22 +29600,6 @@ components:
$ref: '#/components/schemas/UserSelf' $ref: '#/components/schemas/UserSelf'
required: required:
- user - user
SetIconRequest:
type: object
properties:
file:
type: string
format: binary
clear:
type: boolean
default: false
SetIconURLRequest:
type: object
properties:
url:
type: string
required:
- url
SeverityEnum: SeverityEnum:
enum: enum:
- notice - notice

View File

@ -76,7 +76,7 @@ export class ApplicationForm extends ModelForm<Application, string> {
return writeOp.then((app) => { return writeOp.then((app) => {
return new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconUrlCreate({ return new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconUrlCreate({
slug: app.slug, slug: app.slug,
setIconURLRequest: { filePathRequest: {
url: data.metaIcon || "", url: data.metaIcon || "",
}, },
}); });

View File

@ -62,7 +62,7 @@ export class FlowForm extends ModelForm<Flow, string> {
return writeOp.then((app) => { return writeOp.then((app) => {
return new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundUrlCreate({ return new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundUrlCreate({
slug: app.slug, slug: app.slug,
setIconURLRequest: { filePathRequest: {
url: data.background || "", url: data.background || "",
}, },
}); });