diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index b2dbb342..d784ba62 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -329,7 +329,7 @@ def remove_drf_starter_files(): ) os.remove( os.path.join( - "{{cookiecutter.project_slug}}", "users", "tests", "test_swagger_ui.py" + "{{cookiecutter.project_slug}}", "users", "tests", "test_swagger.py" ) ) diff --git a/{{cookiecutter.project_slug}}/config/settings/base.py b/{{cookiecutter.project_slug}}/config/settings/base.py index ef3dfb9c..7165aa9d 100644 --- a/{{cookiecutter.project_slug}}/config/settings/base.py +++ b/{{cookiecutter.project_slug}}/config/settings/base.py @@ -333,6 +333,7 @@ REST_FRAMEWORK = { "rest_framework.authentication.TokenAuthentication", ), "DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",), + "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", } # django-cors-headers - https://github.com/adamchainz/django-cors-headers#setup diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_swagger_ui.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_swagger.py similarity index 70% rename from {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_swagger_ui.py rename to {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_swagger.py index b0c24d91..7f5b7584 100644 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_swagger_ui.py +++ b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/users/tests/test_swagger.py @@ -14,3 +14,9 @@ def test_swagger_ui_not_accessible_by_normal_user(client): url = reverse("api-docs") response = client.get(url) assert response.status_code == 403 + + +def test_api_schema_generated_successfully(admin_client): + url = reverse("api-schema") + response = admin_client.get(url) + assert response.status_code == 200