[Fixed]-How to describe parameters in DRF Docs

19👍

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:

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

And it worked!

5👍

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.

Leave a comment