How to document function-based views parameters?
I'm developing a REST API with Django 1.11 and Django REST Framework 3.7. I installed Django REST Swagger 2.1 to generate the documentation.
I'm using a function-based view like this:
from rest_framework.decorators import api_view, permission_classes @api_view(['POST']) @permission_classes((permissions.AllowAny,)) def jwt_auth(request, provider, format=None): """ View description here """ pass
As you can see, my view is recognized by Swagger and it has the correct description: "View description here".
- You can see the "Description" column is empty for the
- The POST parameters are not documented (obviously, because there is no way for Swagger to know them)
How can I write documentation for the URL and POST parameters of a function-based view, as well as the responses?
I tried YAML Docstrings but it seems it's for the old version (0.3.x) and it doesn't work with version 2.x.
You can use Schema of DjangoRestFrameWork. http://www.django-rest-framework.org/api-guide/schemas/
In your case, you can try the following.
from rest_framework.decorators import api_view, permission_classes, schema @api_view(['POST']) @permission_classes((permissions.AllowAny,)) @schema(custom_schema) def jwt_auth(request, provider, format=None): """ View description here """ pass
custom schema defintion
import coreapi, coreschema from rest_framework.schemas import AutoSchema, ManualSchema custom_schema = AutoSchema(manual_fields=[ coreapi.Field("username", required=True, location="form", type="string", description="username here"), coreapi.Field("password", required=True, location="form", type="string", description="password field" ]
Should do the trick. For more detailed info, visit the link I provided at the top. Basic POST and GET parameters should work in this way.
Documenting DRF function based views parameters · Issue #124 , I wanted to document a single api endpoint written as a function based view. It requires parameters sent as a form. Currently I don't see any There was a time that function-based generic views was a thing. They were created to address the common use cases. But the problem was that they were quite simple, and was very hard to extend or customize them (other than using configurations parameters). To address those issues, the class-based views was created.
Following this github issue, it seems it's not possible for the method-based views as you stated.
But I think this link can help you.
No way to document parameters · Issue #549 · marcgibbons/django , I still haven't found a way to do this on function based views. 81. @ By using view we can search, update, insert and delete the records from the table on which the view is created but whatever we are going to discuss will allow only the very first option “SEARCH” and we cannot use it to update, insert or delete records into the parent table. As I said,
use below code
@swagger_auto_schema(method='post', auto_schema=None) @api_view(['POST']) @permission_classes((permissions.AllowAny,)) def jwt_auth(request, provider, format=None): """ View description here """ pass
Django Rest Swagger 2 for API Documentation: - M Haziq, No way to document parameters of function based views; Less customizablity; No way to enforce permission classes; No handy way to exclude swagger view from and then when using the view select * from test_item_v where rev_id = v_rev_id; Another option is to create a PL/SQL table function with a parameter for the column you want to parameterize. Then execute the SQL statement using the parameter passed in. Finally, return the result set.
Examples, django-rest-swagger also supports function based views. set_price: omit_serializer: true parameters_strategy: form: replace parameters: - name: price type: A view function, or view for short, is a Python function that takes a Web request and returns a Web response. This response can be the HTML contents of a Web page, or a redirect, or a 404 error, or an XML document, or an image . . . or anything, really. The view itself contains whatever arbitrary logic is necessary to return that response.
Custom schema generation, for function based @api_view s, because the same view can handle multiple Note that the serializer_or_field parameter can accept either a subclass or an A Function-Based Framework for Stream Assessment and Restoration Projects. US Environmen-tal Protection Agency, Office of Wetlands, Oceans, and Watersheds, Washington, DC EPA 843-K-12-006. The findings and conclusions in this document are those of the authors and do not
Views, Django's class-based views are a welcome departure from the old-style views. In addition to the documentation here, the Classy Django REST Framework REST framework also allows you to work with regular function based views. Each of these decorators takes a single argument which must be a list or tuple of In this video you will learn how to create the base views from query with parameters in VDP using the Virtual Dataport Admin Tool.