django-ninja
django-ninja copied to clipboard
Postgres ArrayField Inner Type And CharField Choices
- 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.