Skip to content

Commit

Permalink
Handling read_only/write_only fields on OpenAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
fao89 committed Nov 5, 2019
1 parent 2203fee commit b032fd0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/5622.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Handling `read_only` and `write_only` fields on OpenAPISchema.
16 changes: 16 additions & 0 deletions pulpcore/app/openapigenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,19 @@ def get_tags(self, operation_keys):
tags = [' '.join(operation_keys[:-1])]

return tags

def serializer_to_schema(self, serializer):
"""
Convert a serializer to an OpenAPI Schema.
Patch: https://github.com/axnsan12/drf-yasg/issues/70#issuecomment-485050813
"""

if self.method.lower() == "get":
new_fields = OrderedDict()
for field_name, field in serializer.fields.items():
if not field.write_only: # Removing write_only fields
new_fields[field_name] = field

serializer.fields = new_fields

return super().serializer_to_schema(serializer)
1 change: 0 additions & 1 deletion pulpcore/app/serializers/publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class PublicationSerializer(ModelSerializer):
label=_('Repository'),
queryset=models.Repository.objects.all(),
view_name='repositories-detail',
write_only=True
)

def validate(self, data):
Expand Down

0 comments on commit b032fd0

Please sign in to comment.