drf-yasgでForeignKeyのフィールドのパラメータにSerializerを反映させる

# 課題
* django-rest-framework を使ったWeb APIのドキュメントを、[drf-yasg](https://github.com/axnsan12/drf-yasg)で生成しようとしたところ、modelで`ForeignKey`として定義していたパラメータの情報が正しく表示されなかった

# 環境
* python3.6.5
* djangorestframework==3.9.1
* drf-yasg==1.13.0

# サンプルコード
```python
from django.db import models

# Create your models here.


class Article(models.Model):
    title = models.CharField(max_length=100, blank=True, null=True)
    contents_text = models.TextField(blank=True, null=True)
    pubdate = models.DateTimeField(auto_now_add=True)


class User(models.Model):
    name = models.CharField(max_length=100, blank=True, null=True)


class Comment(models.Model):
    target_article = models.ForeignKey(Article, on_delete=models.SET_NULL, null=True, related_name='comments')
    comment = models.TextField(blank=True, null=True)
    pubdate = models.DateTimeField(auto_now_add=True)
    user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
```

```python
from rest_framework.serializers import ModelSerializer
from .models import Article, Comment, User


class UserSerializer(ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'


class CommentSerializer(ModelSerializer):
    class Meta:
        model = Comment
        fields = [
            'id',
            'target_article',
            'comment',
            'pubdate',
            'user',
        ]


class ArticleSerializer(ModelSerializer):
    class Meta:
        model = Article
        fields = [
            'id',
            'title',
            'contents_text',
            'pubdate',
            'comments',
        ]

```

* redocの出力  
<img width="443" alt="スクリーンショット 2019-03-03 3.53.13.png" src="https://qiita-image-store.s3.amazonaws.com/0/208169/f227462f-0807-f490-491d-9ee318feb1b6.png">


# 解決方法
* `ArticleSerializer`の`comments`フィールドを`SerializerMethodField`として定義し、`get_comments`で`Article`に紐づく`Comment`を取得する
* `CommentSerializer`の`user`フィールドを`SerializerMethodField`として定義し、`get_user`メソッドで`Comment`に紐づく`User`を取得する
* `get_comments`メソッドと`get_user`メソッドに`@swagger_serializer_method`デコレータを付加し、それぞれのメソッド内で使うSerializerを指定する

```python
from rest_framework.serializers import ModelSerializer, SerializerMethodField
from .models import Article, Comment, User

from drf_yasg.utils import swagger_serializer_method


class UserSerializer(ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'


class CommentSerializer(ModelSerializer):
    user = SerializerMethodField()

    class Meta:
        model = Comment
        fields = [
            'id',
            'target_article',
            'comment',
            'pubdate',
            'user',
        ]

    @swagger_serializer_method(serializer_or_field=UserSerializer)
    def get_user(self, instance):
        return UserSerializer(instance.user).data


class ArticleSerializer(ModelSerializer):
    comments = SerializerMethodField()

    class Meta:
        model = Article
        fields = [
            'id',
            'title',
            'contents_text',
            'pubdate',
            'comments',
        ]

    @swagger_serializer_method(serializer_or_field=CommentSerializer)
    def get_comments(self, instance):
        try:
            return CommentSerializer(instance.comments.get(target_article=instance)).data
        except Exception as e:
            print(e)
            return None
```
* redocの出力  
<img width="443" alt="スクリーンショット 2019-03-03 4.02.39.png" src="https://qiita-image-store.s3.amazonaws.com/0/208169/3833fe53-f5dc-9b06-cd14-de6d808a30ac.png">

# 補足
`swagger_serializer_method`デコレータをつけないと`ForeignKey`で取得しようとしているフィールドは`string`型として認識される
<img width="425" alt="スクリーンショット 2019-03-03 4.05.18.png" src="https://qiita-image-store.s3.amazonaws.com/0/208169/a225b430-4d41-da63-73f7-5e57a1b9cb63.png">

# 参考
* https://qiita.com/k_mawa82/items/1727c4355a94d5b51213
* https://www.django-rest-framework.org/api-guide/relations/
* https://github.com/axnsan12/drf-yasg/issues/137