{"id":2012,"library":"drf-yasg","title":"Django REST Framework Yet Another Swagger Generator (drf-yasg)","description":"drf-yasg is a powerful tool for automated generation of real Swagger/OpenAPI 2.0 schemas directly from Django Rest Framework code. It simplifies API documentation by integrating Swagger UI and ReDoc into Django projects. The current version is 1.21.15, and the project maintains an active release cadence with frequent updates and bug fixes.","status":"active","version":"1.21.15","language":"en","source_language":"en","source_url":"https://github.com/axnsan12/drf-yasg","tags":["django","drf","rest-api","swagger","openapi","documentation","schema","api-generation"],"install":[{"cmd":"pip install drf-yasg","lang":"bash","label":"Install drf-yasg"}],"dependencies":[{"reason":"Core dependency for schema generation. While not a direct pip dependency, it's required for drf-yasg to function.","package":"djangorestframework","optional":false},{"reason":"Core framework dependency. While not a direct pip dependency, it's required for drf-yasg to function.","package":"Django","optional":false},{"reason":"Used for YAML schema generation, became a direct dependency in 1.21.6.","package":"PyYAML","optional":false},{"reason":"Optional. If using django-filter for API filtering, ensure compatibility with drf-yasg.","package":"django-filter","optional":true}],"imports":[{"symbol":"get_schema_view","correct":"from drf_yasg.views import get_schema_view"},{"symbol":"openapi","correct":"from drf_yasg import openapi"},{"symbol":"swagger_auto_schema","correct":"from drf_yasg.utils import swagger_auto_schema"},{"note":"While `url` might still work in some Django versions, `path` from `django.urls` is the modern and recommended approach for defining URL patterns in Django 2.0+.","wrong":"from django.conf.urls import url","symbol":"path","correct":"from django.urls import path"}],"quickstart":{"code":"from django.urls import path, re_path\nfrom rest_framework import permissions\nfrom drf_yasg.views import get_schema_view\nfrom drf_yasg import openapi\n\nschema_view = get_schema_view(\n   openapi.Info(\n      title=\"My API\",\n      default_version='v1',\n      description=\"Test description\",\n      terms_of_service=\"https://www.google.com/policies/terms/\",\n      contact=openapi.Contact(email=\"contact@snippets.local\"),\n      license=openapi.License(name=\"BSD License\"),\n   ),\n   public=True,\n   permission_classes=(permissions.AllowAny,),\n)\n\nurlpatterns = [\n   re_path(r'^swagger(?P<format>\\.json|\\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),\n   path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),\n   path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),\n]","lang":"python","description":"To quickly integrate drf-yasg, add 'drf_yasg' to your `INSTALLED_APPS` in `settings.py`. Then, include these URL patterns in your project's `urls.py`. This setup provides endpoints for the OpenAPI schema in JSON/YAML, the interactive Swagger UI, and the ReDoc documentation."},"warnings":[{"fix":"Review any client-side or external tools that strictly rely on the order of fields in the generated OpenAPI schema. Most OpenAPI consumers should not depend on field order, but if specific integrations break, consider custom schema generation or alternative validation.","message":"drf-yasg no longer guarantees preservation of schema field order due to a change from `OrderedDict` to native `dict` for schema generation.","severity":"breaking","affected_versions":"1.21.15 and higher"},{"fix":"Upgrade your Python environment to 3.7 or higher. The library officially supports Python 3.9+.","message":"Python 3.6 support has been officially dropped. Installations on Python 3.6 may encounter issues or lack new features.","severity":"deprecated","affected_versions":"1.21.5 and higher"},{"fix":"Ensure you are on drf-yasg 1.21.15 or newer, which includes fixes for Python 3.12 type parameter syntax. For older versions or other type hint issues, review your type hint usage or consider temporarily disabling `from __future__ import annotations` if possible.","message":"Issues with `from __future__ import annotations` and complex type hints, especially on Python 3.12, could lead to schema generation failures.","severity":"gotcha","affected_versions":"Pre-1.21.15 (especially with Python 3.12)"},{"fix":"Upgrade drf-yasg to 1.21.11 or higher, which includes a fix for `django-filter>=25` compatibility.","message":"When using `django-filter`, filter parameters might not appear in the generated Swagger UI if the drf-yasg version is too old.","severity":"gotcha","affected_versions":"Pre-1.21.11"},{"fix":"If you were using custom inspectors based on `CoreAPICompatInspector`, update your configuration to use `DrfAPICompatInspector` for improved compatibility and future-proofing.","message":"The `drf_yasg.inspectors.coreapi.CoreAPICompatInspector` has been replaced by `drf_yasg.inspectors.query.DrfAPICompatInspector`.","severity":"deprecated","affected_versions":"1.21.7 and higher"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}