Melvic Ybanez
Melvic Ybanez

Reputation: 2023

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.

Upvotes: 3

Views: 3582

Answers (1)

Haziq
Haziq

Reputation: 2288

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

Upvotes: 2

Related Questions