diff --git a/backend/backend/settings.py b/backend/backend/settings.py index 465665a..82f2e67 100644 --- a/backend/backend/settings.py +++ b/backend/backend/settings.py @@ -63,6 +63,7 @@ SWAGGER_SETTINGS = { }, 'USE_SESSION_AUTH': False, 'JSON_EDITOR': True, + 'DEFAULT_INFO': 'backend.urls.openapi_info', } MIDDLEWARE = [ diff --git a/backend/backend/urls.py b/backend/backend/urls.py index 1cea34e..ab9c3a2 100644 --- a/backend/backend/urls.py +++ b/backend/backend/urls.py @@ -18,14 +18,16 @@ from django.urls import path, include from drf_yasg import openapi from drf_yasg.views import get_schema_view +openapi_info = openapi.Info( + title="Toolshed API", + default_version='v1', + description="API for all things …", +) + schema_view = get_schema_view( - openapi.Info( - title="Toolshed API", - default_version='v1', - description="API for all things …", - ), + openapi_info, public=True, - permission_classes=[] + permission_classes=[], ) urlpatterns = [ diff --git a/backend/hostadmin/serializers.py b/backend/hostadmin/serializers.py index 201cff7..72bacba 100644 --- a/backend/hostadmin/serializers.py +++ b/backend/hostadmin/serializers.py @@ -23,6 +23,7 @@ class CategorySerializer(serializers.ModelSerializer): model = Category fields = ['name', 'description', 'parent', 'origin'] read_only_fields = ['origin'] + ref_name = 'HostAdminCategory' class PropertySerializer(serializers.ModelSerializer): @@ -33,6 +34,7 @@ class PropertySerializer(serializers.ModelSerializer): fields = ['name', 'description', 'category', 'unit_symbol', 'unit_name', 'unit_name_plural', 'base2_prefix', 'dimensions', 'origin'] read_only_fields = ['origin'] + ref_name = 'HostAdminProperty' class TagSerializer(serializers.ModelSerializer): @@ -42,3 +44,4 @@ class TagSerializer(serializers.ModelSerializer): model = Tag fields = ['name', 'description', 'category', 'origin'] read_only_fields = ['origin'] + ref_name = 'HostAdminTag' diff --git a/backend/toolshed/tests/test_docs.py b/backend/toolshed/tests/test_docs.py new file mode 100644 index 0000000..c9bafaf --- /dev/null +++ b/backend/toolshed/tests/test_docs.py @@ -0,0 +1,21 @@ +from django.test import Client +from authentication.tests import UserTestMixin, SignatureAuthClient, ToolshedTestCase +from backend import settings +from toolshed.tests import CategoryTestMixin, TagTestMixin, PropertyTestMixin + +anonymous_client = Client() +client = SignatureAuthClient() + + +class OpenapiTestCase(UserTestMixin, CategoryTestMixin, TagTestMixin, PropertyTestMixin, ToolshedTestCase): + + def setUp(self): + super().setUp() + self.prepare_users() + + def test_docs_anonymous(self): + response = anonymous_client.get('/docs/?format=openapi') + self.assertEqual(response.status_code, 200) + self.assertTrue('swagger' in response.json()) + self.assertTrue('info' in response.json()) +