Drf-yasg: Support for examples

Created on 15 Oct 2018  路  4Comments  路  Source: axnsan12/drf-yasg

Wondering if there's any plan for supporting examples in serializer Fields? This is pretty important if you intend people to use your API effectively, and can dramatically increase an API's ease of use.

An easy place to implement this would be by using the initial field.

I recognize that this is fairly straightforward to implement by subclassing Field inspector, but this seems like something important enough to warrant built-in support.

feature proposal

Most helpful comment

An easy place to implement this would be by using the initial field.

I hadn't thought of that, sounds like a great idea! This topic (setting example values) kept coming up but I never could figure out a clean way to make it work.

All 4 comments

An easy place to implement this would be by using the initial field.

I hadn't thought of that, sounds like a great idea! This topic (setting example values) kept coming up but I never could figure out a clean way to make it work.

Came here looking for this as well.
Maybe could be described like this...:

class Person(models.Model):
    first_name = models.CharField(max_length=200)
    last_name = models.CharField(max_length=200)
    phone = models.CharField(max_length=200)

class PersonSerializer(serializers.ModelSerializer):
    class Meta:
        model = Person
        fields = ("first_name", "last_name", "phone")
        swagger_example_fields = {
            "first_name": "John",
            "last_name": "Woods",
            "phone": "540-257-555",
        }

Thanks for your work in this project!

i think that initial or placeholder would be best for example data

Was this page helpful?
0 / 5 - 0 ratings

Related issues

therefromhere picture therefromhere  路  3Comments

geekashu picture geekashu  路  5Comments

mkurnikov picture mkurnikov  路  4Comments

hnykda picture hnykda  路  3Comments

vinayan3 picture vinayan3  路  5Comments