Skip to content

Commit

Permalink
Fix missing description for ManyRelatedField and tested for SlugField (
Browse files Browse the repository at this point in the history
…#895)

* Fix missing description for ManyRelatedField and tested for SlugField

* Don't use braces for lists

* differentiate outer/inner help_text & more compact impl

* adapt test

Co-authored-by: ruben <ruben.simons@web.de>
Co-authored-by: T. Franzel <tfranzel@users.noreply.github.com>
  • Loading branch information
StopMotionCuber and tfranzel authored Dec 13, 2022
1 parent 1a124ee commit 72a05cf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion drf_spectacular/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,9 @@ def _map_serializer_field(self, field, direction, bypass_extensions=False):
if isinstance(field, serializers.ManyRelatedField):
schema = self._map_serializer_field(field.child_relation, direction)
# remove hand-over initkwargs applying only to outer scope
schema.pop('description', None)
schema.pop('readOnly', None)
if meta.get('description') == schema.get('description'):
schema.pop('description', None)
return append_meta(build_array_type(schema), meta)

if isinstance(field, (serializers.PrimaryKeyRelatedField, serializers.SlugRelatedField)):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class Aux(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
field_foreign = models.ForeignKey('Aux', null=True, on_delete=models.CASCADE)
url = models.URLField(unique=True)
url = models.URLField(unique=True, help_text="URL identifier for Aux")


class AuxSerializer(serializers.ModelSerializer):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ components:
field_related_slug:
type: string
format: uri
description: URL identifier for Aux
readOnly: true
field_related_slug_many:
type: array
items:
type: string
format: uri
description: URL identifier for Aux
readOnly: true
field_related_string:
type: string
Expand Down Expand Up @@ -368,6 +370,7 @@ components:
url:
type: string
format: uri
description: URL identifier for Aux
maxLength: 200
field_foreign:
type: string
Expand Down

0 comments on commit 72a05cf

Please sign in to comment.