django-rest-swagger icon indicating copy to clipboard operation
django-rest-swagger copied to clipboard

Foreign key field disappear in swagger docs after adding depth attribute in Serializer

Open abdulwahid24 opened this issue 8 years ago • 1 comments

Whenever I define the depth attribute than foreign key field from swagger docs in POST section gets disappears. That's seems strange because I required depth = 1 when I want related data in my GET request. So I can not remove this in order to get this related field parameter in POST section.

Here is the case.

Model:

from django.db import models
from django.conf import settings
# Create your models here.

User = settings.AUTH_USER_MODEL

class Todo(models.Model):
    user = models.ForeignKey(User)
    title = models.CharField("Title", max_length=255)
    completed = models.BooleanField("Completed")

Serializer without depth =1.

from rest_framework import serializers
from models import Todo

class TodoSerializer(serializers.HyperlinkedModelSerializer):
   class Meta:
       model = Todo

Swagger output: enter image description here

Now If I add depth = 1 than Swagger does not display related field. enter image description here

Let me know if anyone has any clue about this.

Thanks :)

abdulwahid24 avatar Jan 02 '16 12:01 abdulwahid24

@abdulwahid24 have you found a solution to this? I found your stack overflow and tried your solution there but am not able to submit a pk in my swagger post example

screen shot 2018-03-13 at 3 33 50 pm

robbykim avatar Mar 13 '18 19:03 robbykim