Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to document parameters in Django REST Swagger 2?

I used to specify the parameters using YAML Docstring, but they have now been deprecated. I have tried using coreapi.Field, as follows:

coreapi.Field(
    name='id',
    type='integer',
    required=True,
    location='query'
)

but it only works withViewSet.list, and not with, say, ViewSet.create. According to this report, this has been an on-going issue. The solution provided in the comments are quite hackish to me. I hope someone has already found (or came up with) a neater solution or alternative, perhaps a plugin or something.

like image 560
Melvic Ybanez Avatar asked Jan 30 '26 14:01

Melvic Ybanez


1 Answers

May be this is so late, but just for some help, you have to override the Schema generator to customize it, this doc explains django rest swagger 2 integration step by step: Django Rest Swagger 2 comprehensive documentation

you may think it a bit hacky but works perfectly fine.

EDIT: This documentation can be followed for function based views but if you already have class based views, you can directly use this package: https://drf-yasg.readthedocs.io/en/stable/readme.html

like image 162
Haziq Avatar answered Feb 02 '26 04:02

Haziq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!