Search code examples
pythondjangodjango-rest-frameworkdocumentation-generation

Django restframework documenting Views


My questions is:

how can i fill the field Description? in tha table of Parameters in my docs page, here an example of my function and a screenshot how does it look

def delete(self, request, id_):
    repository = self.get_object(id_, owner=request.user)
    repository.delete()
    return Response(status=status.HTTP_204_NO_CONTENT, headers={"web_words": request.user.profile.web_words, "repo_words": request.user.profile.repo_words, "files": request.user.profile.files})

enter image description here


Solution

  • 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"))
        ...