Skip to content Skip to sidebar Skip to footer

How To Describe Parameters In Drf Docs

I'm using Django REST Framework v3.6 built-in interactive documentation django_rest_framework.documentation (not django-rest-swagger). Basically, I'm following the official documen

Solution 1:

Oh, I found it. Answering my own question.

DRF documentation isn't verbose on this matter (or I've missed the piece where it is), but it mentions rest_framework.schemas.SchemaGenerator class and it seems that this class really does all the introspection stuff. Fortunately, the source code is well-structured and easy to read.

Those path fields are generated by get_path_fields method (I found it by tracing the execution path: get_schemaget_linksget_link), and I found that descriptions come from model fields's help_text attribute.

So in my model I've specified:

classMyResource(models.Model):
    slug = models.CharField(unique=True, help_text=_("unique alphanumeric identifier"))
    ...

And it worked!

Solution 2:

One important thing was not still covered. It is true that a description comes from the help_text attribute, but this is not enough. I have found that the schema generator rely on view's queryset attribute to determine a model. So, keep in mind that you need define it even if you don't need it. For example in case of using APIView.

Post a Comment for "How To Describe Parameters In Drf Docs"