Add suport for Response schemas (#10)

Schemas generated from Serializers will now be added to the `definitions` section by default, and used as `$ref` objects where needed.  
The Schema definition name is based on the serializer class name, and can be overriden by specifying a `__ref_name__` property on the Serializer. If this property is set to None, the schema will not be added to `definitions` and will be forced inline.

Closes #6, #7.
This commit is contained in:
Cristi Vîjdea
2017-12-10 03:06:49 +01:00
committed by GitHub
parent 53b2560063
commit bfced82ae4
23 changed files with 1637 additions and 273 deletions
+6 -2
View File
@@ -4,11 +4,15 @@ from snippets.models import Snippet, LANGUAGE_CHOICES, STYLE_CHOICES
class LanguageSerializer(serializers.Serializer):
__ref_name__ = None
name = serializers.ChoiceField(
choices=LANGUAGE_CHOICES, default='python', help_text='The name of the programming language')
class ExampleProjectsSerializer(serializers.Serializer):
class ExampleProjectSerializer(serializers.Serializer):
__ref_name__ = 'Project'
project_name = serializers.CharField(help_text='Name of the project')
github_repo = serializers.CharField(required=True, help_text='Github repository of the project')
@@ -26,7 +30,7 @@ class SnippetSerializer(serializers.Serializer):
language = LanguageSerializer(help_text="Sample help text for language")
style = serializers.ChoiceField(choices=STYLE_CHOICES, default='friendly')
lines = serializers.ListField(child=serializers.IntegerField(), allow_empty=True, allow_null=True, required=False)
example_projects = serializers.ListSerializer(child=ExampleProjectsSerializer())
example_projects = serializers.ListSerializer(child=ExampleProjectSerializer())
def create(self, validated_data):
"""
+1
View File
@@ -29,6 +29,7 @@ class SnippetDetail(generics.RetrieveUpdateDestroyAPIView):
"""
queryset = Snippet.objects.all()
serializer_class = SnippetSerializer
pagination_class = None
def patch(self, request, *args, **kwargs):
"""patch method docstring"""