*: linting pass, rename from swagger to schema

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-16 15:14:02 +02:00
parent 4fb71a6bdd
commit ef9f08553c
10 changed files with 71 additions and 82 deletions

View File

@ -59,10 +59,13 @@ class AuthentikTokenAuthentication(BaseAuthentication):
class TokenSchema(OpenApiAuthenticationExtension): class TokenSchema(OpenApiAuthenticationExtension):
"""Auth schema"""
target_class = AuthentikTokenAuthentication target_class = AuthentikTokenAuthentication
name = "authentik" name = "authentik"
def get_security_definition(self, auto_schema): def get_security_definition(self, auto_schema):
"""Auth schema"""
return { return {
"type": "apiKey", "type": "apiKey",
"in": "header", "in": "header",

View File

@ -0,0 +1,22 @@
"""Schema generation tests"""
from django.urls import reverse
from rest_framework.test import APITestCase
from yaml import safe_load
class TestSchemaGeneration(APITestCase):
"""Generic admin tests"""
def test_schema(self):
"""Test generation"""
response = self.client.get(
reverse("authentik_api:schema"),
)
self.assertTrue(safe_load(response.content.decode()))
def test_browser(self):
"""Test API Browser"""
response = self.client.get(
reverse("authentik_api:schema-browser"),
)
self.assertEqual(response.status_code, 200)

View File

@ -1,31 +0,0 @@
"""Swagger generation tests"""
from json import loads
from django.urls import reverse
from rest_framework.test import APITestCase
from yaml import safe_load
class TestSwaggerGeneration(APITestCase):
"""Generic admin tests"""
def test_yaml(self):
"""Test YAML generation"""
response = self.client.get(
reverse("authentik_api:schema-json", kwargs={"format": ".yaml"}),
)
self.assertTrue(safe_load(response.content.decode()))
def test_json(self):
"""Test JSON generation"""
response = self.client.get(
reverse("authentik_api:schema-json", kwargs={"format": ".json"}),
)
self.assertTrue(loads(response.content.decode()))
def test_browser(self):
"""Test API Browser"""
response = self.client.get(
reverse("authentik_api:swagger"),
)
self.assertEqual(response.status_code, 200)

View File

@ -1,8 +1,7 @@
"""api v2 urls""" """api v2 urls"""
from django.urls import path, re_path from django.urls import path
from drf_spectacular.views import SpectacularAPIView from drf_spectacular.views import SpectacularAPIView
from rest_framework import routers from rest_framework import routers
from rest_framework.permissions import AllowAny
from authentik.admin.api.meta import AppsViewSet from authentik.admin.api.meta import AppsViewSet
from authentik.admin.api.metrics import AdministrationMetricsViewSet from authentik.admin.api.metrics import AdministrationMetricsViewSet
@ -10,7 +9,7 @@ from authentik.admin.api.tasks import TaskViewSet
from authentik.admin.api.version import VersionViewSet from authentik.admin.api.version import VersionViewSet
from authentik.admin.api.workers import WorkerViewSet from authentik.admin.api.workers import WorkerViewSet
from authentik.api.v2.config import ConfigsViewSet from authentik.api.v2.config import ConfigsViewSet
from authentik.api.views import SwaggerView from authentik.api.views import APIBrowserView
from authentik.core.api.applications import ApplicationViewSet from authentik.core.api.applications import ApplicationViewSet
from authentik.core.api.groups import GroupViewSet from authentik.core.api.groups import GroupViewSet
from authentik.core.api.propertymappings import PropertyMappingViewSet from authentik.core.api.propertymappings import PropertyMappingViewSet
@ -197,7 +196,7 @@ router.register("policies/dummy", DummyPolicyViewSet)
urlpatterns = ( urlpatterns = (
[ [
path("", SwaggerView.as_view(), name="swagger"), path("", APIBrowserView.as_view(), name="schema-browser"),
] ]
+ router.urls + router.urls
+ [ + [

View File

@ -5,10 +5,10 @@ from django.urls import reverse
from django.views.generic import TemplateView from django.views.generic import TemplateView
class SwaggerView(TemplateView): class APIBrowserView(TemplateView):
"""Show swagger view based on rapi-doc""" """Show browser view based on rapi-doc"""
template_name = "api/swagger.html" template_name = "api/browser.html"
def get_context_data(self, **kwargs: Any) -> dict[str, Any]: def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
path = self.request.build_absolute_uri( path = self.request.build_absolute_uri(

View File

@ -1,5 +1,4 @@
"""OAuth2Provider API Views""" """OAuth2Provider API Views"""
from django.db.models.base import Model
from django.urls import reverse 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

View File

@ -6,12 +6,7 @@ from django.http.response import HttpResponse
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
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,
extend_schema_field,
)
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.fields import CharField, FileField, ReadOnlyField from rest_framework.fields import CharField, FileField, ReadOnlyField
from rest_framework.parsers import MultiPartParser from rest_framework.parsers import MultiPartParser

View File

@ -152,7 +152,9 @@ SPECTACULAR_SETTINGS = {
"url": "https://github.com/goauthentik/authentik/blob/master/LICENSE", "url": "https://github.com/goauthentik/authentik/blob/master/LICENSE",
}, },
"ENUM_NAME_OVERRIDES": { "ENUM_NAME_OVERRIDES": {
"ChallengeChoices": "authentik.flows.challenge.ChallengeTypes" "ChallengeChoices": "authentik.flows.challenge.ChallengeTypes",
"FlowDesignationEnum": "authentik.flows.models.FlowDesignation",
"PolicyEngineMode": "authentik.policies.models.PolicyEngineMode",
}, },
"ENUM_ADD_EXPLICIT_BLANK_NULL_CHOICE": False, "ENUM_ADD_EXPLICIT_BLANK_NULL_CHOICE": False,
} }

View File

@ -13457,7 +13457,7 @@ components:
meta_publisher: meta_publisher:
type: string type: string
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
required: required:
- launch_url - launch_url
- name - name
@ -13492,7 +13492,7 @@ components:
meta_publisher: meta_publisher:
type: string type: string
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
required: required:
- name - name
- slug - slug
@ -14073,16 +14073,6 @@ components:
$ref: '#/components/schemas/FlowRequest' $ref: '#/components/schemas/FlowRequest'
required: required:
- name - name
DesignationEnum:
enum:
- authentication
- authorization
- invalidation
- enrollment
- unenrollment
- recovery
- stage_configuration
type: string
DeviceClassesEnum: DeviceClassesEnum:
enum: enum:
- static - static
@ -14658,7 +14648,7 @@ components:
description: Shown as the Title in Flow pages. description: Shown as the Title in Flow pages.
designation: designation:
allOf: allOf:
- $ref: '#/components/schemas/DesignationEnum' - $ref: '#/components/schemas/FlowDesignationEnum'
description: Decides what this Flow is used for. For example, the Authentication description: Decides what this Flow is used for. For example, the Authentication
flow is redirect to when an un-authenticated user visits authentik. flow is redirect to when an un-authenticated user visits authentik.
background: background:
@ -14681,7 +14671,7 @@ components:
type: integer type: integer
readOnly: true readOnly: true
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
required: required:
- cache_count - cache_count
- designation - designation
@ -14692,6 +14682,16 @@ components:
- slug - slug
- stages - stages
- title - title
FlowDesignationEnum:
enum:
- authentication
- authorization
- invalidation
- enrollment
- unenrollment
- recovery
- stage_configuration
type: string
FlowDiagram: FlowDiagram:
type: object type: object
description: response of the flow's diagram action description: response of the flow's diagram action
@ -14717,7 +14717,7 @@ components:
description: Shown as the Title in Flow pages. description: Shown as the Title in Flow pages.
designation: designation:
allOf: allOf:
- $ref: '#/components/schemas/DesignationEnum' - $ref: '#/components/schemas/FlowDesignationEnum'
description: Decides what this Flow is used for. For example, the Authentication description: Decides what this Flow is used for. For example, the Authentication
flow is redirect to when an un-authenticated user visits authentik. flow is redirect to when an un-authenticated user visits authentik.
background: background:
@ -14725,7 +14725,7 @@ components:
format: binary format: binary
description: Background shown during execution description: Background shown during execution
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
required: required:
- designation - designation
- name - name
@ -14766,7 +14766,7 @@ components:
maximum: 2147483647 maximum: 2147483647
minimum: -2147483648 minimum: -2147483648
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
required: required:
- order - order
- pk - pk
@ -14796,7 +14796,7 @@ components:
maximum: 2147483647 maximum: 2147483647
minimum: -2147483648 minimum: -2147483648
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
required: required:
- order - order
- stage - stage
@ -15429,7 +15429,7 @@ components:
type: string type: string
readOnly: true readOnly: true
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'
@ -15523,7 +15523,7 @@ components:
nullable: true nullable: true
description: Flow to use when enrolling new users. description: Flow to use when enrolling new users.
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'
@ -16020,7 +16020,7 @@ components:
type: string type: string
readOnly: true readOnly: true
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'
@ -16095,7 +16095,7 @@ components:
nullable: true nullable: true
description: Flow to use when enrolling new users. description: Flow to use when enrolling new users.
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'
@ -18228,7 +18228,7 @@ components:
meta_publisher: meta_publisher:
type: string type: string
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
PatchedAuthenticateWebAuthnStageRequest: PatchedAuthenticateWebAuthnStageRequest:
type: object type: object
description: AuthenticateWebAuthnStage Serializer description: AuthenticateWebAuthnStage Serializer
@ -18526,7 +18526,7 @@ components:
description: Shown as the Title in Flow pages. description: Shown as the Title in Flow pages.
designation: designation:
allOf: allOf:
- $ref: '#/components/schemas/DesignationEnum' - $ref: '#/components/schemas/FlowDesignationEnum'
description: Decides what this Flow is used for. For example, the Authentication description: Decides what this Flow is used for. For example, the Authentication
flow is redirect to when an un-authenticated user visits authentik. flow is redirect to when an un-authenticated user visits authentik.
background: background:
@ -18534,7 +18534,7 @@ components:
format: binary format: binary
description: Background shown during execution description: Background shown during execution
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
PatchedFlowStageBindingRequest: PatchedFlowStageBindingRequest:
type: object type: object
description: FlowStageBinding Serializer description: FlowStageBinding Serializer
@ -18557,7 +18557,7 @@ components:
maximum: 2147483647 maximum: 2147483647
minimum: -2147483648 minimum: -2147483648
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
PatchedGroupRequest: PatchedGroupRequest:
type: object type: object
description: Group Serializer description: Group Serializer
@ -18755,7 +18755,7 @@ components:
nullable: true nullable: true
description: Flow to use when enrolling new users. description: Flow to use when enrolling new users.
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'
@ -18951,7 +18951,7 @@ components:
nullable: true nullable: true
description: Flow to use when enrolling new users. description: Flow to use when enrolling new users.
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'
@ -19111,7 +19111,7 @@ components:
nullable: true nullable: true
description: Flow to use when enrolling new users. description: Flow to use when enrolling new users.
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'
@ -19391,7 +19391,7 @@ components:
nullable: true nullable: true
description: Flow to use when enrolling new users. description: Flow to use when enrolling new users.
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'
@ -19655,7 +19655,7 @@ components:
type: string type: string
readOnly: true readOnly: true
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'
@ -19708,7 +19708,7 @@ components:
nullable: true nullable: true
description: Flow to use when enrolling new users. description: Flow to use when enrolling new users.
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'
@ -19859,7 +19859,7 @@ components:
required: required:
- order - order
- target - target
PolicyEngineModeEnum: PolicyEngineMode:
enum: enum:
- all - all
- any - any
@ -20747,7 +20747,7 @@ components:
type: string type: string
readOnly: true readOnly: true
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'
@ -20833,7 +20833,7 @@ components:
nullable: true nullable: true
description: Flow to use when enrolling new users. description: Flow to use when enrolling new users.
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'
@ -21070,7 +21070,7 @@ components:
type: string type: string
readOnly: true readOnly: true
policy_engine_mode: policy_engine_mode:
$ref: '#/components/schemas/PolicyEngineModeEnum' $ref: '#/components/schemas/PolicyEngineMode'
user_matching_mode: user_matching_mode:
allOf: allOf:
- $ref: '#/components/schemas/UserMatchingModeEnum' - $ref: '#/components/schemas/UserMatchingModeEnum'