![]() ![]() Navigate to the config folder and change urls.py content to the following.įrom drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView ![]() For future purposes, you can easily break them down into individual views if needed, but using viewsets keeps the view logic nicely organized and very concise. Instead of writing multiple views, all common behavior is grouped into classes called ViewSets. Permission_classes = Ĭlass GroupViewSet (viewsets.ModelViewSet): """ĪPI endpoint that allows groups to be viewed or edited. serializers import UserSerializer, GroupSerializerĬlass UserViewSet (viewsets.ModelViewSet): """ĪPI endpoint that allows users to be viewed or edited. ![]() I’ll omit some details specific to the framework itself and if you feel lack of information for your own implementation, just explore the official site or ask a question in the comment section below.įirst things first, create the project directory and enter it.įrom import User, Groupįrom. We start with a couple of steps that are slightly different from the official DRF documentation. So, without further ado, be brave and follow me! Django REST framework Here I’m going to shorten this path for you by using quickstart example from the DRF documentation and sprinkle some customization on top of that to implement Swagger UI with version 3 of the specification. The solution I came up with is to create documentation with standard DRF tools (easiest way), then generate OpenAPI 2 schemas with drf-yasg (since it has a richer description of the process) and finally tune the configuration to use drf-spectacular. Well, the second-best option in this direction is drf-spectacular, but I couldn't figure out how to document my API just by following the provided examples (by the way I did it for the first time). The most popular option, in my opinion, was drf-yasg but it explicitly says that "drf-yasg is unlikely to soon, if ever, get support for OpenAPI 3.0". I saw how cool API documentation might look when I first discovered FastAPI and wanted to implement Swagger UI in my own app. I decided to add the Django REST framework into my toolchain and combine it with technologies like OAS 3.0. ![]() Since I’m still a relatively newbie programmer, I constantly struggle with different topics and almost always Googling helps. About use drf-spectacular to simplify creation of beautiful docs for your Django application according to the OpenAPI Specification version 3. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
May 2023
Categories |