django-ninja icon indicating copy to clipboard operation
django-ninja copied to clipboard

Postgres ArrayField Inner Type And CharField Choices

Open kingychiu opened this issue 7 months ago • 0 comments

  • ArrayField Inner Field, similar to what the other has try to do before here https://github.com/vitalik/django-ninja/pull/386/files (Not sure why it is not in main now)
  • Choices of the CharField

Example:

class TypeChoice(models.TextChoices):
    NAME_A = "VALUE_A"
    NAME_B = "VALUE_B"

class ArrayModel(models.Model):
    array_of_int = ps_fields.ArrayField(models.IntegerField())
    array_of_str = ps_fields.ArrayField(models.CharField(max_length=100))
    array_of_choice = ps_fields.ArrayField(
        models.CharField(choices=TypeChoice.choices)
    )

Produces the same OpenAPI schema as

class ExpectedSchema(Schema):
    array_of_int: List[int]
    array_of_str: List[str]
    array_of_choice: List[Literal["VALUE_A", "VALUE_B"]]

Let me know if the added tests are enough. Thank you.

kingychiu avatar Jul 05 '24 19:07 kingychiu