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

Expose exclude_fields in the REST API schema #316

Merged
merged 1 commit 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/5519.feature
@@ -0,0 +1 @@
Expose `exclude_fields` the api schema and bindings to allow users to filter out fields.
1 change: 1 addition & 0 deletions CHANGES/5519.removal
@@ -0,0 +1 @@
Renamed `fields!` to `exclude_fields` since exclamation mark is a special char in many languages.
8 changes: 8 additions & 0 deletions pulpcore/app/openapigenerator.py
Expand Up @@ -274,6 +274,14 @@ def get_operation(self, operation_keys):
type="string",
)
query.append(fields_paramenter)
not_fields_paramenter = Parameter(
name="exclude_fields",
in_="query",
description="A list of fields to exclude from the response.",
required=False,
type="string",
)
query.append(not_fields_paramenter)
parameters = body + query
parameters = filter_none(parameters)
parameters = self.add_manual_parameters(parameters)
Expand Down
3 changes: 3 additions & 0 deletions pulpcore/app/serializers/base.py
Expand Up @@ -31,6 +31,9 @@ class ModelSerializer(QueryFieldsMixin, serializers.HyperlinkedModelSerializer):
This ensures that all Serializers provide values for the '_href` field.
"""

# default is 'fields!' which doesn't work in the bindings for some langs
exclude_arg_name = "exclude_fields"

class Meta:
fields = ('_href', '_created')

Expand Down
2 changes: 1 addition & 1 deletion pulpcore/tests/functional/api/test_crud_repos.py
Expand Up @@ -76,7 +76,7 @@ def test_02_read_repo_with_specific_fields(self):
def test_02_read_repo_without_specific_fields(self):
"""Read a repo by its href excluding specific fields."""
# requests doesn't allow the use of != in parameters.
url = '{}?fields!=created,name'.format(self.repo['_href'])
url = '{}?exclude_fields=created,name'.format(self.repo['_href'])
repo = self.client.get(url)
response_fields = repo.keys()
self.assertNotIn('created', response_fields)
Expand Down
2 changes: 1 addition & 1 deletion pulpcore/tests/functional/api/test_tasks.py
Expand Up @@ -66,7 +66,7 @@ def test_02_read_href_with_specific_fields(self):
def test_02_read_task_without_specific_fields(self):
"""Read a task by its href excluding specific fields."""
# requests doesn't allow the use of != in parameters.
url = '{}?fields!=state'.format(self.task['_href'])
url = '{}?exclude_fields=state'.format(self.task['_href'])
task = self.client.get(url)
self.assertNotIn('state', task.keys())

Expand Down
Expand Up @@ -85,7 +85,7 @@ def test_02_read_publication_with_specific_fields(self):
def test_02_read_publication_without_specific_fields(self):
"""Read a publication by its href excluding specific fields."""
# requests doesn't allow the use of != in parameters.
url = '{}?fields!=distributions'.format(self.publication['_href'])
url = '{}?exclude_fields=distributions'.format(self.publication['_href'])
publication = self.client.get(url)
self.assertNotIn('distributions', publication.keys())

Expand Down