drf-yasg
Generate real Swagger/OpenAPI 2.0 schemas from Django REST Framework
Repository Health
Technical Analysis
drf-yasg (Yet Another Swagger Generator) produces real Swagger/OpenAPI 2.0 specifications directly from a Django REST Framework API. Instead of maintaining schema files by hand, it introspects your serializers, viewsets, and routers to emit an accurate spec, then serves interactive Swagger UI and ReDoc documentation out of the box.
It supports deep customization through decorators and inspectors, letting you override operation details, add parameters, and control the generated schema per view, making it a popular choice for teams that need trustworthy, browsable API docs for their DRF projects.
What You Get
- Automatic OpenAPI 2.0 schema generation from DRF serializers, viewsets, and routers
- Built-in Swagger UI and ReDoc endpoints for interactive, browsable documentation
- The swagger_auto_schema decorator to customize operations, parameters, and responses
- A pluggable inspector system for controlling how types and fields map to the schema
Common Use Cases
- Publishing interactive API docs for a Django REST Framework backend
- Generating a downloadable OpenAPI/Swagger spec for client code generation
- Customizing per-view schema details for accurate request/response documentation
Under The Hood
Architecture - drf-yasg hooks into DRF’s schema machinery via a custom OpenAPISchemaGenerator that walks the URL conf, resolves each view’s serializers, and builds an openapi.Swagger document from typed openapi.* objects. A layered inspector system (FieldInspector, SerializerInspector, PaginatorInspector) decides how serializer fields map to schema definitions, and get_schema_view produces cached JSON/YAML endpoints plus Swagger UI and ReDoc template views.
Tech Stack - Written primarily in Python (~65%) with bundled Swagger UI/ReDoc JavaScript assets (~32%). It depends on Django 4.0+, Django REST Framework 3.13+, and Python 3.10+, using packaging and inflection helpers, and is distributed as a standard Django app.
Code Quality - The project is mature with 68 releases, extensive CI across Django/DRF/Python matrices, Codecov coverage, and a large test suite under tests/. It follows a strict policy of supporting only the latest release. The inspector abstraction is well factored, though the breadth of OpenAPI edge cases makes the internals substantial.
API Design - Day-to-day usage is declarative: mount get_schema_view() URLs and annotate views with @swagger_auto_schema to refine operations. The decorator-plus-inspector model is powerful but the learning curve rises when overriding schema generation for complex serializers, which is where most of the documentation depth is spent.