I use Django, the DRF, drf-yasg and Swagger Codegen to automatically build TypeScript code to access my REST API.
In the Django backend I added a path to be served with the DRF:
rest_router = routers.DefaultRouter()
rest_router.register(r'source/(?P<source_id>[0-9]+)/document', DocumentViewSet)
DocumentViewSet
is a DRF ModelViewSet.
As you can see, the source_id
parameter is of numeric type. However, the resulting generated API description defines the source_id
parameter as type String.
Obviously the numeric regexp in the path setting is not enough so I guess I need some type annotation in the DocumentViewSet
class? I tried the following code, but this showed no effect:
@swagger_auto_schema(
manual_parameters=[
openapi.Parameter(name="source_id",
required=True,
type="integer",
in_="path",
description="Source reference",
),
],
)
class DocumentViewSet(viewsets.ModelViewSet):
serializer_class = rest_serializers.DocumentSerializer
queryset = models.Document.objects.all().order_by('id')
How can I tell drf-yasg to set the source_id
parameter to type Integer?