Skip to content

Commit 1a8f30b

Browse files
jokiefersliverc
authored andcommitted
fixes attribute naming in filter backend and AutoSchema
1 parent c016b8b commit 1a8f30b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ any parts of the framework not mentioned in the documentation should generally b
1515
* Fixed invalid relationship pointer in error objects when field naming formatting is used.
1616
* Properly resolved related resource type when nested source field is defined.
1717
* Prevented overwriting of pointer in custom error object
18+
* Adhered to field naming format setting when generating OpenAPI schema.
1819

1920
### Added
2021

rest_framework_json_api/django_filters/backends.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from rest_framework.exceptions import ValidationError
55
from rest_framework.settings import api_settings
66

7-
from rest_framework_json_api.utils import undo_format_field_name
7+
from rest_framework_json_api.utils import format_field_names, undo_format_field_name
88

99

1010
class DjangoFilterBackend(DjangoFilterBackend):
@@ -139,5 +139,6 @@ def get_schema_operation_parameters(self, view):
139139
result = super().get_schema_operation_parameters(view)
140140
for res in result:
141141
if "name" in res:
142-
res["name"] = "filter[{}]".format(res["name"]).replace("__", ".")
142+
name = format_field_names(res["name"].replace("__", "."))
143+
res["name"] = "filter[{}]".format(name)
143144
return result

rest_framework_json_api/schemas/openapi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,8 @@ def map_serializer(self, serializer):
667667
continue
668668

669669
if field.required:
670-
required.append(field.field_name)
671-
670+
required.append(format_field_name(field.field_name))
671+
672672
schema = self.map_field(field)
673673
if field.read_only:
674674
schema["readOnly"] = True
@@ -681,6 +681,9 @@ def map_serializer(self, serializer):
681681
if field.help_text:
682682
# Ensure django gettext_lazy is rendered correctly
683683
schema["description"] = str(field.help_text)
684+
if field.label:
685+
# Ensure django gettext_lazy is rendered correctly
686+
schema["title"] = str(field.label)
684687
self.map_field_validators(field, schema)
685688

686689
attributes[format_field_name(field.field_name)] = schema

0 commit comments

Comments
 (0)