Adds available endpoint formats to the autogenerated schema

This commit is contained in:
Steven Sklar 2018-10-31 14:10:23 -04:00
parent 40da2a21ef
commit 5cb9d1a39e

View File

@ -212,6 +212,7 @@ class AutoSchema(ViewInspector):
fields += self.get_serializer_fields(path, method) fields += self.get_serializer_fields(path, method)
fields += self.get_pagination_fields(path, method) fields += self.get_pagination_fields(path, method)
fields += self.get_filter_fields(path, method) fields += self.get_filter_fields(path, method)
fields += self.get_renderer_fields(path, method)
manual_fields = self.get_manual_fields(path, method) manual_fields = self.get_manual_fields(path, method)
fields = self.update_fields(fields, manual_fields) fields = self.update_fields(fields, manual_fields)
@ -409,6 +410,26 @@ class AutoSchema(ViewInspector):
fields += filter_backend().get_schema_fields(self.view) fields += filter_backend().get_schema_fields(self.view)
return fields return fields
def get_renderer_fields(self, path, method):
view = self.view
renderers = api_settings.DEFAULT_RENDERER_CLASSES
if getattr(view, "renderer_classes", None) and view.renderer_classes:
renderers = view.renderer_classes
formats = [r.format for r in renderers if r.format]
field = coreapi.Field(
name="format",
location="query",
required=False,
schema=coreschema.Enum(title="Response format",
description="Specify a custom format for the response",
enum=formats)
)
return [field]
def get_manual_fields(self, path, method): def get_manual_fields(self, path, method):
return self._manual_fields return self._manual_fields