Skip to content

Commit

Permalink
expose explode and style for OpenApiParameter #267
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Jan 21, 2021
1 parent cb3adcd commit e2e0c56
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drf_spectacular/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ def _process_override_parameters(self):
description=parameter.description,
enum=parameter.enum,
deprecated=parameter.deprecated,
style=parameter.style,
explode=parameter.explode,
examples=build_examples_list(parameter.examples),
))
elif is_serializer(parameter):
Expand Down
4 changes: 4 additions & 0 deletions drf_spectacular/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ def __init__(
description='',
enum=None,
deprecated=False,
style=None,
explode=None,
examples: Optional[List[OpenApiExample]] = None,
exclude=False,
):
Expand All @@ -120,6 +122,8 @@ def __init__(
self.description = description
self.enum = enum
self.deprecated = deprecated
self.style = style
self.explode = explode
self.examples = examples or []
self.exclude = exclude

Expand Down
23 changes: 23 additions & 0 deletions tests/test_regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,3 +1270,26 @@ class XViewset(viewsets.ModelViewSet):
prop = schema['components']['schemas']['M4']['properties']['multi']
assert prop['type'] == 'array'
assert prop['items']['$ref'] == '#/components/schemas/MultiEnum'


def test_explode_style_parameter_with_custom_schema(no_warnings):
@extend_schema(
parameters=[OpenApiParameter(
name='bbox',
type={'type': 'array', 'minItems': 4, 'maxItems': 6, 'items': {'type': 'number'}},
location=OpenApiParameter.QUERY,
required=False,
style='form',
explode=False,
)],
responses=OpenApiTypes.OBJECT,
)
@api_view(['GET'])
def view_func(request, format=None):
pass # pragma: no cover

schema = generate_schema('/x/', view_function=view_func)
parameter = schema['paths']['/x/']['get']['parameters'][0]
assert 'explode' in parameter
assert 'style' in parameter
assert parameter['schema']['type'] == 'array'

0 comments on commit e2e0c56

Please sign in to comment.