drf_openapi icon indicating copy to clipboard operation
drf_openapi copied to clipboard

Showing write_only field in GET method when it should show only POST method.

Open fernandolins opened this issue 8 years ago • 1 comments

  • DRF OpenAPI version: 1.0.0
  • Python version: 3.6.3
  • Operating System: OS X

Description

I have a serializer which has a write_only field and it is appearing to GET method.

models.py

class Template(models.Model):
    name = models.CharField(
        verbose_name=_('Name'), max_length=200, blank=False, null=False, unique=True,
        help_text=_('A string describing the template name.'))
    user = models.ForeignKey(
        User, verbose_name=_('User'), blank=True,
        null=True, related_name='templates')

serializers.py

class TemplateSerializer(serializers.ModelSerializer):

    class Meta:
        model = Template
        extra_kwargs = {'user': {'write_only': True}}
        fields = '__all__'

Current behavior

GET /api/templates

{
  "count": 0,
  "next": "string",
  "previous": "string",
  "results": [
    {
      "id": 0,
      "name": "string",
      "user": "string"
    }
  ]
}

Expected behavior

GET /api/templates

{
  "count": 0,
  "next": "string",
  "previous": "string",
  "results": [
    {
      "id": 0,
      "name": "string",
    }
  ]
}

This expected behavior is the real behavior of DRF but the drf_openapi hasn't this behavior.

Is there a way to drf_openapi to have the same behavior as drf?

fernandolins avatar Nov 17 '17 15:11 fernandolins

Yes, thanks for reporting. This should be fixed.

limdauto avatar Dec 17 '17 18:12 limdauto