Giter Site home page Giter Site logo

drf-yasg-json-api's People

Contributors

brettdh avatar glowka avatar kaglowka avatar nikosmichas avatar skotenok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

drf-yasg-json-api's Issues

Incorrect schema for non-model viewset list

drf-yasg-json-api generates incorrect schema for non-model views (rest_framework.viewsets.ViewSet). Here is a test that shows it:

diff --git a/tests/test_schema/test_get.py b/tests/test_schema/test_get.py
index c850bdf..1438584 100644
--- a/tests/test_schema/test_get.py
+++ b/tests/test_schema/test_get.py
@@ -7,10 +7,12 @@ import drf_yasg.inspectors
 from django.conf.urls import url
 from drf_yasg import openapi
 from drf_yasg.generators import OpenAPISchemaGenerator
+from drf_yasg.utils import swagger_auto_schema
 from rest_framework import mixins
 from rest_framework import routers
 from rest_framework import views
 from rest_framework import viewsets
+from rest_framework.response import Response
 from rest_framework_json_api import django_filters
 from rest_framework_json_api import filters
 from rest_framework_json_api import pagination
@@ -242,3 +244,31 @@ def test_get__filter():
 
     request_parameters_schema = swagger['paths']['/projects/']['get']['parameters']
     assert request_parameters_schema[0]['name'] == 'filter[archived]'
+
+
+def test_get_nonmodel_many():
+    class ProjectSerializer(serializers.Serializer):
+        pk = serializers.IntegerField()
+        name = serializers.CharField()
+
+    class ProjectViewSet(viewsets.ViewSet):
+        renderer_classes = [renderers.JSONRenderer]
+        parser_classes = [parsers.JSONParser]
+        swagger_schema = base.BasicSwaggerAutoSchema
+        resource_name = 'projects'
+
+        @swagger_auto_schema(responses={200: ProjectSerializer(many=True)})
+        def list(self, request):
+            projects = [{'pk': 1, 'name': 'test'}]
+            serializer = ProjectSerializer(data=projects, many=True)
+            return Response(serializer.data)
+
+    router = routers.DefaultRouter()
+    router.register(r'projects', ProjectViewSet, **compatibility._basename_or_base_name('projects'))
+
+    generator = OpenAPISchemaGenerator(info=openapi.Info(title="", default_version=""), patterns=router.urls)
+
+    swagger = generator.get_schema(None, True)
+
+    response_schema = swagger['paths']['/projects/']['get']['responses']['200']['schema']
+    assert response_schema.type != 'array'

It works fine for single item view, but for list view it generates non-json-api schema:

[
  {
    "id": "integer",
    "name": "string"
  }
]

string based included_serializers

In DJA they support string paths like:

    included_serializers = {
        'categories': 'api.serializers.task.TaskCategorySerializer',
        'tasks': 'api.serializers.task.TaskSerializer'
    }

I have some relationships that I need both sides to be includable and my serializers are usually in the same file.

Eample:

class TaskListSerializer(JSONAPISerializers.ModelSerializer):
    included_serializers = {
        'tasks': 'api.serializers.task.TaskSerializer'
    }

    class Meta:
        model = TaskList
        fields = ['id', 'name', 'description', 'tasks']

class TaskSerializer(JSONAPISerializers.ModelSerializer):
    included_serializers = {
        'lists': TaskListSerializer
    }

    class Meta:
        model = Task
        fields = ['id', 'name', 'description', 'lists']

Every time I try to use the path string it works in DJA but I get the following error when using this plugin:

TypeError: 'str' object is not callable

Is there a possibility of getting path support for included_serializers (ex: 'api.serializers.task.TaskSerializer')?

RecursiveField Assertion Error

I am getting an assertion error while trying to generate schema for a ViewSet which contains a djangorestframework-recursive - RecursiveField

assert use_references is True, "Can not create schema for RecursiveField when use_references is False"
AssertionError: Can not create schema for RecursiveField when use_references is False

serializers.py

class ResourceSerializer(serializers.ModelSerializer):

    children = serializers.ListField(read_only=True, source='get_children', child=RecursiveField())

    class Meta:
        model = Resource
        fields = ('id', 'children', 'slug')

Could you please help me out?

AssertionError("TYPE_ARRAY requires the items attribute")

Hello, I am receiving this error after running the server although there are no custom swagger_auto_schema declared in the API.

raise AssertionError("TYPE_ARRAY requires the items attribute")
AssertionError: TYPE_ARRAY requires the items attribute

Any help on this is appreciated.

Compatibility with django-rest-framework-json-api 5.0

Hello,
I am trying to update a project in new versions of Django, DRF etc, and I am having some issues with drf-yasg-json-api compatibility with new version of django-rest-framework-json-api.
I will try to fix this in a fork. Can I submit a PR for this?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.