Skip to content

Format metadata field names correctly for OPTIONS request #713

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

Merged
merged 3 commits into from
Oct 3, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This release is not backwards compatible. For easy migration best upgrade first

* Avoid printing invalid pointer when api returns 404
* Avoid exception when using `ResourceIdentifierObjectSerializer` with unexisting primary key
* Format metadata field names correctly for OPTIONS request


## [2.8.0] - 2019-06-13
Expand Down
9 changes: 9 additions & 0 deletions example/tests/test_format_keys.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.utils import encoding
from rest_framework import status

from example.tests import TestBase

Expand Down Expand Up @@ -51,3 +52,11 @@ def test_camelization(self):
}

assert expected == response.json()


def test_options_format_field_names(db, client):
response = client.options(reverse('author-list'))
assert response.status_code == status.HTTP_200_OK
data = response.json()['data']
expected_keys = {'name', 'email', 'bio', 'entries', 'firstEntry', 'type', 'comments'}
assert expected_keys == data['actions']['POST'].keys()
4 changes: 2 additions & 2 deletions rest_framework_json_api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from rest_framework.settings import api_settings
from rest_framework.utils.field_mapping import ClassLookupDict

from rest_framework_json_api.utils import get_related_resource_type
from rest_framework_json_api.utils import format_value, get_related_resource_type


class JSONAPIMetadata(SimpleMetadata):
Expand Down Expand Up @@ -83,7 +83,7 @@ def get_serializer_info(self, serializer):
serializer.fields.pop(api_settings.URL_FIELD_NAME, None)

return OrderedDict([
(field_name, self.get_field_info(field))
(format_value(field_name), self.get_field_info(field))
for field_name, field in serializer.fields.items()
])

Expand Down