openapi-core icon indicating copy to clipboard operation
openapi-core copied to clipboard

Django integration is incompatible with Django REST Framework

Open jrtcppv opened this issue 4 years ago • 0 comments

The DjangoOpenAPIRequest class accesses request.body. This can cause issues related to reading the POST data twice, as described here:

https://github.com/encode/django-rest-framework/issues/2774

I have found that DRF accesses the request.body to read the CSRF token so the mitigation steps described in the issue above do not work. I have a branch of openapi-core here:

https://github.com/jrtcppv/openapi-core

That instead reads request.data and bypasses the deserialization of the request body. This is probably not the right solution as it is, but it might be possible to inspect the type of the request and do something different if it is not a normal django HttpRequest class, but rather the Request class provided by DRF.

I also tried subclassing DRF's APIView and overriding the intialize_request function, returning a subclass of Request that contained the parameters parsed by openapi-core. This also worked and might be an option if there needs to be a separate integration just for DRF.

Anyway, thanks for the library!

jrtcppv avatar Apr 24 '20 05:04 jrtcppv