Fix swagger Try it out and make endpoints work

openapi3
Cristi Vîjdea 2017-12-21 17:12:58 +01:00
parent 7683a28816
commit 8a8a9faeeb
7 changed files with 51 additions and 12 deletions

View File

@ -163,7 +163,14 @@
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
layout: "StandaloneLayout",
filter: true,
requestInterceptor: function(request) {
console.log(request);
var headers = request.headers || {};
headers["X-CSRFToken"] = document.querySelector("[name=csrfmiddlewaretoken]").value;
return request;
}
};
var swaggerSettings = {};

View File

@ -0,0 +1,28 @@
# Generated by Django 2.0 on 2017-12-21 15:35
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('articles', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='article',
name='body',
field=models.TextField(help_text='article model help_text', max_length=5000),
),
migrations.AlterField(
model_name='article',
name='slug',
field=models.SlugField(blank=True, help_text='slug model help_text', unique=True),
),
migrations.AlterField(
model_name='article',
name='title',
field=models.CharField(help_text='title model help_text', max_length=255, unique=True),
),
]

View File

@ -7,15 +7,17 @@ class ArticleSerializer(serializers.ModelSerializer):
references = serializers.DictField(
help_text="this is a really bad example",
child=serializers.URLField(help_text="but i needed to test these 2 fields somehow"),
read_only=True,
)
uuid = serializers.UUIDField(help_text="should articles have UUIDs?")
uuid = serializers.UUIDField(help_text="should articles have UUIDs?", read_only=True)
cover_name = serializers.FileField(use_url=False, source='cover', read_only=True)
class Meta:
model = Article
fields = ('title', 'body', 'slug', 'date_created', 'date_modified',
'references', 'uuid', 'cover', 'cover_name')
read_only_fields = ('date_created', 'date_modified')
read_only_fields = ('date_created', 'date_modified',
'references', 'uuid', 'cover_name')
lookup_field = 'slug'
extra_kwargs = {'body': {'help_text': 'body serializer help_text'}}

View File

@ -45,8 +45,8 @@ class ArticleViewSet(viewsets.ModelViewSet):
max_page_size = 5
filter_backends = (DjangoFilterBackend, OrderingFilter)
filter_fields = ('title',)
ordering_fields = ('date_modified',)
ordering = ('username',)
ordering_fields = ('date_modified','date_created')
ordering = ('date_created',)
@swagger_auto_schema(auto_schema=NoPagingAutoSchema)
@list_route(methods=['get'])

Binary file not shown.

View File

@ -30,13 +30,15 @@ class SnippetSerializer(serializers.Serializer):
language = LanguageSerializer(help_text="Sample help text for language")
styles = serializers.MultipleChoiceField(choices=STYLE_CHOICES, default=['friendly'])
lines = serializers.ListField(child=serializers.IntegerField(), allow_empty=True, allow_null=True, required=False)
example_projects = serializers.ListSerializer(child=ExampleProjectSerializer())
difficulty_factor = serializers.FloatField(help_text="this is here just to test FloatField")
example_projects = serializers.ListSerializer(child=ExampleProjectSerializer(), read_only=True)
difficulty_factor = serializers.FloatField(help_text="this is here just to test FloatField", read_only=True)
def create(self, validated_data):
"""
Create and return a new `Snippet` instance, given the validated data.
"""
del validated_data['styles']
del validated_data['lines']
return Snippet.objects.create(**validated_data)
def update(self, instance, validated_data):

View File

@ -459,8 +459,6 @@ definitions:
required:
- title
- body
- references
- uuid
type: object
properties:
title:
@ -489,14 +487,16 @@ definitions:
description: but i needed to test these 2 fields somehow
type: string
format: uri
readOnly: true
uuid:
description: should articles have UUIDs?
type: string
format: uuid
readOnly: true
cover:
type: string
format: uri
readOnly: true
format: uri
cover_name:
type: string
readOnly: true
@ -516,8 +516,6 @@ definitions:
required:
- code
- language
- example_projects
- difficulty_factor
type: object
properties:
id:
@ -1020,9 +1018,11 @@ definitions:
type: array
items:
$ref: '#/definitions/Project'
readOnly: true
difficulty_factor:
description: this is here just to test FloatField
type: number
readOnly: true
UserSerializerrr:
required:
- username