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.
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
Workaround: https://pypi.org/project/drf-yasg-examples/
Most helpful comment
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.