Skip to content

Commit

Permalink
Provide implicit enum values for format
Browse files Browse the repository at this point in the history
Related to tfranzel#110
  • Loading branch information
jayvdb committed Jul 11, 2020
1 parent a4dfe49 commit b791891
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drf_spectacular/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ def dict_helper(parameters):
# override/add @extend_schema parameters
for key, parameter in override_parameters.items():
parameters[key] = parameter

format_param = parameters.get(('format', 'path'))
if format_param and 'enum' not in format_param['schema']:
format_param['enum'] = self.map_formats()

return sorted(parameters.values(), key=lambda p: p['name'])

def get_description(self):
Expand Down Expand Up @@ -732,6 +737,15 @@ def map_renderers(self):
media_types.append(renderer.media_type)
return media_types

def map_formats(self):
formats = set()
for renderer in self.view.renderer_classes:
# BrowsableAPIRenderer not relevant to OpenAPI spec
if renderer == renderers.BrowsableAPIRenderer:
continue
formats.add(renderer.format)
return list(formats)

def _get_serializer(self):
view = self.view
try:
Expand Down

0 comments on commit b791891

Please sign in to comment.