mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-24 18:44:00 +03:00
Ignore derivations of BrowsableAPIRenderer in OpenAPI schema (#7497)
* Ignore derivations of BrowsableAPIRenderer in OpenAPI schema * Improve test_renderer_mapping test Co-authored-by: Carlton Gibson <carlton.gibson@noumenal.es>
This commit is contained in:
parent
eff97efa28
commit
0bdd537cc4
|
@ -595,7 +595,7 @@ class AutoSchema(ViewInspector):
|
|||
media_types = []
|
||||
for renderer in self.view.renderer_classes:
|
||||
# BrowsableAPIRenderer not relevant to OpenAPI spec
|
||||
if renderer == renderers.BrowsableAPIRenderer:
|
||||
if issubclass(renderer, renderers.BrowsableAPIRenderer):
|
||||
continue
|
||||
media_types.append(renderer.media_type)
|
||||
return media_types
|
||||
|
|
|
@ -10,7 +10,9 @@ from rest_framework import filters, generics, pagination, routers, serializers
|
|||
from rest_framework.authtoken.views import obtain_auth_token
|
||||
from rest_framework.compat import uritemplate
|
||||
from rest_framework.parsers import JSONParser, MultiPartParser
|
||||
from rest_framework.renderers import JSONRenderer, OpenAPIRenderer
|
||||
from rest_framework.renderers import (
|
||||
BaseRenderer, BrowsableAPIRenderer, JSONRenderer, OpenAPIRenderer
|
||||
)
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.schemas.openapi import AutoSchema, SchemaGenerator
|
||||
|
||||
|
@ -507,9 +509,16 @@ class TestOperationIntrospection(TestCase):
|
|||
path = '/{id}/'
|
||||
method = 'GET'
|
||||
|
||||
class CustomBrowsableAPIRenderer(BrowsableAPIRenderer):
|
||||
media_type = 'image/jpeg' # that's a wild API renderer
|
||||
|
||||
class TextRenderer(BaseRenderer):
|
||||
media_type = 'text/plain'
|
||||
format = 'text'
|
||||
|
||||
class View(generics.CreateAPIView):
|
||||
serializer_class = views.ExampleSerializer
|
||||
renderer_classes = [JSONRenderer]
|
||||
renderer_classes = [JSONRenderer, TextRenderer, BrowsableAPIRenderer, CustomBrowsableAPIRenderer]
|
||||
|
||||
view = create_view(
|
||||
View,
|
||||
|
@ -524,8 +533,8 @@ class TestOperationIntrospection(TestCase):
|
|||
# schema support is there
|
||||
success_response = responses['200']
|
||||
|
||||
assert len(success_response['content'].keys()) == 1
|
||||
assert 'application/json' in success_response['content']
|
||||
# Check that the API renderers aren't included, but custom renderers are
|
||||
assert set(success_response['content']) == {'application/json', 'text/plain'}
|
||||
|
||||
def test_openapi_yaml_rendering_without_aliases(self):
|
||||
renderer = OpenAPIRenderer()
|
||||
|
|
Loading…
Reference in New Issue
Block a user