From 4c98b0fa47175c5d2af9de00dfd8afa3ddb94897 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 1 Apr 2025 10:14:29 -0400 Subject: [PATCH] Fix handling of array item types --- netbox/utilities/jsonschema.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/netbox/utilities/jsonschema.py b/netbox/utilities/jsonschema.py index b5a4ada04..97217286a 100644 --- a/netbox/utilities/jsonschema.py +++ b/netbox/utilities/jsonschema.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass +from dataclasses import dataclass, field from enum import Enum from typing import Any @@ -74,6 +74,9 @@ class JSONSchemaProperty: maximum: 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): """ Instantiate and return a Django form field suitable for editing the property's value. @@ -92,6 +95,11 @@ class JSONSchemaProperty: choices = [(None, ''), *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 if self.type == PropertyTypeEnum.STRING.value: if self.minLength is not None: @@ -114,6 +122,7 @@ class JSONSchemaProperty: field_kwargs['validators'] = [ MultipleOfValidator(multiple=self.multipleOf) ] + return self.field_class(**field_kwargs) @property