From 215206b92bb6a111a6072de449571ed948390a19 Mon Sep 17 00:00:00 2001 From: Marcus Weiner Date: Fri, 13 Dec 2024 22:04:08 +0100 Subject: [PATCH] Fix OpenAPI schema for vid_ranges in VLANGroup so it shows up --- netbox/netbox/api/fields.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/netbox/netbox/api/fields.py b/netbox/netbox/api/fields.py index e7d1ef5745b..6179e075dac 100644 --- a/netbox/netbox/api/fields.py +++ b/netbox/netbox/api/fields.py @@ -158,7 +158,29 @@ def __init__(self, relation, **kwargs): super().__init__(**kwargs) +_integer_range_schema = { + 'type': 'array', + 'items': { + 'type': 'integer', + }, + 'minItems': 2, + 'maxItems': 2, +} + +@extend_schema_field({ + 'type': 'array', + 'items': _integer_range_schema, +}) +class IntegerRangeListSerializer(serializers.ListSerializer): + # this special class is only here to work around + # https://github.com/tfranzel/drf-spectacular/issues/1353 + pass + +@extend_schema_field(_integer_range_schema) class IntegerRangeSerializer(serializers.Serializer): + class Meta: + list_serializer_class = IntegerRangeListSerializer + """ Represents a range of integers. """