mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 02:48:38 -06:00
Fix handling of array item types
This commit is contained in:
parent
26efdde3cc
commit
4c98b0fa47
@ -1,4 +1,4 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass, field
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -74,6 +74,9 @@ class JSONSchemaProperty:
|
|||||||
maximum: int | float | None = None
|
maximum: int | float | None = None
|
||||||
multipleOf: int | float | None = None
|
multipleOf: int | float | None = None
|
||||||
|
|
||||||
|
# Arrays
|
||||||
|
items: dict | None = field(default_factory=dict)
|
||||||
|
|
||||||
def to_form_field(self, name, required=False):
|
def to_form_field(self, name, required=False):
|
||||||
"""
|
"""
|
||||||
Instantiate and return a Django form field suitable for editing the property's value.
|
Instantiate and return a Django form field suitable for editing the property's value.
|
||||||
@ -92,6 +95,11 @@ class JSONSchemaProperty:
|
|||||||
choices = [(None, ''), *choices]
|
choices = [(None, ''), *choices]
|
||||||
field_kwargs['choices'] = choices
|
field_kwargs['choices'] = choices
|
||||||
|
|
||||||
|
# Arrays
|
||||||
|
if self.type == PropertyTypeEnum.ARRAY.value:
|
||||||
|
items_type = self.items.get('type', PropertyTypeEnum.STRING.value)
|
||||||
|
field_kwargs['base_field'] = FORM_FIELDS[items_type]()
|
||||||
|
|
||||||
# String validation
|
# String validation
|
||||||
if self.type == PropertyTypeEnum.STRING.value:
|
if self.type == PropertyTypeEnum.STRING.value:
|
||||||
if self.minLength is not None:
|
if self.minLength is not None:
|
||||||
@ -114,6 +122,7 @@ class JSONSchemaProperty:
|
|||||||
field_kwargs['validators'] = [
|
field_kwargs['validators'] = [
|
||||||
MultipleOfValidator(multiple=self.multipleOf)
|
MultipleOfValidator(multiple=self.multipleOf)
|
||||||
]
|
]
|
||||||
|
|
||||||
return self.field_class(**field_kwargs)
|
return self.field_class(**field_kwargs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
Reference in New Issue
Block a user