Skip to content
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

wrong Enum type generated when choices have named groups. #339

Closed
elonzh opened this issue Mar 16, 2021 · 4 comments
Closed

wrong Enum type generated when choices have named groups. #339

elonzh opened this issue Mar 16, 2021 · 4 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@elonzh
Copy link

elonzh commented Mar 16, 2021

Describe the bug
According to Django document, choices supports named groups but drf-spectacular can not generate right schema.

To Reproduce

For example:

MEDIA_CHOICES = [
    ('Audio', (
            ('vinyl', 'Vinyl'),
            ('cd', 'CD'),
        )
    ),
    ('Video', (
            ('vhs', 'VHS Tape'),
            ('dvd', 'DVD'),
        )
    ),
    ('Unknown', 'Unknown'),
]

will be generated as:

	schema:
          enum:
          - Audio
          - Unknown
          - Video
          type: string

Expected behavior

generates the right schema.

@elonzh elonzh changed the title wrong Enum type generated when choice have named groups. wrong Enum type generated when choices have named groups. Mar 16, 2021
@tfranzel
Copy link
Owner

wasn't aware of that django feature. yes we should account for that. the right schema would then be enum: ['vinyl', 'cd', 'vhs', 'dvd'], right?

@tfranzel tfranzel added bug Something isn't working enhancement New feature or request labels Mar 16, 2021
@elonzh
Copy link
Author

elonzh commented Mar 17, 2021

@tfranzel Yes you are right. Check out django.db.models.fields.Field._check_choices to see how django parse choices

@tfranzel
Copy link
Owner

@elonzh so there is indeed a small bug in ENUM_NAME_OVERRIDES, but in any case i was unable to produce a schema like stated above. the DRF/Django field mechanics do this transformation automatically. at least that is what i'm observing at the moment.

how did you use MEDIA_CHOICES in field to produce that schema?

@elonzh
Copy link
Author

elonzh commented Mar 18, 2021

Sorry, maybe it's my mistake, My choices are generated and I can't reproduce this issue now.

@elonzh elonzh closed this as completed Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants