Sane and flexible OpenAPI 3.0 schema generation for Django REST framework.
Questions tagged [drf-spectacular]
98 questions
                    
                    9
                    
            votes
                
                1 answer
            
        Using FileField/ImageField with Swagger UI and drf-spectacular
I have a Django REST Framework project which uses a ModelViewSet to create APIs for a model containing a FileField.
I've shared a full example of a Django project demonstrating this issue here. But to summarise the key components:
models.py
from…
        
        LondonAppDev
        
- 8,501
 - 8
 - 60
 - 87
 
                    8
                    
            votes
                
                4 answers
            
        Django drf-spectacular - Can you exclude specific paths?
We have a bunch of api's with different versions in urls.py, eg
api/v1
api/v2
api/v3
.  We want to implement swagger with drf-spectacular, but we only want to expose api/v3 endpoints.
Is there a way to do this?  I cannot make sense of the…
        
        Gareth
        
- 89
 - 1
 - 3
 
                    7
                    
            votes
                
                1 answer
            
        AttributeError: module 'rest_framework.serializers' has no attribute 'NullBooleanField'
After upgrading djangorestframework from djangorestframework==3.13.1 to djangorestframework==3.14.0 the code
from rest_framework.serializers import NullBooleanField
Throws
AttributeError: module 'rest_framework.serializers' has no attribute…
        
        Martin Thoma
        
- 124,992
 - 159
 - 614
 - 958
 
                    6
                    
            votes
                
                1 answer
            
        drf-spectacular: Specify empty payload using @extend_schema
Consider that I have a simple view as,
# serializers.py
class EmptyPayloadResponseSerializer(serializers.Serializer):
    detail = serializers.CharField()
# views.py
from rest_framework.views import APIView
from rest_framework.response import…
        
        JPG
        
- 82,442
 - 19
 - 127
 - 206
 
                    5
                    
            votes
                
                3 answers
            
        How to generate a schema for a custom pagination in django rfw with drf-spectacular?
I am struggling to properly generate the schema for my custom pagination in django rest framework.
I am using drf-spectacular for the schema generation. My custom pagination includes a total-pages field which does not come with djangos…
        
        Anti
        
- 101
 - 5
 
                    5
                    
            votes
                
                1 answer
            
        DRF spectacular not discovering custom auth extension classes
when extending a new Token Authentication class from rest_framework_simplejwt.authentication.JWTAuthentication drf-spectacular swagger-ui authorize button disappears and there is no way to add token bearer, I guess when you subclass it goes…
        
        YosSaL
        
- 667
 - 6
 - 15
 
                    4
                    
            votes
                
                0 answers
            
        drf-spectacular define request content type as 'application/x-www-form-urlencoded'
In drf-spectacular swagger, post method have 3 content types as below
application/json
application/x-www-form-urlencoded
multipart/form-data
Is there anyway to make "application/x-www-form-urlencoded" as default content type for my post…
        
        subba Raidu
        
- 41
 - 3
 
                    4
                    
            votes
                
                1 answer
            
        How to document individual actions of a ViewSet using `drf-spectacular`?
Using DRF's built-in way of documenting the API, I was able to write a docstring like the following and each action was documented by its corresponding line:
"""
list:    The list action returns all available objects.
retrieve:The retrieve action…
        
        finngu
        
- 457
 - 4
 - 23
 
                    4
                    
            votes
                
                2 answers
            
        drf spectacular not showing query params in swagger ui
I have generic ListAPIView with following list request function. Here category is a query parameter. I am trying to achieve such that the swagger ui also shows the query parameter in the swagger ui doc. How to achieve this? I have the following…
        
        Ashin Shakya
        
- 690
 - 6
 - 9
 
                    3
                    
            votes
                
                1 answer
            
        How to set required fields in PATCH API in Swagger UI
I'm using drf-spectacular and here's code in settings.py
SPECTACULAR_SETTINGS = {
    'TITLE': 'TITLE',
    'VERSION': '1.0.0',
    'SCHEMA_PATH_PREFIX_TRIM': True,
    'PREPROCESSING_HOOKS': ["custom.url_remover.preprocessing_filter_spec"],  
}
in…
        
        Umang Bhadja
        
- 101
 - 6
 
                    3
                    
            votes
                
                1 answer
            
        Is it possible to define examples for individual `Model` or `Serializer` fields with DRF-Spectacular?
I use DRF-Spectacular to generate the OpenAPI specification for my DRF-based API. So far, I do not add examples but instead rely on SwaggerUI to show examples based on the type and regex patterns.
However, in same cases, I would like to add examples…
        
        Aecturus
        
- 163
 - 1
 - 4
 
                    3
                    
            votes
                
                3 answers
            
        drf-spectacular: Add OpenApiResponse to a serializer-less function-based view
So,
I'm documenting the following piece of code using drf-spectacular:
from rest_framework import response
from rest_framework.decorators import api_view, permission_classes
from rest_framework.response import Response
from…
        
        Rui Oliveira
        
- 606
 - 8
 - 20
 
                    3
                    
            votes
                
                2 answers
            
        Django drf-spectacular How to split api descriptions for public and private use?
I want to make 2 different documentations. One is for public with few api methods and no authz. Another one is for private usage with all api methods and only for authorized users.
        
        hjortron
        
- 329
 - 1
 - 13
 
                    3
                    
            votes
                
                2 answers
            
        Define component schema with drf-spectacular for django API
I am using drf-spectacular to generate an OpenAPI schema for django. As I am not using serializers, I am defining everything in the extend_schema decorator. Now my question is, if it is possible to manually define a component schema.
Here is an…
        
        elya5
        
- 2,236
 - 1
 - 11
 - 27
 
                    3
                    
            votes
                
                1 answer
            
        Using extend_schema_field for custom field
I created a custom field named PictureField which creates thumbnails with uploaded images and I used it in my User model
User model:
class User(AbstractBaseUser):
    profile_image = PictureField(make_thumbnail=True)
My PictureField, gets an image…
        
        PokerFaCe
        
- 329
 - 2
 - 11