*: fix API Schema for file uploads

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-17 23:12:52 +02:00
parent e177ab33e0
commit 3cf0f07baf
4 changed files with 55 additions and 47 deletions

View File

@ -6,9 +6,14 @@ from django.db.models import QuerySet
from django.http.response import HttpResponseBadRequest
from django.shortcuts import get_object_or_404
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
from drf_spectacular.utils import (
OpenApiParameter,
OpenApiResponse,
extend_schema,
inline_serializer,
)
from rest_framework.decorators import action
from rest_framework.fields import SerializerMethodField
from rest_framework.fields import FileField, SerializerMethodField
from rest_framework.parsers import MultiPartParser
from rest_framework.request import Request
from rest_framework.response import Response
@ -155,15 +160,11 @@ class ApplicationViewSet(ModelViewSet):
@permission_required("authentik_core.change_application")
@extend_schema(
request=OpenApiTypes.NONE,
parameters=[
OpenApiParameter(
name="file",
location=OpenApiParameter.QUERY, # TODO: In Form
type=OpenApiTypes.BINARY,
required=True,
request={
"multipart/form-data": inline_serializer(
"SetIcon", fields={"file": FileField()}
)
],
},
responses={
200: OpenApiResponse(description="Success"),
400: OpenApiResponse(description="Bad request"),

View File

@ -7,9 +7,15 @@ from django.http.response import HttpResponseBadRequest, JsonResponse
from django.urls import reverse
from django.utils.translation import gettext as _
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
from drf_spectacular.utils import (
OpenApiParameter,
OpenApiResponse,
extend_schema,
inline_serializer,
)
from guardian.shortcuts import get_objects_for_user
from rest_framework.decorators import action
from rest_framework.fields import FileField
from rest_framework.parsers import MultiPartParser
from rest_framework.request import Request
from rest_framework.response import Response
@ -140,15 +146,11 @@ class FlowViewSet(ModelViewSet):
],
)
@extend_schema(
request=OpenApiTypes.NONE,
parameters=[
OpenApiParameter(
name="file",
location=OpenApiParameter.QUERY, # TODO: Form
type=OpenApiTypes.BINARY,
required=True,
request={
"multipart/form-data": inline_serializer(
"SetIcon", fields={"file": FileField()}
)
],
},
responses={
204: OpenApiResponse(description="Successfully imported flow"),
400: OpenApiResponse(description="Bad request"),
@ -267,15 +269,11 @@ class FlowViewSet(ModelViewSet):
@permission_required("authentik_flows.change_flow")
@extend_schema(
request=OpenApiTypes.NONE,
parameters=[
OpenApiParameter(
name="file",
location=OpenApiParameter.QUERY, # TODO: Form
type=OpenApiTypes.BINARY,
required=True,
request={
"multipart/form-data": inline_serializer(
"SetIcon", fields={"file": FileField()}
)
],
},
responses={
200: OpenApiResponse(description="Success"),
400: OpenApiResponse(description="Bad request"),

View File

@ -119,7 +119,9 @@ class SAMLProviderViewSet(ModelViewSet):
],
)
@extend_schema(
request=SAMLProviderImportSerializer(),
request={
"multipart/form-data": SAMLProviderImportSerializer,
},
responses={
204: OpenApiResponse(description="Successfully imported provider"),
400: OpenApiResponse(description="Bad request"),

View File

@ -1268,12 +1268,6 @@ paths:
operationId: core_applications_set_icon_create
description: Set application icon
parameters:
- in: query
name: file
schema:
type: string
format: binary
required: true
- in: path
name: slug
schema:
@ -1282,6 +1276,12 @@ paths:
required: true
tags:
- core
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/SetIconRequest'
required: true
security:
- authentik: []
- cookieAuth: []
@ -3948,12 +3948,6 @@ paths:
operationId: flows_instances_set_background_create
description: Set Flow background
parameters:
- in: query
name: file
schema:
type: string
format: binary
required: true
- in: path
name: slug
schema:
@ -3962,6 +3956,12 @@ paths:
required: true
tags:
- flows
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/SetIconRequest'
required: true
security:
- authentik: []
- cookieAuth: []
@ -4012,15 +4012,14 @@ paths:
post:
operationId: flows_instances_import_flow_create
description: Import flow from .akflow file
parameters:
- in: query
name: file
schema:
type: string
format: binary
required: true
tags:
- flows
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/SetIconRequest'
required: true
security:
- authentik: []
- cookieAuth: []
@ -23126,6 +23125,14 @@ components:
$ref: '#/components/schemas/User'
required:
- user
SetIconRequest:
type: object
properties:
file:
type: string
format: binary
required:
- file
SeverityEnum:
enum:
- notice