Problems with Django Swagger and JSON API

Usage django-rest-framework-json-apiI can create API endpoints that work as described in the documentation. Trying to provide API documentation with is django-rest-swaggernot so simple.

1: Swagger uses media_type = 'application/json'which is not supported in the JSON API. To get around this, I created a second rendering class ( renderer_classes), which subclasses the JSON API JSONRendererand forces the media type.

The endpoint now supports application/jsonboth application/vnd.api+json, and swagger is pleased to display the JSON API in the document structure. Recognizing that the generated curl requests do not have a standard JSON API header.

2: Swagger has the same problem with the parser. While work on Problem 1 does work, a secondary problem arises. Swagger provides a flat dictionary of field names that is not a JSON API and is ultimately requested by DRF.

Is it possible to understand the JSON API? Swagger does not currently work for PUT or POST.

djangorestframework-jsonapi==2.2.0
djangorestframework==3.5.4
Django==1.11.2
coreapi==2.3.1
python 3.6
+5
source share
1 answer

Answering my own question so that others can benefit from what they have learned. We have not found a solution to this problem, and we did not have time to contribute to this project. In general, the project also seems to be struggling, possibly because of people like us who are not helping ...

drf-yasg, . drf-yasg , .

, API JSON API, DRF, drf-yasg.

JSON API " ", , . .

Github Gist, , , , .

+1

Source: https://habr.com/ru/post/1685469/


All Articles