Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Camelize query parameters #1002

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions drf_spectacular/contrib/djangorestframework_camel_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ def camelize_component(schema: dict, name: Optional[str] = None) -> dict:
if component_type == 'schemas':
camelize_component(component.schema)

for url_schema in result["paths"].values():
for method_schema in url_schema.values():
for parameter in method_schema.get("parameters", []):
parameter["name"] = camelize_str(parameter["name"])

# inplace modification of components also affect result dict, so regeneration is not necessary
return result
12 changes: 11 additions & 1 deletion tests/contrib/test_djangorestframework_camel_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from typing_extensions import TypedDict

from drf_spectacular.contrib.djangorestframework_camel_case import camelize_serializer_fields
from drf_spectacular.utils import extend_schema
from drf_spectacular.utils import extend_schema, OpenApiParameter
from tests import assert_schema, generate_schema


Expand Down Expand Up @@ -46,6 +46,16 @@ def get_field_nested_ignored(self) -> NestedObject: # type: ignore
pass # pragma: no cover


@extend_schema(
parameters=[
OpenApiParameter(
name="field_one",
description="filter_field",
required=False,
type=str,
),
]
)
class FakeViewset(mixins.ListModelMixin, viewsets.GenericViewSet):
serializer_class = FakeSerializer

Expand Down
12 changes: 12 additions & 0 deletions tests/contrib/test_djangorestframework_camel_case.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ paths:
/a_b_c/:
get:
operationId: a_b_c_list
parameters:
- in: query
name: fieldOne
schema:
type: string
description: filter_field
tags:
- a_b_c
security:
Expand All @@ -24,6 +30,12 @@ paths:
/a_b_c/home/:
get:
operationId: a_b_c_home_retrieve
parameters:
- in: query
name: fieldOne
schema:
type: string
description: filter_field
tags:
- a_b_c
security:
Expand Down