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 openapi spec when using country_dict=True #441

Open
andriijas opened this issue Oct 31, 2023 · 0 comments
Open

Wrong openapi spec when using country_dict=True #441

andriijas opened this issue Oct 31, 2023 · 0 comments
Labels

Comments

@andriijas
Copy link

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?

@SmileyChris SmileyChris added the api label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants