Wrong openapi spec when using country_dict=True
andriijas opened this issue · comments
Andreas Cederström commented
When using CountryField(country_dict=True)
the expected JSON output is fine but the openapi schema is wrong. This makes it hard to generate for example a typescript client based on the generated schema.
from django.contrib.auth import get_user_model
from rest_framework import serializers
from django_countries.serializers import CountryFieldMixin
from django_countries.serializer_fields import CountryField
class UserSerializer(CountryFieldMixin, serializers.ModelSerializer):
country = CountryField(country_dict=True)
class Meta:
model = get_user_model()
fields = (
"id",
"email",
"first_name",
"last_name",
"country",
)
However when looking at drf builtin openapi spec, or generating one with drf_spectactular
./manage.py spectacular --color --file schema.yml
country on User is still specified as an enum in the schema.yml
User:
type: object
properties:
id:
type: integer
readOnly: true
email:
type: string
format: email
title: Email address
maxLength: 254
first_name:
type: string
maxLength: 150
last_name:
type: string
maxLength: 150
country:
$ref: '#/components/schemas/CountryEnum' <-- Correct when not using country_dict wrong when using country_dict=True
required:
- country
- email
- id
#/components/schemas/CountryEnum
CountryEnum:
enum:
- AF
- AX
- AL
- DZ
- AS
- AD
- AO
- AI
- AQ
- AG
- AR
....
Any ideas?