*: 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.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 OpenApiParameter, OpenApiResponse, extend_schema from drf_spectacular.utils import (
OpenApiParameter,
OpenApiResponse,
extend_schema,
inline_serializer,
)
from rest_framework.decorators import action 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.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
@ -155,15 +160,11 @@ class ApplicationViewSet(ModelViewSet):
@permission_required("authentik_core.change_application") @permission_required("authentik_core.change_application")
@extend_schema( @extend_schema(
request=OpenApiTypes.NONE, request={
parameters=[ "multipart/form-data": inline_serializer(
OpenApiParameter( "SetIcon", fields={"file": FileField()}
name="file",
location=OpenApiParameter.QUERY, # TODO: In Form
type=OpenApiTypes.BINARY,
required=True,
) )
], },
responses={ responses={
200: OpenApiResponse(description="Success"), 200: OpenApiResponse(description="Success"),
400: OpenApiResponse(description="Bad request"), 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.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 OpenApiParameter, OpenApiResponse, extend_schema from drf_spectacular.utils import (
OpenApiParameter,
OpenApiResponse,
extend_schema,
inline_serializer,
)
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 FileField
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
@ -140,15 +146,11 @@ class FlowViewSet(ModelViewSet):
], ],
) )
@extend_schema( @extend_schema(
request=OpenApiTypes.NONE, request={
parameters=[ "multipart/form-data": inline_serializer(
OpenApiParameter( "SetIcon", fields={"file": FileField()}
name="file",
location=OpenApiParameter.QUERY, # TODO: Form
type=OpenApiTypes.BINARY,
required=True,
) )
], },
responses={ responses={
204: OpenApiResponse(description="Successfully imported flow"), 204: OpenApiResponse(description="Successfully imported flow"),
400: OpenApiResponse(description="Bad request"), 400: OpenApiResponse(description="Bad request"),
@ -267,15 +269,11 @@ class FlowViewSet(ModelViewSet):
@permission_required("authentik_flows.change_flow") @permission_required("authentik_flows.change_flow")
@extend_schema( @extend_schema(
request=OpenApiTypes.NONE, request={
parameters=[ "multipart/form-data": inline_serializer(
OpenApiParameter( "SetIcon", fields={"file": FileField()}
name="file",
location=OpenApiParameter.QUERY, # TODO: Form
type=OpenApiTypes.BINARY,
required=True,
) )
], },
responses={ responses={
200: OpenApiResponse(description="Success"), 200: OpenApiResponse(description="Success"),
400: OpenApiResponse(description="Bad request"), 400: OpenApiResponse(description="Bad request"),

View file

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

View file

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