Skip to content

DRF generates incorrect attributes for serializers.ListField #6862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 of 6 tasks
knivets opened this issue Aug 9, 2019 · 4 comments · Fixed by #6866
Closed
5 of 6 tasks

DRF generates incorrect attributes for serializers.ListField #6862

knivets opened this issue Aug 9, 2019 · 4 comments · Fixed by #6866

Comments

@knivets
Copy link
Contributor

knivets commented Aug 9, 2019

Checklist

  • I have verified that that issue exists against the master branch of Django REST framework.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • This is not a usage question. (Those should be directed to the discussion group instead.)
  • This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
  • I have reduced the issue to the simplest possible case.
  • I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)

Steps to reproduce

# view.py
from rest_framework import generics
from rest_framework import serializers
from django.db import models

class Book(models.Model):
  title = models.CharField(max_length=200)

class BookSerializer(serializers.ModelSerializer):
  tags = serializers.ListField(min_length=2, max_length=5)
  class Meta:
    model = Book
    fields = ('tags',)

class BooksView(generics.ListAPIView):
  queryset = Book.objects.all()   
  serializer_class = BookSerializer

# urls.py
urlpatterns = [
...
path('api/books/', views.BooksView.as_view()),
...
]

Expected behavior

$ ./manage.py generateschema

openapi: 3.0.2
info:
  title: ''
  version: TODO
paths:
  /api/books/:
    get:
      operationId: ListBooks
      parameters: []
      responses:
        '200':
          content:
            application/json:
              schema:
                required:
                - tags
                properties:
                  tags:
                    type: array
                    items: {}
                    maxItems: 5
                    minItems: 2

Actual behavior

$ ./manage.py generateschema

openapi: 3.0.2
info:
  title: ''
  version: TODO
paths:
  /api/books/:
    get:
      operationId: ListBooks
      parameters: []
      responses:
        '200':
          content:
            application/json:
              schema:
                required:
                - tags
                properties:
                  tags:
                    type: array
                    items: {}
                    maxLength: 5
                    minLength: 2

https://swagger.io/docs/specification/data-models/data-types/#array-length

@knivets
Copy link
Contributor Author

knivets commented Aug 9, 2019

@carltongibson please confirm whether this is something you'd like me to work on 🙂
There's one more #6863

@carltongibson
Copy link
Collaborator

Hi @knivets I’m struggling to spot the difference between the actual and expected here. Could you ping it out for me please? (Sorry)

@carltongibson
Copy link
Collaborator

Oh, items vs length. Right.

@carltongibson
Copy link
Collaborator

Yes, I guess we need an adjustment here, after mapping validators. (Grrrr. Messy spec. Grrrr. 🙂)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants